Add polyfill for WebSocket (node) (#31)

This commit is contained in:
Jaco Greeff
2017-12-03 15:37:56 +01:00
committed by GitHub
parent aa0a231224
commit 53e7f06b03
8 changed files with 57 additions and 8 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
[![coverage](https://img.shields.io/coveralls/polkadot-js/api.svg?style=flat-square)](https://coveralls.io/github/polkadot-js/api?branch=master)
[![greenkeeper](https://img.shields.io/badge/greenkeeper-enabled-brightgreen.svg?style=flat-square)](https://greenkeeper.io/)
# @polkadot/client
# @polkadot/api
This library provides a clean wrapper around all the methods exposed by a Polkadot network client. As part of the JsonRpc defintions, the [exposed methods are documented](packages/api-jsonrpc/docs/).
+1 -1
View File
@@ -33,7 +33,7 @@
"@polkadot/api-jsonrpc": "^0.5.11"
},
"dependencies": {
"@polkadot/util": "^0.6.6",
"@polkadot/util": "^0.6.7",
"babel-runtime": "^6.26.0"
}
}
+3 -2
View File
@@ -34,8 +34,9 @@
"nock": "^9.1.0"
},
"dependencies": {
"@polkadot/util": "^0.6.6",
"@polkadot/util": "^0.6.7",
"babel-runtime": "^6.26.0",
"isomorphic-fetch": "^2.2.1"
"isomorphic-fetch": "^2.2.1",
"ws": "^3.3.2"
}
}
+2
View File
@@ -11,6 +11,8 @@ type WsMessageType = {
data: any
};
require('./polyfill');
const JsonRpcCoder = require('../jsonRpcCoder');
module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterface {
+6
View File
@@ -0,0 +1,6 @@
// ISC, Copyright 2017 Jaco Greeff
// @flow
if (typeof WebSocket === 'undefined') {
global.WebSocket = require('ws');
}
@@ -0,0 +1,24 @@
// ISC, Copyright 2017 Jaco Greeff
describe('ws/polyfill', () => {
let origWs;
beforeEach(() => {
origWs = global.WebSocket;
global.fetch = null;
});
afterEach(() => {
global.WebSocket = origWs;
});
it('polyfills with no exceptions (without WebSocket)', () => {
expect(require('./polyfill')).toBeDefined();
});
it('polyfills with no exceptions (with WebSocket)', () => {
global.WebSocket = () => true;
expect(require('./polyfill')).toBeDefined();
});
});
+1 -1
View File
@@ -33,7 +33,7 @@
"@polkadot/api-format": "^0.5.11",
"@polkadot/api-jsonrpc": "^0.5.11",
"@polkadot/api-provider": "^0.5.11",
"@polkadot/util": "^0.6.6",
"@polkadot/util": "^0.6.7",
"babel-runtime": "^6.26.0"
}
}
+19 -3
View File
@@ -91,9 +91,9 @@
stylelint "^8.2.0"
stylelint-config-standard "^18.0.0"
"@polkadot/util@^0.6.6":
version "0.6.6"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.6.6.tgz#75cbbaa4215dcc353b680613237a76515b00833f"
"@polkadot/util@^0.6.7":
version "0.6.7"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.6.7.tgz#eb9a6bd3717b69c962f6fb70830ebc60380c333f"
dependencies:
babel-runtime "^6.26.0"
bn.js "^4.11.8"
@@ -305,6 +305,10 @@ async-each@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d"
async-limiter@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
async@^1.4.0, async@^1.5.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
@@ -5050,6 +5054,10 @@ uid-number@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"
ultron@~1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.1.tgz#9fe1536a10a664a65266a1e3ccf85fd36302bc9c"
unherit@^1.0.4:
version "1.1.0"
resolved "https://registry.yarnpkg.com/unherit/-/unherit-1.1.0.tgz#6b9aaedfbf73df1756ad9e316dd981885840cd7d"
@@ -5309,6 +5317,14 @@ write@^0.2.1:
dependencies:
mkdirp "^0.5.1"
ws@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/ws/-/ws-3.3.2.tgz#96c1d08b3fefda1d5c1e33700d3bfaa9be2d5608"
dependencies:
async-limiter "~1.0.0"
safe-buffer "~5.1.0"
ultron "~1.1.0"
x-is-function@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/x-is-function/-/x-is-function-1.0.4.tgz#5d294dc3d268cbdd062580e0c5df77a391d1fa1e"