mirror of https://github.com/BTCPrivate/copay.git
Support reconnection to old peerjs session
This commit is contained in:
parent
41dadab915
commit
406db01dd2
|
@ -722,7 +722,7 @@ on supported browsers please check <a href="http://www.webrtc.org/">http://www.w
|
|||
<script src="lib/angular-route/angular-route.min.js"></script>
|
||||
<script src="lib/angular-foundation/mm-foundation.min.js"></script>
|
||||
<script src="lib/angular-foundation/mm-foundation-tpls.min.js"></script>
|
||||
<script src="lib/peerjs/peer.js"></script>
|
||||
<script src="lib/peer.js"></script> <!-- TODO Change this on new PeerJS version -->
|
||||
<script src="lib/bitcore/browser/bundle.js"></script>
|
||||
<script src="lib/crypto-js/rollups/sha256.js"></script>
|
||||
<script src="lib/crypto-js/rollups/pbkdf2.js"></script>
|
||||
|
|
|
@ -32,6 +32,12 @@ function Wallet(opts) {
|
|||
this.name = opts.name;
|
||||
this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64');
|
||||
|
||||
// Renew token every 24hs
|
||||
if (opts.tokenTime && new Date().getTime() - opts.tokenTime < 86400000) {
|
||||
this.token = opts.token;
|
||||
this.tokenTime = opts.tokenTime;
|
||||
}
|
||||
|
||||
this.verbose = opts.verbose;
|
||||
this.publicKeyRing.walletId = this.id;
|
||||
this.txProposals.walletId = this.id;
|
||||
|
@ -162,6 +168,8 @@ Wallet.prototype._optsToObj = function() {
|
|||
requiredCopayers: this.requiredCopayers,
|
||||
totalCopayers: this.totalCopayers,
|
||||
name: this.name,
|
||||
token: this.token,
|
||||
tokenTime: new Date().getTime(),
|
||||
netKey: this.netKey,
|
||||
version: this.version,
|
||||
};
|
||||
|
@ -221,6 +229,7 @@ Wallet.prototype.netStart = function() {
|
|||
var myId = self.getMyCopayerId();
|
||||
var startOpts = {
|
||||
copayerId: myId,
|
||||
token: self.token,
|
||||
maxPeers: self.totalCopayers,
|
||||
netKey: this.netKey,
|
||||
};
|
||||
|
@ -230,6 +239,7 @@ Wallet.prototype.netStart = function() {
|
|||
}
|
||||
net.start(startOpts, function() {
|
||||
self.emit('ready', net.getPeer());
|
||||
self.token = net.peer.options.token;
|
||||
setTimeout(function(){
|
||||
console.log('[EMIT publicKeyRingUpdated:]'); //TODO
|
||||
self.emit('publicKeyRingUpdated', true);
|
||||
|
@ -237,6 +247,7 @@ Wallet.prototype.netStart = function() {
|
|||
self.connectToAll();
|
||||
console.log('[EMIT TxProposal]'); //TODO
|
||||
self.emit('txProposalsUpdated');
|
||||
self.store();
|
||||
},10);
|
||||
});
|
||||
};
|
||||
|
@ -305,6 +316,8 @@ Wallet.fromObj = function(o, storage, network, blockchain) {
|
|||
|
||||
Wallet.prototype.toEncryptedObj = function() {
|
||||
var walletObj = this.toObj();
|
||||
delete walletObj.opts.token;
|
||||
delete walletObj.opts.tokenTime;
|
||||
return this.storage.export(walletObj);
|
||||
};
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ var imports = require('soop').imports();
|
|||
var EventEmitter= imports.EventEmitter || require('events').EventEmitter;
|
||||
var bitcore = require('bitcore');
|
||||
var util = bitcore.util;
|
||||
var extend = require('util')._extend;
|
||||
/*
|
||||
* Emits
|
||||
* 'connect'
|
||||
|
@ -327,6 +328,9 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
this.netKey = opts.netKey;
|
||||
this.maxPeers = opts.maxPeers || this.maxPeers;
|
||||
|
||||
if (opts.token)
|
||||
this.opts.token = opts.token;
|
||||
|
||||
if (!this.copayerId)
|
||||
this.setCopayerId(opts.copayerId);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue