如何使用webRTC-adapter的adapter.js? [英] how to use adapter.js of webRTC-adapter?

查看:1933
本文介绍了如何使用webRTC-adapter的adapter.js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写WebRTC应用程序,并且遇到以下问题:

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

我想使用 adapter.js 库.

我有以下index.html:

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>

和我的main.js看起来像:

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.');  
}

但是我的浏览器记录了错误:Uncaught ReferenceError: require is not defined

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

推荐答案

require在Node.js环境中使用(并定义)以加载模块. (并非排他,有关更多信息,请在此处).

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

如果您从此处下载了adapter.js版本,并将其包含在的方式(通过script标记),您可以简单地删除require(...)行,您应该会很好.

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.

添加了一个示例

console.log(adapter.browserDetails.browser);

<script src="http://webrtc.github.io/adapter/adapter-latest.js"></script>

这篇关于如何使用webRTC-adapter的adapter.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆