This experiment is using socket.io over node.js for signaling. Follow these steps:
- Download and extract ZIP file of this repository then copy
folder-location
of thesignaler.js
file - Open Node.js command prompt window
- Type command
cd folder-location
wherefolder-location
can beC:\socketio-over-nodejs
- Type
npm install express
or download ZIP - Type
npm install socket.io
or download ZIP - Type
node signaler
to run the node.js server
Then open http://localhost:8888/
.
=
- Create an account at
nodejitsu
- Use same Node.js command prompt window
- Type
jitsu deploy
and you're done!
Remember: jitsu deploy
command will deploy the entire directory containing all all files including node_modules
(i.e. dependencies).
=
In ui.js
files you can find openSocket
method; or in all libraries; you can find openSignalingChannel
method.
var SIGNALING_SERVER = 'http://webrtc-signaling.jit.su:80/';
connection.openSignalingChannel = function(config) {
var channel = config.channel || this.channel || 'default-namespace';
var sender = Math.round(Math.random() * 9999999999) + 9999999999;
io.connect(SIGNALING_SERVER).emit('new-channel', {
channel: channel,
sender : sender
});
var socket = io.connect(SIGNALING_SERVER + channel);
socket.channel = channel;
socket.on('connect', function () {
if (config.callback) config.callback(socket);
});
socket.send = function (message) {
socket.emit('message', {
sender: sender,
data : message
});
};
socket.on('message', config.onmessage);
};
io.connect(URL).emit('new-channel')
starts a new namespace that is used privately or publicly to transmit/exchange appropriate stuff e.g. room-details, participation-requests, SDP, ICE, etc.
=
You can detect presence of a room like this:
var SIGNALING_SERVER = 'http://webrtc-signaling.jit.su:80/';
function testChannelPresence(channel) {
var socket = io.connect(SIGNALING_SERVER);
socket.on('presence', function (isChannelPresent) {
console.log('is channel present', isChannelPresent);
if (!isChannelPresent) startNewSession();
});
socket.emit('presence', channel);
}
// test whether default channel already created or not!
testChannelPresence('default-channel');
=
Using this command; you can open project's directory (i.e. folder).
=
This command runs node.js server via signaler.js
file. That file handles socket.io relevant stuff.
=
This command deploys the entire directory (i.e. project, including all node_modules
dependencies) over nodejitsu
servers. You will be able to access your deployed project using URL like this:
http://username.jit.su/
See the demo URL: http://webrtc-signaling.jit.su/
=
Each experiment is using something like this:
var SIGNALING_SERVER = '/';
This is the URL of your site. By default it will be equal to http://localhost:8888/
.
It is strongly recommended to use absolute URL including port number:
var SIGNALING_SERVER = 'http://domain.com:8888/';
=
- To run socket.io on your computer; you need to download
node.js
software fromnodejs.org
. - If you're using windows; in the
Start Menus
; you can typenode
in the search-box.Node.js command prompt
will be listed on the top. - You can use same command prompt to run any
node.js
file; also you can writenodejitsu
commands in the same place e.g.jitsu deploy
orjitsu login
etc. - Default port
8888
is used for this experiment. You can manually open this URL:http://localhost:8888/
=
Interested to understand WebRTC Signaling Concepts? Read this document.
=
muaz-khan/WebRTC-Experiment#62
=
Socket.io over Node.js is released under MIT licence . Copyright (c) 2013 Muaz Khan.