Skip to content

Commit

Permalink
Polyfill websocket for nodejs (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
inwonkim committed Aug 29, 2023
1 parent a319128 commit 88c2979
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 118 deletions.
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

0 comments on commit 88c2979

Please sign in to comment.