Merge branch 'master' into feature/05-new-design
Conflicts: js/services/video.js
This commit is contained in:
commit
e24a88dca1
15 changed files with 217 additions and 55 deletions
|
|
@ -19,24 +19,26 @@ angular.module('copay.signin').controller('SigninController',
|
|||
};
|
||||
|
||||
$scope.join = function(secret) {
|
||||
if (!secret || secret.length !==66 || !secret.match(/^[0-9a-f]*$/) ) {
|
||||
$rootScope.flashMessage = { message: 'Bad secret secret string', type: 'error'};
|
||||
return;
|
||||
}
|
||||
$scope.loading = true;
|
||||
|
||||
walletFactory.network.on('joinError', function() {
|
||||
controllerUtils.onErrorDigest($scope);
|
||||
walletFactory.network.on('badSecret', function() {
|
||||
});
|
||||
|
||||
walletFactory.joinCreateSession(secret, function(w) {
|
||||
if (w) {
|
||||
controllerUtils.startNetwork(w);
|
||||
}
|
||||
else {
|
||||
$scope.loading = false;
|
||||
controllerUtils.onErrorDigest();
|
||||
walletFactory.joinCreateSession(secret, function(err,w) {
|
||||
$scope.loading = false;
|
||||
console.log('[signin.js.27:err:]',err,w); //TODO
|
||||
|
||||
if (err || !w) {
|
||||
if (err === 'joinError')
|
||||
$rootScope.flashMessage = { message: 'Can not find peer'};
|
||||
else if (err === 'badSecret')
|
||||
$rootScope.flashMessage = { message: 'Bad secret secret string', type: 'error'};
|
||||
else
|
||||
$rootScope.flashMessage = { message: 'Unknown error', type: 'error'};
|
||||
controllerUtils.onErrorDigest();
|
||||
}
|
||||
else
|
||||
controllerUtils.startNetwork(w);
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ var Builder = bitcore.TransactionBuilder;
|
|||
var http = require('http');
|
||||
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
|
||||
var copay = copay || require('../../../copay');
|
||||
var SecureRandom = bitcore.SecureRandom;
|
||||
var Base58Check = bitcore.Base58.base58Check;
|
||||
|
||||
function Wallet(opts) {
|
||||
var self = this;
|
||||
|
|
@ -26,6 +28,8 @@ function Wallet(opts) {
|
|||
|
||||
this.id = opts.id || Wallet.getRandomId();
|
||||
this.name = opts.name;
|
||||
this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64');
|
||||
|
||||
this.verbose = opts.verbose;
|
||||
this.publicKeyRing.walletId = this.id;
|
||||
this.txProposals.walletId = this.id;
|
||||
|
|
@ -124,6 +128,7 @@ Wallet.prototype._optsToObj = function() {
|
|||
requiredCopayers: this.requiredCopayers,
|
||||
totalCopayers: this.totalCopayers,
|
||||
name: this.name,
|
||||
netKey: this.netKey,
|
||||
};
|
||||
|
||||
return obj;
|
||||
|
|
@ -139,6 +144,26 @@ Wallet.prototype.getMyCopayerId = function() {
|
|||
return this.getCopayerId(0);
|
||||
};
|
||||
|
||||
|
||||
Wallet.prototype.getSecret = function() {
|
||||
var i = new Buffer(this.getMyCopayerId(),'hex');
|
||||
var k = new Buffer(this.netKey,'base64');
|
||||
var b = Buffer.concat([i,k]);
|
||||
var str = Base58Check.encode(b);
|
||||
return str;
|
||||
};
|
||||
|
||||
|
||||
Wallet.decodeSecret = function(secretB) {
|
||||
var secret = Base58Check.decode(secretB);
|
||||
var netKeyBuf = secret.slice(-8);
|
||||
var pubKeyBuf = secret.slice(0,33);
|
||||
return {
|
||||
pubKey: pubKeyBuf.toString('hex'),
|
||||
netKey: netKeyBuf.toString('base64'),
|
||||
}
|
||||
};
|
||||
|
||||
Wallet.prototype._lockIncomming = function() {
|
||||
this.network.lockIncommingConnections(this.publicKeyRing.getAllCopayerIds());
|
||||
};
|
||||
|
|
@ -162,6 +187,7 @@ Wallet.prototype.netStart = function() {
|
|||
var startOpts = {
|
||||
copayerId: myId,
|
||||
maxPeers: self.totalCopayers,
|
||||
netKey: this.netKey,
|
||||
};
|
||||
|
||||
if (this.publicKeyRing.isComplete()) {
|
||||
|
|
|
|||
|
|
@ -149,27 +149,35 @@ WalletFactory.prototype.remove = function(walletId) {
|
|||
};
|
||||
|
||||
|
||||
WalletFactory.prototype.joinCreateSession = function(copayerId, cb) {
|
||||
WalletFactory.prototype.joinCreateSession = function(secret, cb) {
|
||||
var self = this;
|
||||
|
||||
var s;
|
||||
try {
|
||||
s=Wallet.decodeSecret(secret);
|
||||
} catch (e) {
|
||||
return cb('badSecret');
|
||||
}
|
||||
|
||||
//Create our PrivateK
|
||||
var privateKey = new PrivateKey({ networkName: this.networkName });
|
||||
this.log('\t### PrivateKey Initialized');
|
||||
var opts = {
|
||||
copayerId: privateKey.getId(),
|
||||
netKey: s.netKey,
|
||||
};
|
||||
self.network.cleanUp();
|
||||
self.network.start(opts, function() {
|
||||
self.network.connectTo(copayerId);
|
||||
self.network.connectTo(s.pubKey);
|
||||
self.network.on('onlyYou', function(sender, data) {
|
||||
return cb();
|
||||
return cb('joinError');
|
||||
});
|
||||
self.network.on('data', function(sender, data) {
|
||||
if (data.type ==='walletId') {
|
||||
data.opts.privateKey = privateKey;
|
||||
var w = self.open(data.walletId, data.opts);
|
||||
w.firstCopayerId = copayerId;
|
||||
return cb(w);
|
||||
w.firstCopayerId = s.pubKey;
|
||||
return cb(null, w);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ var imports = require('soop').imports();
|
|||
var EventEmitter= imports.EventEmitter || require('events').EventEmitter;
|
||||
var bitcore = require('bitcore');
|
||||
var util = bitcore.util;
|
||||
var Key = bitcore.Key;
|
||||
/*
|
||||
* Emits
|
||||
* 'networkChange'
|
||||
|
|
@ -18,15 +17,22 @@ var Key = bitcore.Key;
|
|||
*/
|
||||
|
||||
function Network(opts) {
|
||||
var self = this;
|
||||
var self = this;
|
||||
opts = opts || {};
|
||||
this.apiKey = opts.apiKey || 'lwjd5qra8257b9';
|
||||
this.debug = opts.debug || 3;
|
||||
this.maxPeers = opts.maxPeers || 10;
|
||||
this.opts = { key: opts.key };
|
||||
this.sjclParams = opts.sjclParams || {
|
||||
salt: 'f28bfb49ef70573c',
|
||||
iter:500,
|
||||
mode:'ccm',
|
||||
ts:parseInt(64),
|
||||
};
|
||||
|
||||
|
||||
// For using your own peerJs server
|
||||
['port', 'host', 'path', 'debug'].forEach(function(k) {
|
||||
self.opts = {};
|
||||
['port', 'host', 'path', 'debug', 'key'].forEach(function(k) {
|
||||
if (opts[k]) self.opts[k] = opts[k];
|
||||
});
|
||||
this.cleanUp();
|
||||
|
|
@ -38,6 +44,7 @@ Network.prototype.cleanUp = function() {
|
|||
this.started = false;
|
||||
this.connectedPeers = [];
|
||||
this.peerId = null;
|
||||
this.netKey = null;
|
||||
this.copayerId = null;
|
||||
this.signingKey = null;
|
||||
this.allowedCopayerIds=null;
|
||||
|
|
@ -152,10 +159,11 @@ Network.prototype._addCopayer = function(copayerId, isInbound) {
|
|||
|
||||
|
||||
|
||||
Network.prototype._onData = function(data, isInbound, peerId) {
|
||||
Network.prototype._onData = function(encStr, isInbound, peerId) {
|
||||
var sig, payload;
|
||||
|
||||
try {
|
||||
var data = this._decrypt(encStr);
|
||||
payload= JSON.parse(data);
|
||||
} catch (e) {
|
||||
console.log('### ERROR IN DATA: "%s" ', data, isInbound, e);
|
||||
|
|
@ -166,13 +174,15 @@ Network.prototype._onData = function(data, isInbound, peerId) {
|
|||
console.log('### RECEIVED INBOUND?:%s TYPE: %s FROM %s',
|
||||
isInbound, payload.type, peerId, payload);
|
||||
|
||||
if(payload.type === 'hello' && !this.authenticatedPeers[peerId]) {
|
||||
var payloadStr = JSON.stringify(payload);
|
||||
if (this.allowedCopayerIds && !this.allowedCopayerIds[payload.copayerId]) {
|
||||
console.log('#### Peer is not on the allowedCopayerIds. Closing connection',
|
||||
this.allowedCopayerIds, payload.copayerId);
|
||||
this._deletePeer(peerId);
|
||||
return;
|
||||
if(payload.type === 'hello' ) {
|
||||
if (!this.authenticatedPeers[peerId]) {
|
||||
var payloadStr = JSON.stringify(payload);
|
||||
if (this.allowedCopayerIds && !this.allowedCopayerIds[payload.copayerId]) {
|
||||
console.log('#### Peer is not on the allowedCopayerIds. Closing connection',
|
||||
this.allowedCopayerIds, payload.copayerId);
|
||||
this._deletePeer(peerId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
console.log('#### Peer sent hello. Setting it up.'); //TODO
|
||||
this._setPeerAuthenticated(peerId);
|
||||
|
|
@ -330,6 +340,7 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
|
||||
if (this.started) return openCallback();
|
||||
|
||||
this.netKey = opts.netKey;
|
||||
this.maxPeers = opts.maxPeers || this.maxPeers;
|
||||
|
||||
if (!this.copayerId)
|
||||
|
|
@ -355,13 +366,35 @@ Network.prototype.getPeer = function() {
|
|||
return this.peer;
|
||||
};
|
||||
|
||||
Network.prototype._encrypt = function(payloadStr) {
|
||||
var plainText = sjcl.codec.utf8String.toBits(payloadStr);
|
||||
var p = this.sjclParams;
|
||||
ct = sjcl.encrypt(this.netKey, plainText, p);//,p, rp);
|
||||
var c = JSON.parse(ct);
|
||||
var toSend = {
|
||||
iv: c.iv,
|
||||
ct: c.ct,
|
||||
};
|
||||
return JSON.stringify(toSend);
|
||||
};
|
||||
|
||||
Network.prototype._sendToOne = function(copayerId, payloadStr, sig, cb) {
|
||||
|
||||
Network.prototype._decrypt = function(encStr) {
|
||||
var i = JSON.parse(encStr);
|
||||
for (var k in this.sjclParams) {
|
||||
i[k] = this.sjclParams[k];
|
||||
}
|
||||
var str= JSON.stringify(i);
|
||||
var pt = sjcl.decrypt(this.netKey, str);
|
||||
return pt;
|
||||
};
|
||||
|
||||
Network.prototype._sendToOne = function(copayerId, payload, sig, cb) {
|
||||
var peerId = this.peerFromCopayer(copayerId);
|
||||
if (peerId !== this.peerId) {
|
||||
var dataConn = this.connections[peerId];
|
||||
if (dataConn) {
|
||||
dataConn.send(payloadStr);
|
||||
dataConn.send(payload);
|
||||
}
|
||||
else {
|
||||
console.log('[WebRTC.js.255] WARN: NO CONNECTION TO:', peerId); //TODO
|
||||
|
|
@ -379,17 +412,18 @@ Network.prototype.send = function(copayerIds, payload, cb) {
|
|||
|
||||
var sig;
|
||||
var payloadStr = JSON.stringify(payload);
|
||||
var encPayload = this._encrypt(payloadStr);
|
||||
if (Array.isArray(copayerIds)) {
|
||||
var l = copayerIds.length;
|
||||
var i = 0;
|
||||
copayerIds.forEach(function(copayerId) {
|
||||
self._sendToOne(copayerId, payloadStr, sig, function () {
|
||||
self._sendToOne(copayerId, encPayload, sig, function () {
|
||||
if (++i === l && typeof cb === 'function') cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
else if (typeof copayerIds === 'string')
|
||||
self._sendToOne(copayerIds, payloadStr, sig, cb);
|
||||
self._sendToOne(copayerIds, encPayload, sig, cb);
|
||||
};
|
||||
|
||||
Network.prototype.connectTo = function(copayerId) {
|
||||
|
|
|
|||
|
|
@ -29,11 +29,6 @@ angular.module('copay.controllerUtils')
|
|||
|
||||
root.onError = function(scope) {
|
||||
if (scope) scope.loading = false;
|
||||
$rootScope.flashMessage = {
|
||||
type: 'error',
|
||||
message: 'Could not connect to peer: ' +
|
||||
scope
|
||||
};
|
||||
root.logout();
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +88,7 @@ angular.module('copay.controllerUtils')
|
|||
|
||||
root.setSocketHandlers = function() {
|
||||
Socket.removeAllListeners();
|
||||
if (!$rootScope.wallet) return;
|
||||
|
||||
var addrs = $rootScope.wallet.getAddressesStr();
|
||||
for (var i = 0; i < addrs.length; i++) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ var Video = function() {
|
|||
|
||||
this.mediaConnections = {};
|
||||
this.localStream = null;
|
||||
this.onlineSound = new Audio('./sound/online.wav');
|
||||
this.onlineSound = new Audio('sound/online.wav');
|
||||
};
|
||||
|
||||
Video.prototype.setOwnPeer = function(peer, wallet, cb) {
|
||||
|
|
@ -72,11 +72,13 @@ Video.prototype._addCall = function(mediaConnection, cb) {
|
|||
}
|
||||
|
||||
Video.prototype.close = function() {
|
||||
this.localStream.stop();
|
||||
this.localStream.mozSrcObject = null;
|
||||
this.localStream.src = "";
|
||||
this.localStream.src = null;
|
||||
this.localStream = null;
|
||||
if (this.localStream){
|
||||
this.localStream.stop();
|
||||
this.localStream.mozSrcObject = null;
|
||||
this.localStream.src = "";
|
||||
this.localStream.src = null;
|
||||
this.localStream = null;
|
||||
}
|
||||
for (var i = 0; this.mediaConnections.length; i++) {
|
||||
this.mediaConnections[i].close();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue