Skip to content

Instantly share code, notes, and snippets.

@kkm
Created September 1, 2017 07:28
Show Gist options
  • Save kkm/41b4ce92ee9b9f08e06a1ab8912b8a38 to your computer and use it in GitHub Desktop.
Save kkm/41b4ce92ee9b9f08e06a1ab8912b8a38 to your computer and use it in GitHub Desktop.
var socketIO = require('socket.io');
var server = require('http').createServer().listen(7000);
var io = socketIO.listen(server);
console.log((new Date()) + " Server is listening on port 7000");
io.sockets.on('connection', function (client) {
console.log('New Client Connection: ' + client.id);
client.on('offer', function (details) {
client.broadcast.emit('offer', details);
console.log(`OFFER (${client.id}):`,details.sdp);
console.log('----------------------------------------------');
});
client.on('answer', function (details) {
client.broadcast.emit('answer', details);
console.log(`ANSWER (${client.id}):`, details.sdp);
console.log('----------------------------------------------');
});
client.on('candidate', function (details) {
client.broadcast.emit('candidate', details);
console.log(`CANDIDATE (${client.id}):`);
console.log(details.sdpMid);
console.log(details.sdpMLineIndex);
console.log(details.sdp);
console.log('----------------------------------------------');
});
// Here starts evertyhing!
// The first connection doesn't send anything (no other clients)
// Second connection emits the message to start the SDP negotation
client.broadcast.emit('createoffer', {});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment