how to use adapter.js of webRTC-adapter?

风格不统一 提交于 2019-12-02 06:06:18

问题


I am writing a WebRTC application and have the following problem:

I want to use the adapter.js library.

I have the following index.html:

<html>
  <header>
     <script src='../out/adapter.js'></script>
     <script src='../out/main.js'></script>
  </header>
  <body> 
    <video id="localVideo" width='500' autoplay></video> 
  </body>
</html>

and my main.js looks like:

var adapter=require('webrtc-adapter');
var localVideo=document.querySelector('video#localVideo');
navigator.getUserMedia(media_constraints, handleUserMedia, handleUserMediaError); 
function handleUserMedia(stream) {        
   localStream = stream;        
   adapter.attachMediaStream(localVideo, stream);        
   console.log('Adding local stream.');  
}

but my browser logs the error: Uncaught ReferenceError: require is not defined


回答1:


require is used (and defined) in Node.js environments to load modules. (Not exclusively, for more information check here).

If you downloaded an adapter.js version from here and include it the way you do (via script tags), you can simple delete the require(...) line and you should be good to go.

Edit: added an example

console.log(adapter.browserDetails.browser);
<script src="http://webrtc.github.io/adapter/adapter-latest.js"></script>



回答2:


if you have checked installing adapter js? check

npm webrtc-adapter --version

if not showing up in node, install it to your app

npm install --save webrtc-adapter 


来源:https://stackoverflow.com/questions/37550269/how-to-use-adapter-js-of-webrtc-adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!