index.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <html>
  4. <head>
  5. <meta charset="UTF-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>demo</title>
  8. <style>
  9. html,
  10. body {
  11. overflow: hidden;
  12. width: 100%;
  13. height: 100%;
  14. margin: 0;
  15. padding: 0;
  16. }
  17. #renderCanvas {
  18. width: 100%;
  19. height: 100%;
  20. touch-action: none;
  21. }
  22. #videoTextureBox video {
  23. display: none;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <canvas id="renderCanvas"></canvas>
  29. <div id="videoTextureBox">
  30. <video
  31. id="houseTexture0"
  32. src="./textures/outputmp4/0/0.mp4"
  33. crossorigin="anonymous"
  34. playsinline
  35. autoplay
  36. muted
  37. ></video>
  38. </div>
  39. <!-- Babylon.js -->
  40. <script src="./libs/dat.gui.min.js"></script>
  41. <script src="./libs/ammo.js"></script>
  42. <script src="./libs/cannon.js"></script>
  43. <script src="./libs/Oimo.js"></script>
  44. <script src="./libs/earcut.min.js"></script>
  45. <script src="./libs/recast.js"></script>
  46. <script src="./libs/babylon.js"></script>
  47. <script src="./libs/babylonjs.materials.min.js"></script>
  48. <script src="./libs/babylonjs.proceduralTextures.min.js"></script>
  49. <script src="./libs/babylonjs.postProcess.min.js"></script>
  50. <script src="./libs/babylonjs.loaders.js"></script>
  51. <script src="./libs/babylonjs.serializers.min.js"></script>
  52. <script src="./libs/babylon.gui.min.js"></script>
  53. <script src="./libs/babylon.inspector.bundle.js"></script>
  54. <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js""></script>
  55. <script type="module">
  56. import App from "./modules/index.js";
  57. var canvas = document.getElementById("renderCanvas");
  58. var engine = null;
  59. var scene = null;
  60. var sceneToRender = null;
  61. var startRenderLoop = function (engine, canvas) {
  62. engine.runRenderLoop(function () {
  63. if (sceneToRender && sceneToRender.activeCamera) {
  64. sceneToRender.render();
  65. }
  66. });
  67. };
  68. var createDefaultEngine = function () {
  69. return new BABYLON.Engine(canvas, true, {
  70. preserveDrawingBuffer: true,
  71. stencil: true,
  72. disableWebGL2Support: false,
  73. });
  74. };
  75. var asyncEngineCreation = async function () {
  76. try {
  77. return createDefaultEngine();
  78. } catch (e) {
  79. console.log(
  80. "the available createEngine function failed. Creating the default engine instead"
  81. );
  82. return createDefaultEngine();
  83. }
  84. };
  85. window.initFunction = async function () {
  86. engine = await asyncEngineCreation();
  87. if (!engine) throw "engine should not be null.";
  88. startRenderLoop(engine, canvas);
  89. engine.enableOfflineSupport = false;
  90. // Scene and Camera
  91. window.app = new App(engine);
  92. scene = window.app.scene;
  93. };
  94. initFunction().then(() => {
  95. sceneToRender = scene;
  96. });
  97. window.scene = scene;
  98. window.engine = engine;
  99. // Resize
  100. window.addEventListener("resize", function () {
  101. engine.resize();
  102. });
  103. </script>
  104. <!-- worker -->
  105. <!-- <script src="./worker/decoderWorker.js"></script> -->
  106. <script src="./worker/index.js" type="module"></script>
  107. <script type="module">
  108. import { Connection } from "./webrtc/connection.js";
  109. document.addEventListener("DOMContentLoaded", async() => {
  110. const connection = new Connection();
  111. window.connection = connection;
  112. connection.init(async()=>{
  113. if(connection.client){
  114. await connection.client.join({ roomId: 8889 })
  115. console.log('userSig',connection.userSig)
  116. connection.socket.emit('getPush',{
  117. userId:123,
  118. roomId: 8889,
  119. sceneCode:"2111",
  120. userSig:connection.userSig
  121. })
  122. connection.socket.on('getPush',(data)=>{
  123. console.log('getPush',
  124. `ffmpeg -loglevel info -re -stream_loop -1 -i output.mp4 -c:v libx264 -preset fast -profile:v baseline -g 30 -sc_threshold 0 -b:v 1500k -c:a libfdk_aac -ac 2 -b:a 128k -f flv "${data}"`);
  125. });
  126. console.log('connection.client',connection.client);
  127. connection.client.on('peer-join', event => {
  128. console.log('peer-join',event)
  129. });
  130. connection.client.on('stream-added', event => {
  131. const remoteStream = event.stream;
  132. const remoteUserId = remoteStream.getUserId();
  133. console.log('received a remoteStream ID: ' + remoteStream.getId() + ' from user: ' + remoteUserId);
  134. // 若需要观看该远端流,则需要订阅它
  135. connection.client.subscribe(remoteStream);
  136. });
  137. // connection.client.on('network-quality', event => {
  138. // console.log(`network-quality, uplinkNetworkQuality:${event.uplinkNetworkQuality}, downlinkNetworkQuality: ${event.downlinkNetworkQuality}`)
  139. // // 自 v4.10.3 支持获取上、下行的 RTT 及丢包率
  140. // console.log(`uplink rtt:${event.uplinkRTT} loss:${event.uplinkLoss}`)
  141. // console.log(`downlink rtt:${event.downlinkRTT} loss:${event.downlinkLoss}`)
  142. // })
  143. connection.client.on('stream-subscribed', event => {
  144. const remoteStream = event.stream;
  145. // 远端流订阅成功,在HTML页面中创建一个<video>标签,假设该标签ID为‘remote-video-view’
  146. // 播放该远端流
  147. remoteStream.play('remote-video-view');
  148. });
  149. connection.client.on('error', event => {
  150. console.log('error',event)
  151. });
  152. // await connection.client.on('connection-state-changed', event => {
  153. // console.log('connection-state-changed',event)
  154. // });
  155. // 监听‘stream-removed’事件
  156. // connection.client.on('stream-removed', event => {
  157. // const remoteStream = event.stream;
  158. // console.log('remoteStream ID: ' + remoteStream.getId() + ' has been removed');
  159. // // 停止播放并删除相应<video>标签
  160. // });
  161. // // 监听‘stream-updated’事件
  162. // connection.client.on('stream-updated', event => {
  163. // const remoteStream = event.stream;
  164. // console.log('remoteStream ID: ' + remoteStream.getId() + ' was updated hasAudio: '
  165. // + remoteStream.hasAudio() + ' hasVideo: ' + remoteStream.hasVideo());
  166. // });
  167. // 监听‘stream-subscribed’事件
  168. }
  169. });
  170. });
  171. </script>
  172. <video id="remote-video-view" style="position: fixed;width:300px;height:300px;z-index: 10000;top:0;left:0"></video>
  173. </body>
  174. <script src="https://web.sdk.qcloud.com/trtc/webrtc/demo/latest/dist/trtc.js"></script>
  175. </html>
  176. </html>