(options: InitializationOptions)
| 79 | public configurations: Map<string, EnhancedConfig> |
| 80 | |
| 81 | constructor(options: InitializationOptions) { |
| 82 | validateOptions(options) |
| 83 | |
| 84 | const { |
| 85 | system = DEFAULT_SYSTEM, |
| 86 | name = DEFAULT_APP_NAME, |
| 87 | appVersion = DEFAULT_APP_VERSION, |
| 88 | networkId, |
| 89 | transactionHandlers = [], |
| 90 | ws, |
| 91 | onopen, |
| 92 | ondown, |
| 93 | onreopen, |
| 94 | onerror, |
| 95 | onclose |
| 96 | } = options |
| 97 | |
| 98 | const { apiUrl } = options as InitializationOptionsApiUrl |
| 99 | const { dappId } = options as InitializationOptionsDappId |
| 100 | |
| 101 | // override default timeout to allow for slow connections |
| 102 | const timeout = { connectTimeout: 10000 } |
| 103 | |
| 104 | const socket = new SturdyWebSocket( |
| 105 | apiUrl || 'wss://api.blocknative.com/v0', |
| 106 | ws |
| 107 | ? { |
| 108 | wsConstructor: ws, |
| 109 | ...timeout |
| 110 | } |
| 111 | : { ...timeout } |
| 112 | ) |
| 113 | |
| 114 | socket.onopen = onOpen.bind(this, onopen) |
| 115 | socket.ondown = onDown.bind(this, ondown) |
| 116 | socket.onreopen = onReopen.bind(this, onreopen) |
| 117 | socket.onmessage = handleMessage.bind(this) |
| 118 | socket.onerror = (error: any) => |
| 119 | onerror && onerror({ message: 'There was a WebSocket error', error }) |
| 120 | socket.onclose = () => { |
| 121 | this._pingTimeout && clearInterval(this._pingTimeout) |
| 122 | onclose && onclose() |
| 123 | } |
| 124 | |
| 125 | const storageKey = CryptoEs.SHA1(`${dappId} - ${name}`).toString() |
| 126 | const storedConnectionId = |
| 127 | isLocalStorageAvailable() && window.localStorage.getItem(storageKey) |
| 128 | |
| 129 | this._storageKey = storageKey |
| 130 | this._connectionId = storedConnectionId || undefined |
| 131 | this._dappId = dappId |
| 132 | this._system = system |
| 133 | this._networkId = networkId |
| 134 | this._appName = name |
| 135 | this._appVersion = appVersion |
| 136 | this._transactionHandlers = transactionHandlers |
| 137 | this._socket = socket |
| 138 | this._connected = false |
nothing calls this directly
no test coverage detected