srs.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { SrsRTC } from "./srsRtc.js";
  2. import { Connection } from "./connection.js";
  3. const sdk = new SrsRTC();
  4. const testConfig = {
  5. sceneCode: "testApp",
  6. userId: "testUser",
  7. roomId: "8888",
  8. };
  9. const connection = new Connection(testConfig);
  10. console.log("sdk", sdk);
  11. console.log("sdk", connection);
  12. const url = "webrtc://demo-kms.4dage.com/live/test1";
  13. sdk.start(url);
  14. console.log("第一个");
  15. // connection.socket.emit("pushVideo", {
  16. // videoList: ["0/0_1_0", "0/0_1_1"],
  17. // sessionId: "1",
  18. // sceneCode: testConfig.sceneCode,
  19. // roomId: testConfig.roomId,
  20. // userId: testConfig.userId,
  21. // });
  22. // setTimeout(()=>{
  23. // console.log('第二个')
  24. // connection.socket.emit('pushVideo',{
  25. // videoList:['output'],
  26. // sessionId:'',
  27. // sceneCode:testConfig.sceneCode,
  28. // roomId:testConfig.roomId,
  29. // userId:testConfig.userId,
  30. // })
  31. // },10000)
  32. // setTimeout(()=>{
  33. // console.log('第二个')
  34. // connection.socket.emit('rotate',{
  35. // videoPath:'sample-5s',
  36. // sessionId:'2',
  37. // sceneCode:testConfig.sceneCode,
  38. // roomId:testConfig.roomId,
  39. // userId:testConfig.userId,
  40. // sangle: '0',
  41. // eangle:'900',
  42. // reverses:true,
  43. // })
  44. // },12000)
  45. // setTimeout(()=>{
  46. // console.log('正转')
  47. // connection.socket.emit('rotate',{
  48. // videoList:['output'],
  49. // sessionId:'3',
  50. // sceneCode:testConfig.sceneCode,
  51. // roomId:testConfig.roomId,
  52. // userId:testConfig.userId,
  53. // })
  54. // },14000)
  55. // setTimeout(()=>{
  56. // console.log('第三个')
  57. // connection.socket.emit('pushVideo',{
  58. // videoList:['sample-5s'],
  59. // sessionId:'4',
  60. // sceneCode:testConfig.sceneCode,
  61. // roomId:testConfig.roomId,
  62. // userId:testConfig.userId,
  63. // })
  64. // },20000)
  65. window.connection = connection;
  66. // connection.socket.on("getVideo", async (streamUrl) => {
  67. // if (streamUrl) {
  68. // const url = "webrtc://demo-kms.4dage.com/" + streamUrl;
  69. // console.log("getVideo", streamUrl);
  70. // sdk.close();
  71. // await getVideo(url);
  72. // }
  73. // });
  74. // 正转
  75. // connection.socket.emit("getVideo", {
  76. // videoList: ["0/0_1_0", "0/0_1_1", "0/0_1_2"],
  77. // // sessionId: "1",
  78. // sceneCode: testConfig.sceneCode,
  79. // roomId: testConfig.roomId,
  80. // userId: testConfig.userId,
  81. // });
  82. // connection.socket.emit("getRotateVideo", {
  83. // videoPath: "0/0_1_0",
  84. // // sessionId: "3",
  85. // sceneCode: testConfig.sceneCode,
  86. // roomId: testConfig.roomId,
  87. // userId: testConfig.userId,
  88. // sangle: "0",
  89. // eangle: "360",
  90. // reverses: true,
  91. // });
  92. // connection.socket.emit("getRoute", {
  93. // sceneCode: testConfig.sceneCode,
  94. // roomId: testConfig.roomId,
  95. // userId: testConfig.userId,
  96. // s_location: {
  97. // x: 3.6,
  98. // y: 0.0,
  99. // z: -5.76,
  100. // },
  101. // e_location: {
  102. // x: 2.88,
  103. // y: 0.0,
  104. // z: -4.68,
  105. // },
  106. // });
  107. // connection.socket.on("getRoute", (event) => {
  108. // console.log("getRoute", event);
  109. // });
  110. // connection.socket.on("getSocketVideo", async (data) => {
  111. // console.log("getSocketVideo", data);
  112. // downloadBlob(data, "getSocketVideo.mp4", "application/video");
  113. // });
  114. const downloadURL = function (r, n) {
  115. const o = document.createElement("a");
  116. (o.href = r),
  117. (o.download = n),
  118. document.body.appendChild(o),
  119. (o.style.display = "none"),
  120. o.click(),
  121. o.remove();
  122. };
  123. let downloadBlob = (data, fileName, mimeType) => {
  124. const blob = new Blob([data], {
  125. type: mimeType,
  126. });
  127. const url = URL.createObjectURL(blob);
  128. downloadURL(url, fileName);
  129. setTimeout(function () {
  130. return URL.revokeObjectURL(url);
  131. }, 3000);
  132. };
  133. // connection.socket.emit("pushVideo_test", {
  134. // videoPath: "sample-5s",
  135. // });
  136. // connection.socket.on("pushVideo_test", async (data) => {
  137. // console.log(data);
  138. // // downloadBlob(data, 'test.mp4', 'application/video')
  139. // });
  140. // const getVideo = (videoUrl) => {
  141. // $("#testVideoFeed").prop("srcObject", sdk.stream);
  142. // sdk
  143. // .getVideo(videoUrl)
  144. // .then(function (session) {
  145. // console.log("session", session.sessionid);
  146. // })
  147. // .catch(function (reason) {
  148. // console.error(reason);
  149. // });
  150. // };