WebRTC

node.js websocket Server für WebRTC

websocket muss installiert sein!!!

npm install -g websocket

 

Hier mein Websocket Server js.
var WebSocketServer = require('websocket').server;
var http = require('http');
var clients = [];

var server = http.createServer(function(request, response) {
});
server.listen(1337, function() {
console.log((new Date()) + " Server is listening on port 1337");
});

wsServer = new WebSocketServer({
httpServer: server
});

function originIsAllowed(origin) {
console.log((new Date()) + ' originIsAllowed ' + origin + '.');
if (origin != "http://www.soho-piper.de"){
return false;
}
}
function sendCallback(err) {
if (err) console.error("send() error: " + err);
}
wsServer.on('request', function(request) {

if (!originIsAllowed(request.origin)){
request.reject();
console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
return;
}

console.log((new Date()) + ' Connection from origin ' + request.origin + ' accepted.');
var connection = request.accept(null, request.origin);
console.log(' Connection ' + connection.remoteAddress);
clients.push(connection);

connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log((new Date()) + ' Received Message ' + message.utf8Data);
clients.forEach(function (outputConnection) {
if (outputConnection != connection) {
outputConnection.send(message.utf8Data, sendCallback);
}
});
}
});

connection.on('close', function(connection) {
console.log((new Date()) + " Peer disconnected.");
});
});

ngrep websocket RTCPeerConnection SDP Chrome Beta

Die Chrome Beta Version hat schon den opus/48000 Audio Codec und den VP8/90000 Video Codec.

isRTCPeerConnection: true www.soho-piper.de:82
SEND: {"sdp":"v=0
o=- 3117233998 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video
m=audio 1 RTP/SAVPF 103 104 111 0 8 106 105 13 126
c=IN IP4 0.0.0.0
a=rtcp:1 IN IP4 0.0.0.0
a=ice-ufrag:EohH2MyR2LBzUGLn
a=ice-pwd:IbGkWyhCr73E9Jnjn/FV5qPL
a=ice-options:google-ice
a=sendrecv
a=mid:audio
a=rtcp-mux
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:9dVqc72ok2wFPh6GFvEMDkk7aDAqmQjukd/ItjZX
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:111 opus/48000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 CN/32000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:126 telephone-event/8000
a=ssrc:2262201577 cname:1IsV42jXVbXIX3XA
a=ssrc:2262201577 msid:FtDKFx4ghoDhLuiUVlmsxYJHdlijwl9IyjOA a0
a=ssrc:2262201577 mslabel:FtDKFx4ghoDhLuiUVlmsxYJHdlijwl9IyjOA
a=ssrc:2262201577 label:FtDKFx4ghoDhLuiUVlmsxYJHdlijwl9IyjOAa0
m=video 1 RTP/SAVPF 100 101 102
c=IN IP4 0.0.0.0
a=rtcp:1 IN IP4 0.0.0.0
a=ice-ufrag:EohH2MyR2LBzUGLn
a=ice-pwd:IbGkWyhCr73E9Jnjn/FV5qPL
a=ice-options:google-ice
a=sendrecv\r\na=mid:video
a=rtcp-mux\r\n
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:9dVqc72ok2wFPh6GFvEMDkk7aDAqmQjukd/ItjZX
a=rtpmap:100 VP8/90000
a=rtpmap:101 red/90000
a=rtpmap:102 ulpfec/90000
a=ssrc:684625129 cname:1IsV42jXVbXIX3XA
a=ssrc:684625129 msid:FtDKFx4ghoDhLuiUVlmsxYJHdlijwl9IyjOA v0
a=ssrc:684625129 mslabel:FtDKFx4ghoDhLuiUVlmsxYJHdlijwl9IyjOA
a=ssrc:684625129 label:FtDKFx4ghoDhLuiUVlmsxYJHdlijwl9IyjOAv0","type":"offer"}