【发布时间】:2018-05-31 15:24:39
【问题描述】:
我正在编写一个非常简单的 WebRTC 应用程序来从 RaspberryPi Zero 摄像头流式传输实时视频。我使用Linux Project's UV4L driver 设置服务器和JavaScript 来连接和播放视频流。我的 JavaScript 代码基于UV4L's demo,它本质上使用 RTC Web 套接字方法来执行协商。
他们的代码在 Chrome 中运行良好,但在 Firefox 或 Safari 下似乎无法运行。
RTCPeerConnection = window.webkitRTCPeerConnection;
RTCSessionDescription = window.RTCSessionDescription;
RTCIceCandidate = window.RTCIceCandidate;
var ws;
function signal(url, onStream, onError, onClose, onMessage) {
if("WebSocket" in window) {
var pc;
ws = new WebSocket(url);
ws.onopen = function () {
var config = {"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]};
pc = new RTCPeerConnection(config); // <---- ERROR here.
pc.onicecandidate = function (event) {
// ... ICE negotiation.
};
if('ontrack' in pc) {
pc.ontrack = function(event) {
// ... set stream object and play
};
} else { // onaddstream() is deprecated
pc.onaddstream = function (event) {
// ... set stream object and play
};
}
// ... other event listeners.
ws.send(...); // Signals the remote peer to initiate a call
};
}
}
特别是,当我尝试连接时,我收到一个错误,在 Firefox v60.0.1 中抛出以下错误(在 Safari 中非常相似):
TypeError: RTCPeerConnection 不是构造函数
根据MDN docs,Firefox 从 v22 开始支持此构造函数。可能是什么问题?
【问题讨论】:
-
似乎是
RTCPeerConnection是不可构造的。你试过删除new吗? -
我刚试过,Chrome和Firefox都抱怨。错误消息说
RTCPeerConnection不能用作函数。
标签: javascript firefox websocket safari webrtc