Adding websocket.
This commit is contained in:
@@ -3,12 +3,14 @@ import mempool from './mempool';
|
||||
import blocks from './blocks';
|
||||
import transactions from './transactions';
|
||||
import addresses from './addresses';
|
||||
import websocket from './websocket';
|
||||
|
||||
export { default as fees } from './fees';
|
||||
export { default as mempool } from './mempool';
|
||||
export { default as blocks } from './blocks';
|
||||
export { default as transactions } from './transactions';
|
||||
export { default as addresses } from './addresses';
|
||||
export { default as websocket } from './websocket';
|
||||
|
||||
export default {
|
||||
fees,
|
||||
@@ -16,4 +18,5 @@ export default {
|
||||
blocks,
|
||||
transactions,
|
||||
addresses,
|
||||
websocket,
|
||||
};
|
||||
|
||||
22
src/websocket.ts
Normal file
22
src/websocket.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
const WebSocket = require('ws');
|
||||
|
||||
const ws = new WebSocket('wss://mempool.space/api/v1/ws');
|
||||
|
||||
const init = (params: { options: string[] }) => {
|
||||
ws.on('open', function open() {
|
||||
ws.send(JSON.stringify({ action: 'init' }));
|
||||
setInterval(function timeout() {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
action: 'want',
|
||||
data: params.options,
|
||||
})
|
||||
);
|
||||
}, 500);
|
||||
});
|
||||
return ws;
|
||||
};
|
||||
|
||||
export default {
|
||||
init,
|
||||
};
|
||||
Reference in New Issue
Block a user