How to use the @zilliqa-js/subscriptions.SocketConnect.CLOSE function in @zilliqa-js/subscriptions

To help you get started, we’ve selected a few @zilliqa-js/subscriptions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Zilliqa / Zilliqa-JavaScript-Library / examples / newTxBlockSubscriptions.js View on Github external
const subscriber = zilliqa.subscriptionBuilder.buildNewBlockSubscriptions(
    'ws://',
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_NEW_BLOCK, (event) => {
    console.log('get SubscribeNewBlock echo: ', event);
  });

  subscriber.emitter.on(MessageType.NEW_BLOCK, (event) => {
    console.log('get new block: ', event.value.TxBlock.header);
  });

  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  subscriber.emitter.on(SocketConnect.CLOSE, (event) => {
    console.log('get socket close: ', event);
  });

  subscriber.emitter.on(SocketConnect.ERROR, (event) => {
    console.log('get socket error: ', event);
  });

  await subscriber.start();
  // await subscriber.stop();
}