video works both ways!!

This commit is contained in:
Manuel Araoz 2014-04-24 18:24:03 -03:00
commit 97014cdace
2 changed files with 12 additions and 12 deletions

View file

@ -4,6 +4,8 @@ var Video = function() {
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
this.mediaConnections = {};
};
Video.prototype.setOwnPeer = function(peer, wallet, cb) {
@ -16,12 +18,13 @@ Video.prototype.setOwnPeer = function(peer, wallet, cb) {
// This is called when user accepts using webcam
self.localStream = stream;
var online = wallet.getOnlinePeerIDs();
for (var i=0; i<online.length; i++) {
for (var i = 0; i < online.length; i++) {
var o = online[i];
var mc = self.mediaConnections[o];
if (o !== peer.id) {
self.callPeer(o, cb);
}
}
}
cb(null, peer.id, URL.createObjectURL(stream));
}, function() {
cb(new Error('Failed to access the webcam and microphone.'));
@ -29,17 +32,14 @@ Video.prototype.setOwnPeer = function(peer, wallet, cb) {
// Receiving a call
peer.on('call', function(mediaConnection) {
alert('answering call from ' + mediaConnection.peer);
if (self.localStream) {
mediaConnection.answer(self.localStream);
} else {
mediaConnection.answer();
}
self.mediaConnections[mediaConnection.peer] = mediaConnection;
self._addCall(mediaConnection, cb);
});
peer.on('error', function(err) {
alert('error on video peer '+err);
});
this.peer = peer;
};
@ -52,19 +52,15 @@ Video.prototype.callPeer = function(peerID, cb) {
Video.prototype._addCall = function(mediaConnection, cb) {
var peerID = mediaConnection.peer;
alert('_addCall ' + peerID);
// Wait for stream on the call, then set peer video display
mediaConnection.on('stream', function(stream) {
alert('STREAM ON ADD CALL');
cb(null, peerID, URL.createObjectURL(stream));
});
mediaConnection.on('close', function() {
alert('CLOSEEEEEEEEEEEEEEE ON ADD CALL');
});
mediaConnection.on('error', function() {
alert('ERROR ON ADD CALL');
});
}