import * as Html5WebSocket from '@ont-community/html5-websocket' ; import { TEST_ONT_URL } from '../consts' ; /**
 * We can import html5-websocket directly, because webpack will use html5-websocket/browser.js
 * in browser environment, which does not require 'ws'.
 */ deprecated export default class TxSender { SOCKET_URL : string ; constructor ( socketUrl ? ) { this . SOCKET_URL = socketUrl || TEST_ONT_URL . SOCKET_URL ; } sendTxWithSocket ( param , callback ) { if ( ! param ) { return ; } const socket = new Html5WebSocket ( this . SOCKET_URL ) ; socket . onopen = ( ) => { socket . send ( param ) ; } ; socket . onmessage = ( event ) => { let res ; if ( typeof event . data === 'string' ) { res = JSON . parse ( event . data ) ; } else { res = event . data ; } if ( callback ) { callback ( null , res , socket ) ; } } ; socket . onerror = ( err ) => { console . log ( err ) ; callback ( err , null , null ) ; socket . close ( ) ; } ; } }