how to use adapter.js of webRTC-adapter?

18,538

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>
Share:
18,538
Mirai
Author by

Mirai

Updated on July 12, 2022

Comments

  • Mirai
    Mirai almost 2 years

    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

  • Mirai
    Mirai about 8 years
    'code' <html> <head> <script src='adapter.js'></script> <script type='text/javascript'> function a() { alert(detectBrowser()); } </script> </head> <body> <button id='browser' onclick="a()">as</button> </body> </html>'code' and i got "detectBrowser is not defined".
  • Mirai
    Mirai about 8 years
    excuse me! please me me, WPP. actually i can't use adapter even i did as u said. Could it be something wrong?
  • wpp
    wpp about 8 years
    Looks like you made a mistake. Working fine for me, make sure you include the right adapter.js version and read up on it's API and functionality.
  • Mirai
    Mirai about 8 years
    i really don't know how to appreciate your help. Really thanks alot. I did have a big trouble with adapter.js
  • Mirai
    Mirai about 8 years
    I would like to ask you one thing more. That's the library of adapter.js. While using jsoup library, i search for documents for it so that i can use it effectively. But i hardly finded out documents of adapter.js . It really took alot of time if i read whole file to know about it.
  • wpp
    wpp about 8 years
    Not sure what you want from me here? Maybe you're looking for this? webrtc.org/web-apis/interop
  • Mirai
    Mirai about 8 years
    sorry to say this. But i did search there and then i saw no lead so i did come here to ask after 2 weeks of searching on internet.
  • Mirai
    Mirai about 8 years
    could i ask u for how to use function attach(element, stream) in adapter.js? because i knew it will took more time to search anymore while i need it. Could it be used as "adapter.browser.attach(element, stream)'? Sorry for being annoying like this.
  • Mirai
    Mirai about 8 years
    Could you please let me contact u via email? Acttually, i am new with javascript, yet my job is invoked a lot with javascript. Iread many tutorials about javascript and try manything but there is something about this language, i don't understand. It's about logic of programming and syntax but not about how to write a purpose function.