Skip to content

Commit

Permalink
#71, #68 and #17 implemented in RTCMultiConnection-v1.4
Browse files Browse the repository at this point in the history
Mute only "remote" media streams:
connection.streams.mute({
—— audio: true,
—— video: true,
—— type: 'remote'
});

Mute all:
connection.streams.mute();

connection.mediaConstraints.mandatory = {
—— minWidth: 640,
—— maxWidth: 640,
—— minHeight: 480,
—— maxHeight: 480,
—— minFrameRate: 30
};

See #68 and #17 for further details.
  • Loading branch information
muaz-khan committed Jul 21, 2013
1 parent e94ed54 commit 8d76c0c
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 193 deletions.
149 changes: 100 additions & 49 deletions RTCMultiConnection/RTCMultiConnection-v1.4.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if (_channel)
self.channel = _channel;

if (self.socket)
if (self.socket && self.socket.onDisconnect)
self.socket.onDisconnect().remove();

self.isInitiator = true;
Expand Down Expand Up @@ -218,7 +218,8 @@

self.streams[streamid] = self._getStream({
stream: stream,
userid: self.userid
userid: self.userid,
type: 'local'
});

if (forcedCallback) forcedCallback(stream);
Expand Down Expand Up @@ -279,8 +280,7 @@

var participants = { },
isbroadcaster,
isAcceptNewSession = true,
RTCDataChannels = [];
isAcceptNewSession = true;

function newPrivateSocket(_config) {
var socketConfig = {
Expand Down Expand Up @@ -342,6 +342,10 @@
e.extra = _config.extra;
e.userid = _config.userid;
root.onclose(e);

// suggested in #71 by "efaj"
if (root.channels[e.userid])
delete root.channels[e.userid];
},
onerror: function(e) {
e.extra = _config.extra;
Expand Down Expand Up @@ -410,19 +414,15 @@
root.streams[streamid] = root._getStream({
stream: _config.stream,
userid: _config.userid,
socket: socket
socket: socket,
type: 'remote'
});

onSessionOpened();
}

function onChannelOpened(channel) {
RTCDataChannels[RTCDataChannels.length] = _config.channel = channel;

root.onopen({
extra: _config.extra,
userid: _config.userid
});
_config.channel = channel;

// connection.channels['user-id'].send(data);
root.channels[_config.userid] = {
Expand All @@ -431,6 +431,11 @@
root.send(data, this.channel);
}
};

root.onopen({
extra: _config.extra,
userid: _config.userid
});

if (isData(session)) onSessionOpened();
}
Expand Down Expand Up @@ -713,7 +718,7 @@

this.initSession = function() {
isbroadcaster = true;
isAcceptNewSession = false;
this.isOwnerLeaving = isAcceptNewSession = false;
(function transmit() {
if (getLength(participants) < root.maxParticipantsAllowed) {
defaultSocket && defaultSocket.send({
Expand All @@ -724,7 +729,7 @@
});
}

if (!root.transmitRoomOnce && !that.leaving)
if (!root.transmitRoomOnce && !that.isOwnerLeaving)
setTimeout(transmit, root.interval || 3000);
})();
};
Expand Down Expand Up @@ -757,10 +762,7 @@
};

this.send = function(message, _channel) {
var _channels = RTCDataChannels,
data, length = _channels.length;
if (!length)
return;
var data;

if (moz && message.file)
data = message.file;
Expand All @@ -770,8 +772,8 @@
if (_channel)
_channel.send(data);
else
for (var i = 0; i < length; i++)
_channels[i].send(data);
for (_channel in root.channels)
root.channels[_channel].channel.send(data);
};

this.leave = function(userid) {
Expand All @@ -782,6 +784,11 @@
root.joinedARoom = self.joinedARoom = isbroadcaster = false;
isAcceptNewSession = true;
}

if (isbroadcaster) {
this.isOwnerLeaving = true;
root.isInitiator = false;
}
};

this.addStream = function(e) {
Expand Down Expand Up @@ -1481,7 +1488,29 @@
};

self.peers = { };
self.streams = { };

self.streams = {
mute: function(session) {
this._private(session, true);
},
unmute: function(session) {
this._private(session, false);
},
_private: function(session, enabled) {
// implementation from #68
for (var stream in this) {
if (stream != 'mute' && stream != 'unmute' && stream != '_private') {
var root = this[stream];
muteOrUnmute({
root: root,
session: session,
stream: root.stream,
enabled: enabled
});
}
}
}
};
self.channels = { };
self.extra = { };

Expand Down Expand Up @@ -1509,6 +1538,7 @@
stream: e.stream,
userid: e.userid,
socket: e.socket,
type: e.type,
stop: function() {
var stream = this.stream;
if (stream && stream.stop)
Expand All @@ -1521,35 +1551,12 @@
this._private(session, false);
},
_private: function(session, enabled) {
var stream = this.stream;

if (e.socket)
e.socket.send({
userid: this.userid,
mute: !!enabled,
unmute: !enabled
});

// for local streams only
else
log('No socket to send mute/unmute notification message.');

session = session || {
audio: true,
video: true
};

if (session.audio) {
var audioTracks = stream.getAudioTracks()[0];
if (audioTracks)
audioTracks.enabled = !enabled;
}

if (session.video) {
var videoTracks = stream.getVideoTracks()[0];
if (videoTracks)
videoTracks.enabled = !enabled;
}
muteOrUnmute({
root: this,
session: session,
enabled: enabled,
stream: this.stream
});
}
};
};
Expand All @@ -1559,6 +1566,50 @@
};
}

function muteOrUnmute(e) {
var stream = e.stream,
root = e.root,
session = e.session || { },
enabled = e.enabled;

if (!session.audio && !session.video) {
session = merge(session, {
audio: true,
video: true
});
}

// implementation from #68
if (session.type) {
if (session.type == 'remote' && root.type != 'remote') return;
if (session.type == 'local' && root.type != 'local') return;
}

console.log('session', JSON.stringify(session, null, '\t'));

// enable/disable audio/video tracks

if (session.audio) {
var audioTracks = stream.getAudioTracks()[0];
if (audioTracks)
audioTracks.enabled = !enabled;
}

if (session.video) {
var videoTracks = stream.getVideoTracks()[0];
if (videoTracks)
videoTracks.enabled = !enabled;
}

// socket message to change media element look
if (root.socket)
root.socket.send({
userid: root.userid,
mute: !!enabled,
unmute: !enabled
});
}

function getLength(obj) {
var length = 0;
for (var o in obj) length++;
Expand Down
3 changes: 1 addition & 2 deletions websocket/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,13 @@ <h2>

<div id="participants"></div>

<script src="https://www.webrtc-experiment.com/dependencies/websocket.js"></script>
<script src="https://www.webrtc-experiment.com/RTCPeerConnection-v1.5.js"></script>
<script src="https://www.webrtc-experiment.com/websocket/rtclib.js"> </script>
<script src="https://www.webrtc-experiment.com/websocket/ui.js"></script>
<p>WebRTC one-to-one video sharing experiment where PubNub's WebSocket implementation is used for signaling.</p>
</article>
<article>
<h2>Use <a href="https://github.com/muaz-khan/WebRTC-Experiment/blob/master/websocket-over-nodejs" target="_blank">WebSocket over Node.js</a> for signaling! / <a href="http://websocket-over-nodejs.jit.su/" target="_blank">Demo</a></h2>
<h2>Use <a href="https://github.com/muaz-khan/WebRTC-Experiment/blob/master/websocket-over-nodejs" target="_blank">WebSocket over Node.js</a> for signaling! <!-- / <a href="http://websocket-over-nodejs.jit.su/" target="_blank">Demo</a> --> </h2>

<br />
<br />
Expand Down
Loading

0 comments on commit 8d76c0c

Please sign in to comment.