Skip to content

Commit

Permalink
Added [email protected] Keeping data channels opened on re…
Browse files Browse the repository at this point in the history
…negotiations.
  • Loading branch information
muaz-khan committed Mar 23, 2016
1 parent 5f8c2e6 commit 61340e3
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 217 deletions.
12 changes: 12 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ module.exports = function(grunt) {

var banner = '// Last time updated: <%= grunt.template.today("UTC:yyyy-mm-dd h:MM:ss TT Z") %>\n\n';

banner += '// _____________________\n';
banner += '// RTCMultiConnection-v3\n\n';

banner += '// Open-Sourced: https://github.com/muaz-khan/RTCMultiConnection\n\n';

banner += '// --------------------------------------------------\n';
banner += '// Muaz Khan - www.MuazKhan.com\n';
banner += '// MIT License - www.WebRTC-Experiment.com/licence\n';
banner += '// --------------------------------------------------\n\n';

banner += '\'use strict\';\n\n';

// configure project
grunt.initConfig({
// make node configurations available
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| DemoTitle | TestLive | ViewSource |
| ------------- |-------------|-------------|
| Audio+Video+File+Text | [Demo](https://rtcmulticonnection.herokuapp.com/demos/) | [Source](https://github.com/muaz-khan/RTCMultiConnection/tree/master/demos/Audio+Video+TextChat+FileSharing.html) |
| Audio+Video+File+TextChat | [Demo](https://rtcmulticonnection.herokuapp.com/demos/Audio+Video+TextChat+FileSharing.html) | [Source](https://github.com/muaz-khan/RTCMultiConnection/tree/master/demos/Audio+Video+TextChat+FileSharing.html) |
| FileSharing | [Demo](https://rtcmulticonnection.herokuapp.com/demos/file-sharing.html) | [Source](https://github.com/muaz-khan/RTCMultiConnection/tree/master/demos/file-sharing.html) |
| Scalable Audio/Video Broadcast | [Demo](https://rtcmulticonnection.herokuapp.com/demos/Scalable-Broadcast.html) | [Source](https://github.com/muaz-khan/RTCMultiConnection/tree/master/demos/Scalable-Broadcast.html) |
| Scalable Video Broadcast | [Demo](https://rtcmulticonnection.herokuapp.com/demos/Video-Scalable-Broadcast.html) | [Source](https://github.com/muaz-khan/RTCMultiConnection/tree/master/demos/Video-Scalable-Broadcast.html) |
Expand Down Expand Up @@ -134,7 +134,7 @@ All files from `/dist` directory are available on CDN: `https://cdn.webrtc-exper
<script src="https://cdn.webrtc-experiment.com:443/rmc3.min.js"></script>

<!-- or specific version -->
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.95/rmc3.min.js"></script>
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.96/rmc3.min.js"></script>
```

If you're sharing files, you also need to link:
Expand All @@ -146,7 +146,7 @@ If you're sharing files, you also need to link:
<script src="https://cdn.webrtc-experiment.com:443/rmc3.fbr.min.js"></script>

<!-- or specific version -->
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.95/rmc3.fbr.min.js"></script>
<script src="https://github.com/muaz-khan/RTCMultiConnection/releases/download/3.2.96/rmc3.fbr.min.js"></script>
```

> You can link multiple files from `dev` directory. Order doesn't matters.
Expand Down
89 changes: 59 additions & 30 deletions RTCMultiConnection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// Last time updated: 2016-03-17 11:15:54 AM UTC
// Last time updated: 2016-03-23 2:23:55 PM UTC

// ______________________________
// RTCMultiConnection-v3.0 (Beta)
// _____________________
// RTCMultiConnection-v3

// Open-Sourced: https://github.com/muaz-khan/RTCMultiConnection

// --------------------------------------------------
// Muaz Khan - www.MuazKhan.com
// MIT License - www.WebRTC-Experiment.com/licence
// --------------------------------------------------

'use strict';

Expand Down Expand Up @@ -1872,6 +1879,15 @@
if (remoteUserId) {
var remoteUser = connection.peers[remoteUserId];
if (remoteUser) {
if (!remoteUser.channels.length) {
connection.peers[remoteUserId].createDataChannel();
connection.renegotiate(remoteUserId);
setTimeout(function() {
that.send(data, remoteUserId);
}, 3000);
return;
}

remoteUser.channels.forEach(function(channel) {
channel.send(data);
});
Expand All @@ -1880,6 +1896,17 @@
}

this.getAllParticipants().forEach(function(participant) {
if (!that[participant].channels.length) {
connection.peers[participant].createDataChannel();
connection.renegotiate(participant);
setTimeout(function() {
that[participant].channels.forEach(function(channel) {
channel.send(data);
});
}, 3000);
return;
}

that[participant].channels.forEach(function(channel) {
channel.send(data);
});
Expand All @@ -1905,6 +1932,7 @@
dontAttachLocalStream: !!userPreferences.dontAttachLocalStream,
renegotiatingPeer: !!userPreferences.renegotiatingPeer,
peerRef: userPreferences.peerRef,
channels: userPreferences.channels || [],
onLocalSdp: function(localSdp) {
self.onNegotiationNeeded(localSdp, remoteUserId);
},
Expand Down Expand Up @@ -2034,6 +2062,7 @@

userPreferences.renegotiatingPeer = true;
userPreferences.peerRef = connection.peers[remoteUserId].peer;
userPreferences.channels = connection.peers[remoteUserId].channels;

var localConfig = this.getLocalConfig(remoteSdp, remoteUserId, userPreferences);

Expand Down Expand Up @@ -2276,6 +2305,7 @@
this.onDataChannelOpened = function(channel, remoteUserId) {
// keep last channel only; we are not expecting parallel/channels channels
if (connection.peers[remoteUserId].channels.length) {
connection.peers[remoteUserId].channels = [channel];
return;
}

Expand Down Expand Up @@ -3615,10 +3645,10 @@
this.extra = config.remoteSdp ? config.remoteSdp.extra : connection.extra;
this.userid = config.userid;
this.streams = [];
this.channels = [];
this.channels = config.channels || [];
this.connectionDescription = config.connectionDescription;

var that = this;
var self = this;

if (config.remoteSdp) {
this.connectionDescription = config.remoteSdp.connectionDescription;
Expand Down Expand Up @@ -3691,7 +3721,7 @@
sdp: localSdp.sdp,
remotePeerSdpConstraints: config.remotePeerSdpConstraints || false,
renegotiatingPeer: !!config.renegotiatingPeer || false,
connectionDescription: that.connectionDescription,
connectionDescription: self.connectionDescription,
dontGetRemoteStream: !!config.dontGetRemoteStream,
extra: connection ? connection.extra : {},
streamsToShare: streamsToShare,
Expand Down Expand Up @@ -3730,9 +3760,9 @@
});

peer.oniceconnectionstatechange = peer.onsignalingstatechange = function() {
var extra = that.extra;
if (connection.peers[that.userid]) {
extra = connection.peers[that.userid].extra || extra;
var extra = self.extra;
if (connection.peers[self.userid]) {
extra = connection.peers[self.userid].extra || extra;
}

if (!peer) {
Expand All @@ -3744,7 +3774,7 @@
iceGatheringState: peer.iceGatheringState,
signalingState: peer.signalingState,
extra: extra,
userid: that.userid
userid: self.userid
});
};

Expand Down Expand Up @@ -3797,9 +3827,9 @@
peer.addIceCandidate(new RTCIceCandidate(remoteCandidate));
};

this.addRemoteSdp = function(remoteSdp) {
this.addRemoteSdp = function(remoteSdp, cb) {
remoteSdp.sdp = connection.processSdp(remoteSdp.sdp);
peer.setRemoteDescription(new RTCSessionDescription(remoteSdp), function() {}, function(error) {
peer.setRemoteDescription(new RTCSessionDescription(remoteSdp), cb || function() {}, function(error) {
if (!!connection.enableLogs) {
console.error(JSON.stringify(error, null, '\t'), '\n', remoteSdp.type, remoteSdp.sdp);
}
Expand All @@ -3812,29 +3842,28 @@
isOfferer = false;
}

if (connection.session.data === true) {
createDataChannel();
}

if (config.remoteSdp) {
if (config.remoteSdp.remotePeerSdpConstraints) {
sdpConstraints = config.remoteSdp.remotePeerSdpConstraints;
}
defaults.sdpConstraints = setSdpConstraints(sdpConstraints);
this.addRemoteSdp(config.remoteSdp);
}
this.createDataChannel = function() {
var channel = peer.createDataChannel('sctp', {});
setChannelEvents(channel);
};

function createDataChannel() {
if (connection.session.data === true && !renegotiatingPeer) {
if (!isOfferer) {
peer.ondatachannel = function(event) {
var channel = event.channel;
setChannelEvents(channel);
};
return;
} else {
this.createDataChannel();
}
}

var channel = peer.createDataChannel('RTCDataChannel', {});
setChannelEvents(channel);
if (config.remoteSdp) {
if (config.remoteSdp.remotePeerSdpConstraints) {
sdpConstraints = config.remoteSdp.remotePeerSdpConstraints;
}
defaults.sdpConstraints = setSdpConstraints(sdpConstraints);
this.addRemoteSdp(config.remoteSdp);
}

function setChannelEvents(channel) {
Expand Down Expand Up @@ -3895,7 +3924,7 @@
sdp: localSdp.sdp,
remotePeerSdpConstraints: config.remotePeerSdpConstraints || false,
renegotiatingPeer: !!config.renegotiatingPeer || false,
connectionDescription: that.connectionDescription,
connectionDescription: self.connectionDescription,
dontGetRemoteStream: !!config.dontGetRemoteStream,
extra: connection ? connection.extra : {},
streamsToShare: streamsToShare,
Expand Down Expand Up @@ -3923,7 +3952,7 @@
} catch (e) {}

peer = null;
that.peer = null;
self.peer = null;
};

this.peer = peer;
Expand Down Expand Up @@ -4331,7 +4360,7 @@
}

function getExtenralIceFormatted() {
var iceServers;
var iceServers = [];
window.RMCExternalIceServers.forEach(function(ice) {
if (!ice.urls) {
ice.urls = ice.url;
Expand Down
20 changes: 16 additions & 4 deletions RTCMultiConnection.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions demos/Audio+Video+TextChat+FileSharing.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ <h1>Audio+Video+TextChat+FileSharing using RTCMultiConnection-v3.0</h1>
<div id="videos-container"></div>
</section>

<!-- <script src="https://cdn.webrtc-experiment.com:443/rmc3.min.js"></script> -->
<script src="/dist/rmc3.min.js"></script>
<!-- <script src="/dist/rmc3.min.js"></script> -->
<script src="https://cdn.webrtc-experiment.com:443/rmc3.min.js"></script>

<!-- <script src="/dev/FileBufferReader.js"></script> -->
<script src="https://cdn.webrtc-experiment.com:443/rmc3.fbr.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion demos/Video-Conferencing.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h1>Video Conferencing using RTCMultiConnection-v3.0</h1>
</section>

<!-- <script src="/dist/rmc3.min.js"></script> -->
<script src="/dist/rmc3.min.js"></script>
<script src="https://cdn.webrtc-experiment.com/rmc3.min.js"></script>

<!-- socket.io for signaling -->
<script src="/socket.io/socket.io.js"></script>
Expand Down
5 changes: 3 additions & 2 deletions demos/addStream-in-Chat-room.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ <h1>addStream in a Chat Room using RTCMultiConnection-v3.0</h1>
</section>

<!-- <script src="/RTCMultiConnection.min.js"></script> -->
<script src="https://cdn.webrtc-experiment.com:443/rmc3.min.js"></script>
<script src="https://cdn.webrtc-experiment.com/rmc3.min.js"></script>

<!-- <script src="/dev/FileBufferReader.js"></script> -->
<script src="https://cdn.webrtc-experiment.com:443/rmc3.fbr.min.js"></script>
<script src="/dist/rmc3.fbr.min.js"></script>

<!-- socket.io for signaling -->
<script src="/socket.io/socket.io.js"></script>
Expand Down Expand Up @@ -226,6 +226,7 @@ <h1>addStream in a Chat Room using RTCMultiConnection-v3.0</h1>
video: true,
oneway: true
});

document.getElementById('btn-removeStream').disabled = false;
};

Expand Down
Loading

0 comments on commit 61340e3

Please sign in to comment.