|
@@ -220,34 +220,9 @@ class BankClient {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
subscribePrivate(peerAddr, topic, callback) {
|
|
subscribePrivate(peerAddr, topic, callback) {
|
|
|
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
- const nonce = yield this.getNonce();
|
|
|
|
|
- const retrieveRequest = yield this.makePlaintextPayload(JSON.stringify({
|
|
|
|
|
- _date: new Date().toISOString(),
|
|
|
|
|
- _nonce: nonce,
|
|
|
|
|
- addr: peerAddr,
|
|
|
|
|
- topic: topic
|
|
|
|
|
- }));
|
|
|
|
|
- const ws = new ws_1.default(this.wsUrlBase + '/bank/ws', {
|
|
|
|
|
- headers: {
|
|
|
|
|
- 'x-msg': retrieveRequest.msg,
|
|
|
|
|
- 'x-pub': retrieveRequest.pub,
|
|
|
|
|
- 'x-pubhash': retrieveRequest.pubHash,
|
|
|
|
|
- 'x-sig': retrieveRequest.sig
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- ws.on('open', function open() {
|
|
|
|
|
- console.log('opened ws');
|
|
|
|
|
- resolve();
|
|
|
|
|
- });
|
|
|
|
|
- ws.on('message', data => {
|
|
|
|
|
- // console.log('ws message', data);
|
|
|
|
|
- callback();
|
|
|
|
|
- });
|
|
|
|
|
- ws.on('error', err => {
|
|
|
|
|
- reject(err);
|
|
|
|
|
- });
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
+ yield this.connectWebsocket(peerAddr, topic, callback);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
appendPrivate(peerAddr, topic, hash, replaceHash, deleteHash) {
|
|
appendPrivate(peerAddr, topic, hash, replaceHash, deleteHash) {
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -325,6 +300,56 @@ class BankClient {
|
|
|
return new content_item_1.ContentItem(hash, contentParams);
|
|
return new content_item_1.ContentItem(hash, contentParams);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+ connectWebsocket(peerAddr, topic, callback) {
|
|
|
|
|
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
+ const nonce = yield this.getNonce();
|
|
|
|
|
+ const retrieveRequest = yield this.makePlaintextPayload(JSON.stringify({
|
|
|
|
|
+ _date: new Date().toISOString(),
|
|
|
|
|
+ _nonce: nonce,
|
|
|
|
|
+ addr: peerAddr,
|
|
|
|
|
+ topic: topic
|
|
|
|
|
+ }));
|
|
|
|
|
+ const arg = encodeURIComponent(Buffer.from(JSON.stringify(retrieveRequest)).toString('base64'));
|
|
|
|
|
+ const ws = new ws_1.default(this.wsUrlBase + '/bank/ws?arg=' + arg, {
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'x-msg': retrieveRequest.msg,
|
|
|
|
|
+ 'x-pub': retrieveRequest.pub,
|
|
|
|
|
+ 'x-pubhash': retrieveRequest.pubHash,
|
|
|
|
|
+ 'x-sig': retrieveRequest.sig
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ ws.on('open', (param) => {
|
|
|
|
|
+ console.log('opened ws', param);
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ });
|
|
|
|
|
+ ws.on('message', data => {
|
|
|
|
|
+ // console.log('ws message', data);
|
|
|
|
|
+ callback();
|
|
|
|
|
+ });
|
|
|
|
|
+ ws.on('error', err => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ ws.terminate();
|
|
|
|
|
+ }
|
|
|
|
|
+ finally {
|
|
|
|
|
+ console.log('reconnecting in 5s');
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ this.connectWebsocket(peerAddr, topic, callback);
|
|
|
|
|
+ }, 5000);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ ws.on('close', err => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ ws.terminate();
|
|
|
|
|
+ }
|
|
|
|
|
+ finally {
|
|
|
|
|
+ console.log('reconnecting in 5s');
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ this.connectWebsocket(peerAddr, topic, callback);
|
|
|
|
|
+ }, 5000);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
getItemsForCommaList(commaList) {
|
|
getItemsForCommaList(commaList) {
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
const itemHashes = commaList.split(',').filter(x => x.trim() !== '');
|
|
const itemHashes = commaList.split(',').filter(x => x.trim() !== '');
|