srs.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.on("getSocketVideo", async (data) => {
  93. console.log("getSocketVideo", data);
  94. downloadBlob(data, "getSocketVideo.mp4", "application/video");
  95. });
  96. const downloadURL = function (r, n) {
  97. const o = document.createElement("a");
  98. (o.href = r),
  99. (o.download = n),
  100. document.body.appendChild(o),
  101. (o.style.display = "none"),
  102. o.click(),
  103. o.remove();
  104. };
  105. let downloadBlob = (data, fileName, mimeType) => {
  106. const blob = new Blob([data], {
  107. type: mimeType,
  108. });
  109. const url = URL.createObjectURL(blob);
  110. downloadURL(url, fileName);
  111. setTimeout(function () {
  112. return URL.revokeObjectURL(url);
  113. }, 3000);
  114. };
  115. // connection.socket.emit("pushVideo_test", {
  116. // videoPath: "sample-5s",
  117. // });
  118. // connection.socket.on("pushVideo_test", async (data) => {
  119. // console.log(data);
  120. // // downloadBlob(data, 'test.mp4', 'application/video')
  121. // });
  122. // const getVideo = (videoUrl) => {
  123. // $("#testVideoFeed").prop("srcObject", sdk.stream);
  124. // sdk
  125. // .getVideo(videoUrl)
  126. // .then(function (session) {
  127. // console.log("session", session.sessionid);
  128. // })
  129. // .catch(function (reason) {
  130. // console.error(reason);
  131. // });
  132. // };