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

Polyfill websocket for nodejs #80

Merged
merged 2 commits into from
Aug 29, 2023
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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@
"bignumber.js": "^9.1.1",
"bip66": "^1.1.5",
"buffer": "^6.0.3",
"bufferutil": "^4.0.7",
"core-js": "^3.27.1",
"crypto-browserify": "^3.12.0",
"js-sha3": "^0.8.0",
"readable-stream": "^4.3.0",
"secp256k1": "5.0.0",
"utf-8-validate": "^6.0.3",
"utf8": "^3.0.0",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"ws": "^8.13.0"
},
"browser": "./build/icon-sdk-js.web.min.js"
}
20 changes: 20 additions & 0 deletions quickstart/example/js/MonitorNodeExample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const pkg = require("icon-sdk-js");
const { HttpProvider, BlockMonitorSpec, Converter, IconService } = pkg;

const NODE_URL = "http://localhost:9090/api/v3";
const provider = new HttpProvider(NODE_URL + "/icon_dex");
const iconService = new IconService(provider);
async function main() {
const lastBlock = await iconService.getLastBlock().execute();
const height = lastBlock.height;
const spec = new BlockMonitorSpec(Converter.toBigNumber(height + 1));
const onevent = (data) => {
console.log(data);
};
const onerror = (error) => {
console.log(error);
};
const monitor = iconService.monitorBlock(spec, onevent, onerror);
}

main().catch((e) => console.log(e));
6 changes: 5 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const setPlugin = target =>
}
)
]
: [];
: [
new webpack.ProvidePlugin({
WebSocket: ['ws', "WebSocket"]
})
];

const config = target => ({
mode,
Expand Down
Loading
Loading