-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
7 changed files
with
1,699 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
Oops, something went wrong.