3

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

wpp
  • 7,093
  • 4
  • 33
  • 65
Mirai
  • 75
  • 1
  • 2
  • 9

2 Answers2

9

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>
Community
  • 1
  • 1
wpp
  • 7,093
  • 4
  • 33
  • 65
  • 'code' 'code' and i got "detectBrowser is not defined". – Mirai May 31 '16 at 16:03
  • excuse me! please me me, WPP. actually i can't use adapter even i did as u said. Could it be something wrong? – Mirai Jun 03 '16 at 00:23
  • 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. – wpp Jun 03 '16 at 09:10
  • i really don't know how to appreciate your help. Really thanks alot. I did have a big trouble with adapter.js – Mirai Jun 11 '16 at 03:22
  • 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. – Mirai Jun 11 '16 at 03:33
  • Not sure what you want from me here? Maybe you're looking for this? https://webrtc.org/web-apis/interop/ – wpp Jun 13 '16 at 15:58
  • 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 Jun 15 '16 at 00:19
  • 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 Jun 15 '16 at 00:31
  • 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. – Mirai Jun 15 '16 at 00:37
-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