I made the signaling server by using webRTC. This is why I made the signaling server(signaling.js).
What should I do to solve this problem?
・signaling.js
"use strict";
let WebSocketServer = require('ws').Server;
let port = 3001;
let wsServer = new WebSocketServer({ port: port });
console.log('websocket server start. port=' + port);
wsServer.on('connection', function(ws) {
console.log('-- websocket connected --');
ws.on('message', function(message) {
wsServer.clients.forEach(function each(client) {
if (isSame(ws, client)) {
console.log('- skip sender -');
}
else {
client.send(message);
}
});
});
});
function isSame(ws1, ws2) {
// -- compare object --
return (ws1 === ws2);
} let wsUrl = 'ws://localhost:3001/';
let ws = new WebSocket(wsUrl);
ws.onopen = function(evt) {
console.log('ws open()');
};
ws.onerror = function(err) {
console.error('ws onerror() ERR:', err);
};
ws.onmessage = function(evt) {
console.log('ws onmessage() data:', evt.data);
let message = JSON.parse(evt.data);
if (message.type === 'offer') {
// -- got offer ---
console.log('Received offer ...');
textToReceiveSdp.value = message.sdp;
let offer = new RTCSessionDescription(message);
setOffer(offer);
}
else if (message.type === 'answer') {
// --- got answer ---
console.log('Received answer ...');
textToReceiveSdp.value = message.sdp;
let answer = new RTCSessionDescription(message);
setAnswer(answer);
}
};
function sendSdp(sessionDescription) {
console.log('---sending sdp ---');
textForSendSdp.value = sessionDescription.sdp;
/*--- テキストエリアをハイライトするのを止める
textForSendSdp.focus();
textForSendSdp.select();
----*/
// --- シグナリングサーバーに送る ---
let message = JSON.stringify(sessionDescription);
console.log('sending SDP=' + message);
ws.send(message);
}
When I load the "signaling.js", I set the node.js. After that, I access signaling.js. However, It listed upgrade required.
I searched how to upgrade node.js.
I tried
Linux/Mac:
The module n makes version-management easy:
sudo npm install n -g
sudo n 0.12.2
For the latest stable version:
sudo n stable
For the latest version:
sudo n latest
after this, I accessed signaling.js
/signaling.js:26
let ws = new WebSocket(wsUrl);
^
ReferenceError: WebSocket is not defined
at Object.<anonymous> (/Users/Desktop/webRTC/signaling.js:26:16)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3