(key?: string)
| 87 | // This function will be executed automatically after the connection event is triggered. |
| 88 | // Generally, there is no need to execute it manually. |
| 89 | public async auth(key?: string) { |
| 90 | if (key) this.config.apiKey = key; |
| 91 | const daemonInfo = this.getDaemonInfo(); |
| 92 | try { |
| 93 | const res = await new RemoteRequest(this).request("auth", this.config.apiKey, 5000, true); |
| 94 | if (res === true) { |
| 95 | this.available = true; |
| 96 | await this.setLanguage(); |
| 97 | logger.info($t("TXT_CODE_daemonInfo.authSuccess", { v: daemonInfo })); |
| 98 | return true; |
| 99 | } |
| 100 | this.available = false; |
| 101 | logger.warn($t("TXT_CODE_daemonInfo.authFailure", { v: daemonInfo })); |
| 102 | return false; |
| 103 | } catch (error: any) { |
| 104 | logger.warn($t("TXT_CODE_daemonInfo.authError", { v: daemonInfo })); |
| 105 | logger.warn(error); |
| 106 | return false; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | public emit(event: string, data?: any) { |
| 111 | return this.socket?.emit(event, data); |
no test coverage detected