| 308 | private logger: Logger; |
| 309 | |
| 310 | constructor(token: string, { |
| 311 | slackApiUrl = 'https://slack.com/api/', |
| 312 | logger = undefined, |
| 313 | logLevel = LogLevel.INFO, |
| 314 | retryConfig, |
| 315 | agent = undefined, |
| 316 | autoReconnect = true, |
| 317 | useRtmConnect = true, |
| 318 | clientPingTimeout, |
| 319 | serverPongTimeout, |
| 320 | replyAckOnReconnectTimeout = 2000, |
| 321 | tls = undefined, |
| 322 | }: RTMClientOptions = {}) { |
| 323 | super(); |
| 324 | this.webClient = new WebClient(token, { |
| 325 | slackApiUrl, |
| 326 | logger, |
| 327 | logLevel, |
| 328 | retryConfig, |
| 329 | agent, |
| 330 | tls, |
| 331 | maxRequestConcurrency: 1, |
| 332 | }); |
| 333 | |
| 334 | this.agentConfig = agent; |
| 335 | this.autoReconnect = autoReconnect; |
| 336 | this.useRtmConnect = useRtmConnect; |
| 337 | this.replyAckOnReconnectTimeout = replyAckOnReconnectTimeout; |
| 338 | // NOTE: may want to filter the keys to only those acceptable for TLS options |
| 339 | this.tlsConfig = tls !== undefined ? tls : {}; |
| 340 | |
| 341 | this.keepAlive = new KeepAlive({ |
| 342 | clientPingTimeout, |
| 343 | serverPongTimeout, |
| 344 | logger, |
| 345 | logLevel, |
| 346 | }); |
| 347 | this.keepAlive.on( |
| 348 | 'recommend_reconnect', |
| 349 | () => { |
| 350 | if (this.websocket !== undefined) { |
| 351 | // this will trigger the 'websocket close' event on the state machine, which transitions to clean up |
| 352 | this.websocket.close(); |
| 353 | |
| 354 | // if the websocket actually is no longer connected, the eventual 'websocket close' event will take a long |
| 355 | // time, because it won't fire until the close handshake completes. in the meantime, stop the keep alive so we |
| 356 | // don't send pings on a dead connection. |
| 357 | this.keepAlive.stop(); |
| 358 | } |
| 359 | }, |
| 360 | this, |
| 361 | ); |
| 362 | |
| 363 | // Logging |
| 364 | this.logger = getLogger(RTMClient.loggerName, logLevel, logger); |
| 365 | |
| 366 | this.stateMachine = Finity.start(this.stateMachineConfig); |
| 367 | |