Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix websocket module import error #178

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"browserify-cipher": "^1.0.1",
"eventemitter3": "^4.0.0",
"hdkey": "^1.1.1",
"is-in-browser": "^2.0.0",
"isomorphic-ws": "^5.0.0",
"lodash": "^4.17.20",
"node-seal": "^4.5.7",
Expand Down
9 changes: 5 additions & 4 deletions src/event-manager/event-channel-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ain from '../ain';
// NOTE(jiyoung): comment out for original reference.
// import * as WebSocket from 'isomorphic-ws';
import isBrowser from "is-in-browser";
import WebSocket from 'isomorphic-ws';
import { WebSocket as WebSocketBE } from 'ws';
import {
EventChannelMessageTypes,
EventChannelMessage,
Expand All @@ -23,7 +23,7 @@ export default class EventChannelClient {
/** The event callback manager object. */
private readonly _eventCallbackManager: EventCallbackManager;
/** The web socket client. */
private _ws?: WebSocket;
private _ws?: WebSocket | WebSocketBE;
/** The blockchain endpoint URL. */
private _endpointUrl?: string;
/** Whether it's connected or not. */
Expand Down Expand Up @@ -88,7 +88,8 @@ export default class EventChannelClient {
}

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

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,11 @@ is-generator-fn@^2.0.0:
resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-2.1.0.tgz#7d140adc389aaf3011a8f2a2a4cfa6faadffb118"
integrity sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ==

is-in-browser@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-in-browser/-/is-in-browser-2.0.0.tgz#a2343a18d8f8a600e8a20cb3022183a251e30355"
integrity sha512-/NUv5pqj+krUJalhGpj0lyy+x7vrD9jt1PlAfkoIDEXqE+xZgFJ4FU8e9m99WuHbCqsBZVf+nzvAjNso+SO80A==

is-number@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
Expand Down
Loading