Skip to content

Commit

Permalink
All experiments are socket.io over node.js compatible
Browse files Browse the repository at this point in the history
https://github.com/muaz-khan/WebRTC-Experiment/tree/master/socketio-over-nodejs

Change JUST "openSignalingChannel" or "openSocket" method; and you're
done!
  • Loading branch information
muaz-khan committed May 31, 2013
1 parent b38a228 commit b2e7789
Show file tree
Hide file tree
Showing 20 changed files with 2,099 additions and 1,818 deletions.
2 changes: 1 addition & 1 deletion DataChannel/DataChannel.js
Expand Up @@ -972,4 +972,4 @@
}
};
}
})();
})();
125 changes: 67 additions & 58 deletions Pluginfree-Screen-Sharing/conference.js
@@ -1,17 +1,22 @@
var conference = function (config) {
/* MIT License: https://webrtc-experiment.appspot.com/licence/ */

var conference = function (config) {
var self = {
userToken: uniqueToken()
},
channels = '--',
isbroadcaster,
isGetNewRoom = true,
participants = 1,
defaultSocket = {};
channels = '--',
isbroadcaster,
isGetNewRoom = true,
participants = 1,
defaultSocket = {};

function openDefaultSocket() {
defaultSocket = config.openSocket({
onmessage: defaultSocketResponse
});
onmessage: defaultSocketResponse,
callback: function (socket) {
defaultSocket = socket;
}
});
}

function defaultSocketResponse(response) {
Expand All @@ -24,10 +29,10 @@
if (response.userToken && response.joinUser == self.userToken && response.participant && channels.indexOf(response.userToken) == -1) {
channels += response.userToken + '--';
openSubSocket({
isofferer: true,
channel: response.channel || response.userToken,
closeSocket: true
});
isofferer: true,
channel: response.channel || response.userToken,
closeSocket: true
});
}
}

Expand All @@ -41,6 +46,11 @@
}
};

socketConfig.callback = function (_socket) {
socket = _socket;
this.onopen();
};

var socket = config.openSocket(socketConfig),
isofferer = _config.isofferer,
gotstream,
Expand All @@ -52,12 +62,12 @@
attachStream: config.attachStream,
onICE: function (candidate) {
socket && socket.send({
userToken: self.userToken,
candidate: {
sdpMLineIndex: candidate.sdpMLineIndex,
candidate: JSON.stringify(candidate.candidate)
}
});
userToken: self.userToken,
candidate: {
sdpMLineIndex: candidate.sdpMLineIndex,
candidate: JSON.stringify(candidate.candidate)
}
});
},
onRemoteStream: function (stream) {
htmlElement[moz ? 'mozSrcObject' : 'src'] = moz ? stream : webkitURL.createObjectURL(stream);
Expand Down Expand Up @@ -87,15 +97,15 @@
gotstream = true;

config.onRemoteStream({
video: htmlElement
});
video: htmlElement
});

if (isbroadcaster && channels.split('--').length > 3) {
/* broadcasting newly connected participant for video-conferencing! */
defaultSocket && defaultSocket.send({
newParticipant: socket.channel,
userToken: self.userToken
});
newParticipant: socket.channel,
userToken: self.userToken
});
}

/* closing subsocket here on the offerer side */
Expand All @@ -116,19 +126,19 @@
}

socket && socket.send({
userToken: self.userToken,
firstPart: firstPart
});
userToken: self.userToken,
firstPart: firstPart
});

socket && socket.send({
userToken: self.userToken,
secondPart: secondPart
});
userToken: self.userToken,
secondPart: secondPart
});

socket && socket.send({
userToken: self.userToken,
thirdPart: thirdPart
});
userToken: self.userToken,
thirdPart: thirdPart
});
}

function socketResponse(response) {
Expand All @@ -151,9 +161,9 @@

if (response.candidate && !gotstream) {
peer && peer.addICE({
sdpMLineIndex: response.candidate.sdpMLineIndex,
candidate: JSON.parse(response.candidate.candidate)
});
sdpMLineIndex: response.candidate.sdpMLineIndex,
candidate: JSON.parse(response.candidate.candidate)
});
}
}

Expand All @@ -166,19 +176,18 @@

inner.sdp = JSON.parse(inner.firstPart + inner.secondPart + inner.thirdPart);
if (isofferer) {
peer.addAnswerSDP(inner.sdp);
if(config.onNewParticipant) config.onNewParticipant(participants++);
}
else initPeer(inner.sdp);
peer.addAnswerSDP(inner.sdp);
if (config.onNewParticipant) config.onNewParticipant(participants++);
} else initPeer(inner.sdp);
}
}

function startBroadcasting() {
defaultSocket && defaultSocket.send({
roomToken: self.roomToken,
roomName: self.roomName,
broadcaster: self.userToken
});
roomToken: self.roomToken,
roomName: self.roomName,
broadcaster: self.userToken
});
setTimeout(startBroadcasting, 3000);
}

Expand All @@ -188,16 +197,16 @@

var new_channel = uniqueToken();
openSubSocket({
channel: new_channel,
closeSocket: true
});
channel: new_channel,
closeSocket: true
});

defaultSocket.send({
participant: true,
userToken: self.userToken,
joinUser: channel,
channel: new_channel
});
participant: true,
userToken: self.userToken,
joinUser: channel,
channel: new_channel
});
}

function uniqueToken() {
Expand All @@ -219,14 +228,14 @@
isGetNewRoom = false;

openSubSocket({
channel: self.userToken
});
channel: self.userToken
});

defaultSocket.send({
participant: true,
userToken: self.userToken,
joinUser: _config.joinUser
});
participant: true,
userToken: self.userToken,
joinUser: _config.joinUser
});
}
};
};
};
2 changes: 1 addition & 1 deletion RTCMultiConnection/RTCMultiConnection-v1.1.js
Expand Up @@ -1048,4 +1048,4 @@ var FileSaver = {

(window.URL || window.webkitURL).revokeObjectURL(save.href);
}
};
};

0 comments on commit b2e7789

Please sign in to comment.