Skip to content

Commit

Permalink
Fixing #38, and may be #39
Browse files Browse the repository at this point in the history
Channel presence in "socket.io over node.js" can be detected like this:

function testChannelPresence(channel) {
var socket = io.connect('/');

socket.on('presence', function (isChannelPresent) {
console.log('is channel present', isChannelPresent);
if (!isChannelPresent) playRoleOfSessionInitiator();
});

socket.emit('presence', channel);
}
testChannelPresence('default-channel');

Demo: http://webrtc-signaling.jit.su/RTCMultiConnection

Socket.io over Node.js source code:

https://github.com/muaz-khan/WebRTC-Experiment/tree/master/socketio-over-nodejs
  • Loading branch information
muaz-khan committed Jun 3, 2013
1 parent 2a5d63a commit 83cd060
Show file tree
Hide file tree
Showing 7 changed files with 1,699 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DataChannel/DataChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
self.sockets = self.sockets.swap();
}

window.onunload = function () {
window.onbeforeunload = function () {
leaveChannels();
};

Expand Down
6 changes: 5 additions & 1 deletion RTCMultiConnection/RTCMultiConnection-v1.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,13 @@

var that = this;

window.onunload = function () {
window.onbeforeunload = function () {
leaveARoom();
};

window.onkeyup = function (e) {
if (e.keyCode == 116) leaveARoom();
};

(function () {
var anchors = document.querySelectorAll('a'),
Expand Down
4 changes: 2 additions & 2 deletions RTCMultiConnection/RTCMultiConnection-v1.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@
sockets = sockets.swap();
}

window.onunload = function () {
window.onbeforeunload = function () {
leaveARoom();
};

Expand Down Expand Up @@ -1068,7 +1068,7 @@
bandwidth = options.bandwidth;

function setBandwidth(sdp) {
if(bandwidth.audio == 50 && bandwidth.video == 256) return sdp;
//if(bandwidth.audio == 50 && bandwidth.video == 256) return sdp;
sdp = sdp.replace(/a=mid:audio\r\n/g, 'a=mid:audio\r\nb=AS:' + (bandwidth.audio || 50) + '\r\n');
sdp = sdp.replace(/a=mid:video\r\n/g, 'a=mid:video\r\nb=AS:' + (bandwidth.video || 256) + '\r\n');
return sdp;
Expand Down
74 changes: 52 additions & 22 deletions socketio-over-nodejs/webrtc-signaling/signaler.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,105 @@
/* MIT License: https://webrtc-experiment.appspot.com/licence/ -- https://github.com/muaz-khan */

// var port = 80; // use port:80 for non-localhost tests
var port = 8888; // use port:8888 for localhost tests

var port = 8888;
// use port:80 for non-localhost (i.e. real) web servers
var app = require('express')(),
server = require('http').createServer(app),
io = require('socket.io').listen(server);
server = require('http').createServer(app),
io = require('socket.io').listen(server);

server.listen(port);

/* -------------- for presence detection! -------------- */

var channels = {};

/* -------------- <socket.io> -------------- */

io.sockets.on('connection', function (socket) {
if (!io.connected) io.connected = true;
io.sockets.on('connection', function(socket) {
var initiatorChannel = '';
if (!io.connected)
io.connected = true;

socket.on('new-channel', function (data) {
socket.on('new-channel', function(data) {
channels[data.channel] = data.channel;
onNewNamespace(data.channel, data.sender);
});

socket.on('presence', function(channel) {
var isChannelPresent = !!channels[channel];
socket.emit('presence', isChannelPresent);
if (!isChannelPresent)
initiatorChannel = channel;
});

socket.on('disconnect', function(channel) {
if (initiatorChannel)
channels[initiatorChannel] = null;
});
});

function onNewNamespace(channel, sender) {
io.of('/' + channel).on('connection', function (socket) {
io.of('/' + channel).on('connection', function(socket) {
if (io.isConnected) {
io.isConnected = false;
socket.emit('connect', true);
}

socket.on('message', function (data) {
if (data.sender == sender) socket.broadcast.emit('message', data.data);
socket.on('message', function(data) {
if (data.sender == sender)
socket.broadcast.emit('message', data.data);
});
});
}

/* -------------- </socket.io> -------------- */

app.get('/', function (req, res) {
app.get('/', function(req, res) {
res.sendfile(__dirname + '/static/video-conferencing/index.html');
});

app.get('/socketio.js', function (req, res) {
app.get('/socketio.js', function(req, res) {
res.setHeader('Content-Type', 'application/javascript');
res.sendfile(__dirname + '/static/socket.io.js');
});

app.get('/RTCPeerConnection-v1.5.js', function (req, res) {
app.get('/RTCPeerConnection-v1.5.js', function(req, res) {
res.setHeader('Content-Type', 'application/javascript');
res.sendfile(__dirname + '/static/video-conferencing/RTCPeerConnection-v1.5.js');
});

app.get('/conference.js', function (req, res) {
app.get('/conference.js', function(req, res) {
res.setHeader('Content-Type', 'application/javascript');
res.sendfile(__dirname + '/static/video-conferencing/conference.js');
});

app.get('/conference-ui.js', function (req, res) {
app.get('/conference-ui.js', function(req, res) {
res.setHeader('Content-Type', 'application/javascript');
res.sendfile(__dirname + '/static/video-conferencing/conference-ui.js');
});

// text chat
app.get('/chat', function (req, res) {
/* -------------- text chat -------------- */
app.get('/chat', function(req, res) {
res.sendfile(__dirname + '/static/text-chat.html');
});

// following lines aimed to auto-open the browser
/* -------------- RTCMultiConnection demos -------------- */

app.get('/RTCMultiConnection', function(req, res) {
res.sendfile(__dirname + '/static/RTCMultiConnection/index.html');
});

app.get('/RTCMultiConnection-v1.2.js', function(req, res) {
res.setHeader('Content-Type', 'application/javascript');
res.sendfile(__dirname + '/static/RTCMultiConnection/RTCMultiConnection-v1.2.js');
});

// following lines aimed to auto-open the browser instance
// you can remove them if causing failure
var childProcess = require('child_process'),
openURL = 'http://localhost:' + port + '/';
openURL = 'http://localhost:' + port + '/';

var chromeURL = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
firefoxURL = 'c:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe';
firefoxURL = 'c:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe';

childProcess.spawn(chromeURL, ['-incognito', openURL]);
//childProcess.spawn(firefoxURL, ['-new-tab', openURL]);
//childProcess.spawn(firefoxURL, ['-new-tab', openURL]);
Loading

0 comments on commit 83cd060

Please sign in to comment.