-1

I'm using peerJs (http://peerjs.com/docs/) to create a little nodeJS script running on pc and connected to a server. I run it by opening on a web browser and it works but I need to use nodeJS and not use browser.

I created something like this :

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);

});

When I run it using node server.js, I get this error:

node server.js

{ 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' }

Thanks!

Saqib Omer
  • 5,387
  • 7
  • 50
  • 71
byteo
  • 1
  • 3

1 Answers1

1

If you want to continue using the peerjs client library for this, you will need to make modifications to it.

Having said that, the code queries RTCPeerConnection to look at the capabilities of the browser, but this method won't exist in the server (ie running nodejs as you are). You could stop if from giving you this error message by forcing it, but you will hit the problem again when you try and call some webrtc function.

Have a look at the answers to this question: Making a node.js application a PEER with WebRTC

As you will read, this is not a simple matter. Good luck!

Mikkel
  • 7,693
  • 3
  • 17
  • 31