mirror of https://github.com/BTCPrivate/copay.git
self video working
This commit is contained in:
parent
db1cba99fb
commit
f5b8aa7c61
|
@ -127,8 +127,8 @@ Wallet.prototype._handleNetworkChange = function(newCopayerId) {
|
|||
if (newCopayerId) {
|
||||
this.log('#### Setting new PEER:', newCopayerId);
|
||||
this.sendWalletId(newCopayerId);
|
||||
this.emit('peer', newCopayerId);
|
||||
}
|
||||
this.emit('peer', newPeerId);
|
||||
this.emit('refresh');
|
||||
};
|
||||
|
||||
|
@ -178,10 +178,11 @@ Wallet.prototype.netStart = function() {
|
|||
|
||||
net.start(function() {
|
||||
self.emit('created', net.getPeer());
|
||||
for (var i=0; i<self.publicKeyRing.registeredCopayers(); i++) {
|
||||
var otherId = self.getCopayerId(i);
|
||||
if (otherId !== myId) {
|
||||
net.connectTo(otherId);
|
||||
var registered = self.getRegisteredPeerIds();
|
||||
for (var i=0; i<registered.length; i++) {
|
||||
var otherPeerId = registered[i];
|
||||
if (otherPeerId !== myPeerId) {
|
||||
net.connectTo(otherPeerId);
|
||||
}
|
||||
if (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) {
|
||||
this.log('[Wallet.js.135:store:]'); //TODO
|
||||
var wallet = this.toObj();
|
||||
|
|
|
@ -347,6 +347,13 @@ Network.prototype._sign = function(payload, copayerId) {
|
|||
).toString('hex');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Network.prototype.getOnlinePeerIDs = function() {
|
||||
return this.connectedPeers;
|
||||
};
|
||||
|
||||
Network.prototype.getPeer = function() {
|
||||
return this.peer;
|
||||
};
|
||||
|
||||
Network.prototype._sendToOne = function(copayerId, payload, cb) {
|
||||
|
|
|
@ -35,7 +35,7 @@ angular.module('copay.controllerUtils')
|
|||
if (err) {
|
||||
root.onErrorDigest(err);
|
||||
}
|
||||
$sce.trustAsResourceUrl(url);
|
||||
alert('add this video url='+url+' for peer '+peerID);
|
||||
$rootScope.videoSrc[peerID] = encodeURI(url);
|
||||
$rootScope.$apply();
|
||||
};
|
||||
|
@ -45,9 +45,8 @@ angular.module('copay.controllerUtils')
|
|||
message: 'Received wrong message from peer id:' + peerId
|
||||
};
|
||||
});
|
||||
|
||||
w.on('created', function(selfpeer) {
|
||||
video.setOwnPeer(selfpeer, handlePeerVideo);
|
||||
w.on('created', function(myPeerID) {
|
||||
video.setOwnPeer(myPeerID, w, handlePeerVideo);
|
||||
$location.path('peer');
|
||||
$rootScope.wallet = w;
|
||||
root.updateBalance();
|
||||
|
@ -58,7 +57,7 @@ angular.module('copay.controllerUtils')
|
|||
});
|
||||
w.on('openError', root.onErrorDigest);
|
||||
w.on('peer', function(peerID) {
|
||||
video.addPeer(peerID, handlePeerVideo);
|
||||
video.callPeer(peerID, handlePeerVideo);
|
||||
});
|
||||
w.on('close', root.onErrorDigest);
|
||||
w.netStart();
|
||||
|
|
|
@ -6,46 +6,65 @@ var Video = function() {
|
|||
navigator.mozGetUserMedia;
|
||||
};
|
||||
|
||||
Video.prototype.setOwnPeer = function(peer, cb) {
|
||||
Video.prototype.setOwnPeer = function(peer, wallet, cb) {
|
||||
var self = this;
|
||||
|
||||
navigator.getUserMedia({
|
||||
audio: true,
|
||||
video: true
|
||||
}, 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));
|
||||
window.localStream = stream;
|
||||
}, function() {
|
||||
cb(new Error('Failed to access the webcam and microphone.'));
|
||||
});
|
||||
|
||||
// Receiving a call
|
||||
peer.on('call', function(call) {
|
||||
// Answer the call automatically (instead of prompting user) for demo purposes
|
||||
call.answer(window.localStream);
|
||||
self.addCall(call, cb);
|
||||
peer.on('call', function(mediaConnection) {
|
||||
alert('answering call from ' + mediaConnection.peer);
|
||||
if (self.localStream) {
|
||||
mediaConnection.answer(self.localStream);
|
||||
} else {
|
||||
mediaConnection.answer();
|
||||
}
|
||||
self._addCall(mediaConnection, cb);
|
||||
});
|
||||
peer.on('error', function(err) {
|
||||
console.log('ERROR on video peer '+err);
|
||||
alert('error on video peer '+err);
|
||||
});
|
||||
this.peer = peer;
|
||||
};
|
||||
|
||||
Video.prototype.addPeer = function(peerID, cb) {
|
||||
var call = this.peer.call(peerID, window.localStream);
|
||||
this.addCall(call, cb);
|
||||
Video.prototype.callPeer = function(peerID, cb) {
|
||||
if (this.localStream) {
|
||||
var mediaConnection = this.peer.call(peerID, this.localStream);
|
||||
this._addCall(mediaConnection, cb);
|
||||
}
|
||||
};
|
||||
|
||||
Video.prototype.addCall = function(call, cb) {
|
||||
var peerID = call.id;
|
||||
Video.prototype._addCall = function(mediaConnection, cb) {
|
||||
var peerID = mediaConnection.peer;
|
||||
alert('_addCall ' + peerID);
|
||||
|
||||
// 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));
|
||||
});
|
||||
|
||||
call.on('close', function() {
|
||||
// TODO: use peerID
|
||||
mediaConnection.on('close', function() {
|
||||
alert('CLOSEEEEEEEEEEEEEEE ON ADD CALL');
|
||||
});
|
||||
mediaConnection.on('error', function() {
|
||||
alert('ERROR ON ADD CALL');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue