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
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-format",
"version": "0.5.13",
"version": "0.6.0",
"description": "Input/Output formatters for JsonRPC exchange",
"main": "index.js",
"keywords": [
@@ -30,7 +30,7 @@
"test": "echo \"Tests only available from root wrapper\""
},
"devDependencies": {
"@polkadot/api-jsonrpc": "^0.5.13"
"@polkadot/api-jsonrpc": "^0.6.0"
},
"dependencies": {
"@polkadot/util": "^0.6.7",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-jsonrpc",
"version": "0.5.13",
"version": "0.6.0",
"description": "Method definitions for the Polkadot RPC layer",
"main": "index.js",
"engines": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-provider",
"version": "0.5.13",
"version": "0.6.0",
"description": "Transport providers for the API",
"main": "index.js",
"keywords": [
+5 -5
View File
@@ -1,7 +1,7 @@
// ISC, Copyright 2017 Jaco Greeff
// @flow
import type { JsonRpcRequest, JsonRpcResponse, ProviderInterface } from '../types';
import type { JsonRpcResponse, ProviderInterface } from '../types';
type AwaitingType = {
callback: (error: ?Error, result: any) => void
@@ -21,7 +21,7 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf
_endpoint: string;
_handlers: { [number]: AwaitingType } = {};
_isConnected: boolean = false;
_queued: { [number]: JsonRpcRequest } = {};
_queued: { [number]: string } = {};
_websocket: WebSocket;
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> {
return new Promise((resolve, reject) => {
try {
const encoded = this.encodeObject(method, params);
const json = this.encodeJson(method, params);
this._handlers[this.id] = {
callback: (error: ?Error, result: any) => {
@@ -114,9 +114,9 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf
};
if (this._isConnected) {
this._websocket.send(encoded);
this._websocket.send(json);
} else {
this._queued[this.id] = encoded;
this._queued[this.id] = json;
}
} catch (error) {
reject(error);
+3 -6
View File
@@ -189,12 +189,9 @@ describe('Ws', () => {
return ws
.send('test_body', ['param'])
.then((result) => {
expect(mock.body['test_body']).toEqual({
id: 1,
jsonrpc: '2.0',
method: 'test_body',
params: ['param']
});
expect(
mock.body['test_body']
).toEqual('{"id":1,"jsonrpc":"2.0","method":"test_body","params":["param"]}');
});
});
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api",
"version": "0.5.13",
"version": "0.6.0",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
"keywords": [
@@ -30,9 +30,9 @@
"test": "echo \"Tests only available from root wrapper\""
},
"dependencies": {
"@polkadot/api-format": "^0.5.13",
"@polkadot/api-jsonrpc": "^0.5.13",
"@polkadot/api-provider": "^0.5.13",
"@polkadot/api-format": "^0.6.0",
"@polkadot/api-jsonrpc": "^0.6.0",
"@polkadot/api-provider": "^0.6.0",
"@polkadot/util": "^0.6.7",
"babel-runtime": "^6.26.0"
}