From a6b525b09edb83fca27ad59ac38af40fa06a286c Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Tue, 16 Jan 2018 16:32:30 -0200 Subject: [PATCH] fix subscriptions (#196) --- app/lib/ddp.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/lib/ddp.js b/app/lib/ddp.js index 5a88923aa..5d6ef612c 100644 --- a/app/lib/ddp.js +++ b/app/lib/ddp.js @@ -46,7 +46,7 @@ export default class Socket extends EventEmitter { this._connect(); this.ddp = new EventEmitter(); this.on('ping', () => this.send({ msg: 'pong' })); - this.on('result', data => this.ddp.emit(data.id, { result: data.result, error: data.error })); + this.on('result', data => this.ddp.emit(data.id, { id: data.id, result: data.result, error: data.error })); this.on('ready', data => this.ddp.emit(data.subs[0], data)); } send(obj) { @@ -54,7 +54,7 @@ export default class Socket extends EventEmitter { this.id += 1; const id = obj.id || `${ this.id }`; this.connection.send(EJSON.stringify({ ...obj, id })); - this.ddp.once(id, data => (data.error ? reject(data.error) : resolve(data.result || data.subs))); + this.ddp.once(id, data => (data.error ? reject(data.error) : resolve({ id, ...data }))); }); } _connect() { @@ -99,22 +99,22 @@ export default class Socket extends EventEmitter { call(method, ...params) { return this.send({ msg: 'method', method, params - }); + }).then(data => data.result || data.subs); } unsubscribe(id) { if (!this.subscriptions[id]) { - return Promise.reject(); + return Promise.reject(id); } delete this.subscriptions[id]; return this.send({ msg: 'unsub', id - }); + }).then(data => data.result || data.subs); } subscribe(name, ...params) { return this.send({ msg: 'sub', name, params - }).then((id) => { + }).then(({ id }) => { const args = { name, params,