()
| 359 | this.logger?.debug('Connected to Streamer.bot WebSocket server', response.info); |
| 360 | this.info = response.info; |
| 361 | this.version = response.info.version; |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | throw new Error('Handshake failed (unknown)'); |
| 366 | } |
| 367 | |
| 368 | private async authenticate(data: StreamerbotHelloRequest): Promise<void> { |
| 369 | if (!this._authEnabled || !this.options.password) { |
| 370 | this.logger?.debug( |
| 371 | 'No password provided for authentication. Checking if auth is enforced for all requests...', |
| 372 | ); |
| 373 | const res = await this.getInfo(); |
| 374 | if (res.status === 'ok') { |
| 375 | this._authenticated = false; |
| 376 | this.version = data.info.version; |
| 377 | this.info = data.info; |
| 378 | return; |
| 379 | } |
| 380 | await this.disconnect(); |
| 381 | throw new Error('Authentication required'); |
| 382 | } |
| 383 | |
| 384 | if (!data.authentication) { |
| 385 | this.logger?.debug('Missing authentication payload'); |
| 386 | await this.disconnect(); |
| 387 | throw new Error('Invalid authentication payload'); |
| 388 | } |
| 389 | |
| 390 | this.logger?.debug('Authenticating with Streamer.bot WebSocket server...'); |
| 391 | |
| 392 | const { salt, challenge } = data.authentication; |
| 393 | const secret = await sha256base64(`${this.options.password}${salt}`); |
| 394 | const authentication = await sha256base64(`${secret}${challenge}`); |
| 395 | |
| 396 | const response = await this.request({ |
| 397 | request: 'Authenticate', |
| 398 | authentication, |
| 399 | }); |
| 400 | |
| 401 | if (response.status === 'ok') { |
| 402 | this._authenticated = true; |
| 403 | this.version = data.info.version; |
| 404 | this.info = data.info; |
| 405 | } else { |
| 406 | await this.disconnect(); |
| 407 | throw new Error('Authentication failed'); |
| 408 | } |
| 409 | } |
| 410 |
nothing calls this directly
no test coverage detected