self video working
This commit is contained in:
parent
db1cba99fb
commit
f5b8aa7c61
4 changed files with 64 additions and 26 deletions
|
|
@ -127,8 +127,8 @@ Wallet.prototype._handleNetworkChange = function(newCopayerId) {
|
||||||
if (newCopayerId) {
|
if (newCopayerId) {
|
||||||
this.log('#### Setting new PEER:', newCopayerId);
|
this.log('#### Setting new PEER:', newCopayerId);
|
||||||
this.sendWalletId(newCopayerId);
|
this.sendWalletId(newCopayerId);
|
||||||
|
this.emit('peer', newCopayerId);
|
||||||
}
|
}
|
||||||
this.emit('peer', newPeerId);
|
|
||||||
this.emit('refresh');
|
this.emit('refresh');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -178,10 +178,11 @@ Wallet.prototype.netStart = function() {
|
||||||
|
|
||||||
net.start(function() {
|
net.start(function() {
|
||||||
self.emit('created', net.getPeer());
|
self.emit('created', net.getPeer());
|
||||||
for (var i=0; i<self.publicKeyRing.registeredCopayers(); i++) {
|
var registered = self.getRegisteredPeerIds();
|
||||||
var otherId = self.getCopayerId(i);
|
for (var i=0; i<registered.length; i++) {
|
||||||
if (otherId !== myId) {
|
var otherPeerId = registered[i];
|
||||||
net.connectTo(otherId);
|
if (otherPeerId !== myPeerId) {
|
||||||
|
net.connectTo(otherPeerId);
|
||||||
}
|
}
|
||||||
if (self.firstCopayerId){
|
if (self.firstCopayerId){
|
||||||
self.sendWalletReady(self.firstCopayerId);
|
self.sendWalletReady(self.firstCopayerId);
|
||||||
|
|
@ -192,6 +193,18 @@ Wallet.prototype.netStart = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.getOnlinePeerIDs = function() {
|
||||||
|
return this.network.getOnlinePeerIDs();
|
||||||
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.getRegisteredPeerIds = function() {
|
||||||
|
var ret = [];
|
||||||
|
for (var i=0; i<this.publicKeyRing.registeredCopayers(); i++) {
|
||||||
|
ret.push(this.getPeerId(i));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
Wallet.prototype.store = function(isSync) {
|
Wallet.prototype.store = function(isSync) {
|
||||||
this.log('[Wallet.js.135:store:]'); //TODO
|
this.log('[Wallet.js.135:store:]'); //TODO
|
||||||
var wallet = this.toObj();
|
var wallet = this.toObj();
|
||||||
|
|
|
||||||
|
|
@ -347,6 +347,13 @@ Network.prototype._sign = function(payload, copayerId) {
|
||||||
).toString('hex');
|
).toString('hex');
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
Network.prototype.getOnlinePeerIDs = function() {
|
||||||
|
return this.connectedPeers;
|
||||||
|
};
|
||||||
|
|
||||||
|
Network.prototype.getPeer = function() {
|
||||||
|
return this.peer;
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype._sendToOne = function(copayerId, payload, cb) {
|
Network.prototype._sendToOne = function(copayerId, payload, cb) {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ angular.module('copay.controllerUtils')
|
||||||
if (err) {
|
if (err) {
|
||||||
root.onErrorDigest(err);
|
root.onErrorDigest(err);
|
||||||
}
|
}
|
||||||
$sce.trustAsResourceUrl(url);
|
alert('add this video url='+url+' for peer '+peerID);
|
||||||
$rootScope.videoSrc[peerID] = encodeURI(url);
|
$rootScope.videoSrc[peerID] = encodeURI(url);
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
};
|
};
|
||||||
|
|
@ -45,9 +45,8 @@ angular.module('copay.controllerUtils')
|
||||||
message: 'Received wrong message from peer id:' + peerId
|
message: 'Received wrong message from peer id:' + peerId
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
w.on('created', function(myPeerID) {
|
||||||
w.on('created', function(selfpeer) {
|
video.setOwnPeer(myPeerID, w, handlePeerVideo);
|
||||||
video.setOwnPeer(selfpeer, handlePeerVideo);
|
|
||||||
$location.path('peer');
|
$location.path('peer');
|
||||||
$rootScope.wallet = w;
|
$rootScope.wallet = w;
|
||||||
root.updateBalance();
|
root.updateBalance();
|
||||||
|
|
@ -58,7 +57,7 @@ angular.module('copay.controllerUtils')
|
||||||
});
|
});
|
||||||
w.on('openError', root.onErrorDigest);
|
w.on('openError', root.onErrorDigest);
|
||||||
w.on('peer', function(peerID) {
|
w.on('peer', function(peerID) {
|
||||||
video.addPeer(peerID, handlePeerVideo);
|
video.callPeer(peerID, handlePeerVideo);
|
||||||
});
|
});
|
||||||
w.on('close', root.onErrorDigest);
|
w.on('close', root.onErrorDigest);
|
||||||
w.netStart();
|
w.netStart();
|
||||||
|
|
|
||||||
|
|
@ -6,46 +6,65 @@ var Video = function() {
|
||||||
navigator.mozGetUserMedia;
|
navigator.mozGetUserMedia;
|
||||||
};
|
};
|
||||||
|
|
||||||
Video.prototype.setOwnPeer = function(peer, cb) {
|
Video.prototype.setOwnPeer = function(peer, wallet, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
navigator.getUserMedia({
|
navigator.getUserMedia({
|
||||||
audio: true,
|
audio: true,
|
||||||
video: true
|
video: true
|
||||||
}, function(stream) {
|
}, function(stream) {
|
||||||
// Set your video displays
|
// This is called when user accepts using webcam
|
||||||
|
self.localStream = stream;
|
||||||
|
var online = wallet.getOnlinePeerIDs();
|
||||||
|
for (var i=0; i<online.length; i++) {
|
||||||
|
var o = online[i];
|
||||||
|
if (o !== peer.id) {
|
||||||
|
self.callPeer(o, cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
cb(null, peer.id, URL.createObjectURL(stream));
|
cb(null, peer.id, URL.createObjectURL(stream));
|
||||||
window.localStream = stream;
|
|
||||||
}, function() {
|
}, function() {
|
||||||
cb(new Error('Failed to access the webcam and microphone.'));
|
cb(new Error('Failed to access the webcam and microphone.'));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Receiving a call
|
// Receiving a call
|
||||||
peer.on('call', function(call) {
|
peer.on('call', function(mediaConnection) {
|
||||||
// Answer the call automatically (instead of prompting user) for demo purposes
|
alert('answering call from ' + mediaConnection.peer);
|
||||||
call.answer(window.localStream);
|
if (self.localStream) {
|
||||||
self.addCall(call, cb);
|
mediaConnection.answer(self.localStream);
|
||||||
|
} else {
|
||||||
|
mediaConnection.answer();
|
||||||
|
}
|
||||||
|
self._addCall(mediaConnection, cb);
|
||||||
});
|
});
|
||||||
peer.on('error', function(err) {
|
peer.on('error', function(err) {
|
||||||
console.log('ERROR on video peer '+err);
|
alert('error on video peer '+err);
|
||||||
});
|
});
|
||||||
this.peer = peer;
|
this.peer = peer;
|
||||||
};
|
};
|
||||||
|
|
||||||
Video.prototype.addPeer = function(peerID, cb) {
|
Video.prototype.callPeer = function(peerID, cb) {
|
||||||
var call = this.peer.call(peerID, window.localStream);
|
if (this.localStream) {
|
||||||
this.addCall(call, cb);
|
var mediaConnection = this.peer.call(peerID, this.localStream);
|
||||||
|
this._addCall(mediaConnection, cb);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Video.prototype.addCall = function(call, cb) {
|
Video.prototype._addCall = function(mediaConnection, cb) {
|
||||||
var peerID = call.id;
|
var peerID = mediaConnection.peer;
|
||||||
|
alert('_addCall ' + peerID);
|
||||||
|
|
||||||
// Wait for stream on the call, then set peer video display
|
// Wait for stream on the call, then set peer video display
|
||||||
call.on('stream', function(stream) {
|
mediaConnection.on('stream', function(stream) {
|
||||||
|
alert('STREAM ON ADD CALL');
|
||||||
cb(null, peerID, URL.createObjectURL(stream));
|
cb(null, peerID, URL.createObjectURL(stream));
|
||||||
});
|
});
|
||||||
|
|
||||||
call.on('close', function() {
|
mediaConnection.on('close', function() {
|
||||||
// TODO: use peerID
|
alert('CLOSEEEEEEEEEEEEEEE ON ADD CALL');
|
||||||
|
});
|
||||||
|
mediaConnection.on('error', function() {
|
||||||
|
alert('ERROR ON ADD CALL');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue