Node.js peerjs节点无浏览器
我正在使用peerJs()创建一个运行在pc上并连接到服务器的小nodeJS脚本。 我通过在web浏览器上打开来运行它,它可以工作,但我需要使用nodeJS,而不是使用浏览器 我创造了这样的东西:Node.js peerjs节点无浏览器,node.js,peerjs,Node.js,Peerjs,我正在使用peerJs()创建一个运行在pc上并连接到服务器的小nodeJS脚本。 我通过在web浏览器上打开来运行它,它可以工作,但我需要使用nodeJS,而不是使用浏览器 我创造了这样的东西: window = global; window.BlobBuilder = require("BlobBuilder"); location = { protocol: 'http' }; BinaryPack = require("binary-pack"); XMLHttpRequest = r
window = global;
window.BlobBuilder = require("BlobBuilder");
location = { protocol: 'http' };
BinaryPack = require("binary-pack");
XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var path = require("path");
var wrtc = require("wrtc");
var peerjs = require('peerjs');
RTCPeerConnection = wrtc.RTCPeerConnection;
RTCSessionDescription = wrtc.RTCSessionDescription;
RTCIceCandidate = wrtc.RTCIceCandidate;
WebSocket = require('ws');
var peer = new peerjs({
key: 'b0yke14mnsev1jor',
// Set highest debug level (log everything!).
debug: 3,
// Set a logging function:
logFunction: function() {
var copy = Array.prototype.slice.call(arguments).join(' ');
}
});
peer.on('connection', function(conn) {
conn.on('open', function() {
console.log("peer connected"); // This fires as expected
conn.send("helo");
});
});
peer.on('open', function(id) {
console.log('My peer ID is: ' + id);
});
peer.on('error', function(err) {
console.log(err);
});
当我使用node server.js运行它时,会出现以下错误:
node server.js
谢谢 如果要继续为此使用peerjs客户端库,则需要对其进行修改 话虽如此,代码查询rtpeerconnection以查看浏览器的功能,但此方法在服务器中不存在(即像您一样运行nodejs)。如果强制发送此错误消息,您可以停止发送此错误消息,但当您尝试调用某个webrtc函数时,会再次遇到此问题 看看这个问题的答案: 正如你将看到的,这不是一件简单的事情。祝你好运
{ Error: The current browser does not support WebRTC
at Peer.emitError (C:\nodeworkspace\playground\PeerJS\iperiusRemoteHost\node_modules\peerjs\lib\peer.js:372:15)
at Peer._abort (C:\nodeworkspace\playground\PeerJS\iperiusRemoteHost\node_modules\peerjs\lib\peer.js:365:10)
at Timeout._onTimeout (C:\nodeworkspace\playground\PeerJS\iperiusRemoteHost\node_modules\peerjs\lib\peer.js:349:14)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5) type: 'browser-incompatible' }