/** * @returns Promise */ isAlive() { return new Promise((resolve) => { post(this.jsonrpc_url, { json: { jsonrpc: '2.0', method: 'ping', params: [], id: '1', }, }, (err, res, body) => resolve(!err && body && body.result === 'pong')); }); }
/** * @returns Promise */ send(method, extraParams) { this._counter = this._counter + 1; const params = { jsonrpc: '2.0', method, params: extraParams, id: this._counter, }; const self = this; return new Promise((resolve, reject) => { setTimeout(() => { post( this.jsonrpc_url, { json: params }, (err, res, body) => { if (err) return reject(err); if (body.error) return reject(body.error); return resolve(body.result); }, ); }, self.options.delay); }); }