Send encoded JSON over Ws (#33)

* Send encoded JSON over Ws

* Remove unused type import
This commit is contained in:
Jaco Greeff
2017-12-03 17:34:15 +01:00
committed by GitHub
parent 1125312427
commit 88a2c0f007
7 changed files with 17 additions and 20 deletions
+1 -1
View File
@@ -10,5 +10,5 @@
"packages": [ "packages": [
"packages/*" "packages/*"
], ],
"version": "0.5.13" "version": "0.6.0"
} }
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@polkadot/api-format", "name": "@polkadot/api-format",
"version": "0.5.13", "version": "0.6.0",
"description": "Input/Output formatters for JsonRPC exchange", "description": "Input/Output formatters for JsonRPC exchange",
"main": "index.js", "main": "index.js",
"keywords": [ "keywords": [
@@ -30,7 +30,7 @@
"test": "echo \"Tests only available from root wrapper\"" "test": "echo \"Tests only available from root wrapper\""
}, },
"devDependencies": { "devDependencies": {
"@polkadot/api-jsonrpc": "^0.5.13" "@polkadot/api-jsonrpc": "^0.6.0"
}, },
"dependencies": { "dependencies": {
"@polkadot/util": "^0.6.7", "@polkadot/util": "^0.6.7",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@polkadot/api-jsonrpc", "name": "@polkadot/api-jsonrpc",
"version": "0.5.13", "version": "0.6.0",
"description": "Method definitions for the Polkadot RPC layer", "description": "Method definitions for the Polkadot RPC layer",
"main": "index.js", "main": "index.js",
"engines": { "engines": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@polkadot/api-provider", "name": "@polkadot/api-provider",
"version": "0.5.13", "version": "0.6.0",
"description": "Transport providers for the API", "description": "Transport providers for the API",
"main": "index.js", "main": "index.js",
"keywords": [ "keywords": [
+5 -5
View File
@@ -1,7 +1,7 @@
// ISC, Copyright 2017 Jaco Greeff // ISC, Copyright 2017 Jaco Greeff
// @flow // @flow
import type { JsonRpcRequest, JsonRpcResponse, ProviderInterface } from '../types'; import type { JsonRpcResponse, ProviderInterface } from '../types';
type AwaitingType = { type AwaitingType = {
callback: (error: ?Error, result: any) => void callback: (error: ?Error, result: any) => void
@@ -21,7 +21,7 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf
_endpoint: string; _endpoint: string;
_handlers: { [number]: AwaitingType } = {}; _handlers: { [number]: AwaitingType } = {};
_isConnected: boolean = false; _isConnected: boolean = false;
_queued: { [number]: JsonRpcRequest } = {}; _queued: { [number]: string } = {};
_websocket: WebSocket; _websocket: WebSocket;
constructor (endpoint: string, autoConnect: boolean = true) { constructor (endpoint: string, autoConnect: boolean = true) {
@@ -101,7 +101,7 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf
send (method: string, params: Array<any>): Promise<any> { send (method: string, params: Array<any>): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
const encoded = this.encodeObject(method, params); const json = this.encodeJson(method, params);
this._handlers[this.id] = { this._handlers[this.id] = {
callback: (error: ?Error, result: any) => { callback: (error: ?Error, result: any) => {
@@ -114,9 +114,9 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf
}; };
if (this._isConnected) { if (this._isConnected) {
this._websocket.send(encoded); this._websocket.send(json);
} else { } else {
this._queued[this.id] = encoded; this._queued[this.id] = json;
} }
} catch (error) { } catch (error) {
reject(error); reject(error);
+3 -6
View File
@@ -189,12 +189,9 @@ describe('Ws', () => {
return ws return ws
.send('test_body', ['param']) .send('test_body', ['param'])
.then((result) => { .then((result) => {
expect(mock.body['test_body']).toEqual({ expect(
id: 1, mock.body['test_body']
jsonrpc: '2.0', ).toEqual('{"id":1,"jsonrpc":"2.0","method":"test_body","params":["param"]}');
method: 'test_body',
params: ['param']
});
}); });
}); });
+4 -4
View File
@@ -1,6 +1,6 @@
{ {
"name": "@polkadot/api", "name": "@polkadot/api",
"version": "0.5.13", "version": "0.6.0",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface", "description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js", "main": "index.js",
"keywords": [ "keywords": [
@@ -30,9 +30,9 @@
"test": "echo \"Tests only available from root wrapper\"" "test": "echo \"Tests only available from root wrapper\""
}, },
"dependencies": { "dependencies": {
"@polkadot/api-format": "^0.5.13", "@polkadot/api-format": "^0.6.0",
"@polkadot/api-jsonrpc": "^0.5.13", "@polkadot/api-jsonrpc": "^0.6.0",
"@polkadot/api-provider": "^0.5.13", "@polkadot/api-provider": "^0.6.0",
"@polkadot/util": "^0.6.7", "@polkadot/util": "^0.6.7",
"babel-runtime": "^6.26.0" "babel-runtime": "^6.26.0"
} }