Skip to content

Commit daa4259

Browse files
authored
Merge pull request #179 from ainblockchain/release/v1.9.0
Upgrade version to 1.9.0
2 parents 2671a45 + 5823db8 commit daa4259

File tree

4 files changed

+261
-8
lines changed

4 files changed

+261
-8
lines changed

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ainblockchain/ain-js",
3-
"version": "1.8.0",
3+
"version": "1.9.0",
44
"description": "",
55
"main": "lib/ain.js",
66
"scripts": {
@@ -13,7 +13,8 @@
1313
"test_ain_raw": "jest ain_raw.test.ts",
1414
"test_he": "jest he.test.ts",
1515
"test_em": "jest event_manager.test.ts",
16-
"docs": "yarn build && typedoc --plugin @mxssfd/typedoc-theme --theme my-theme --out docs"
16+
"docs": "yarn build && typedoc --plugin @mxssfd/typedoc-theme --theme my-theme --out docs",
17+
"postinstall": "patch-package"
1718
},
1819
"engines": {
1920
"node": ">=16"
@@ -59,10 +60,13 @@
5960
"browserify-cipher": "^1.0.1",
6061
"eventemitter3": "^4.0.0",
6162
"hdkey": "^1.1.1",
63+
"is-in-browser": "^2.0.0",
6264
"isomorphic-ws": "^5.0.0",
6365
"lodash": "^4.17.20",
6466
"node-seal": "^4.5.7",
67+
"patch-package": "^8.0.0",
6568
"pbkdf2": "^3.0.17",
69+
"postinstall-postinstall": "^2.1.0",
6670
"randombytes": "^2.1.0",
6771
"scryptsy": "^2.1.0",
6872
"semver": "^6.3.0",

patches/isomorphic-ws+5.0.0.patch

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
diff --git a/node_modules/isomorphic-ws/index.d.ts b/node_modules/isomorphic-ws/index.d.ts
2+
index de923a9..7d56cf5 100644
3+
--- a/node_modules/isomorphic-ws/index.d.ts
4+
+++ b/node_modules/isomorphic-ws/index.d.ts
5+
@@ -3,6 +3,9 @@
6+
// Fix for https://github.com/heineiuo/isomorphic-ws/issues/8
7+
// If there is still something wrong, welcome issue.
8+
9+
-import WebSocket = require('ws')
10+
+// NOTE(jiyoung): comment out for original reference.
11+
+// import WebSocket = require('ws')
12+
+// export = WebSocket
13+
14+
-export = WebSocket
15+
\ No newline at end of file
16+
+import { WebSocket } from 'ws'
17+
+export default WebSocket
18+
\ No newline at end of file

src/event-manager/event-channel-client.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Ain from '../ain';
2-
import * as WebSocket from 'isomorphic-ws';
2+
import isBrowser from "is-in-browser";
3+
import WebSocket from 'isomorphic-ws';
4+
import { WebSocket as WebSocketBE } from 'ws';
35
import {
46
EventChannelMessageTypes,
57
EventChannelMessage,
@@ -21,7 +23,7 @@ export default class EventChannelClient {
2123
/** The event callback manager object. */
2224
private readonly _eventCallbackManager: EventCallbackManager;
2325
/** The web socket client. */
24-
private _ws?: WebSocket;
26+
private _ws?: WebSocket | WebSocketBE;
2527
/** The blockchain endpoint URL. */
2628
private _endpointUrl?: string;
2729
/** Whether it's connected or not. */
@@ -86,7 +88,8 @@ export default class EventChannelClient {
8688
}
8789

8890
this._endpointUrl = url;
89-
this._ws = new WebSocket(url);
91+
// NOTE(platfowner): Fix WebSocket module import issue (see https://github.com/ainblockchain/ain-js/issues/177).
92+
this._ws = isBrowser ? new WebSocket(url) : new WebSocketBE(url);
9093
// NOTE(platfowner): A custom handshake timeout (see https://github.com/ainblockchain/ain-js/issues/171).
9194
this.startHandshakeTimer(DEFAULT_HANDSHAKE_TIMEOUT_MS);
9295

0 commit comments

Comments
 (0)