From 7c679aa0d2beea872658f5cd5950c11f8918c9d5 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Fri, 5 Sep 2025 20:39:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(wip):=20=E9=80=B2=E4=B8=80=E6=AD=A5?= =?UTF-8?q?=E5=AE=8C=E5=96=84=20Client=20=E8=88=87=E6=9C=8D=E5=8B=99?= =?UTF-8?q?=E7=AB=AF=E7=9A=84=E4=BA=A4=E4=BA=92=E9=82=8F=E8=BC=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/api/ApiCallbackMessage.ts | 14 ++++++++++++++ client/api/ApiDeclare.ts | 3 +++ client/api/Client.ts | 10 ++++++++++ 3 files changed, 27 insertions(+) create mode 100644 client/api/ApiCallbackMessage.ts create mode 100644 client/api/ApiDeclare.ts diff --git a/client/api/ApiCallbackMessage.ts b/client/api/ApiCallbackMessage.ts new file mode 100644 index 0000000..185651b --- /dev/null +++ b/client/api/ApiCallbackMessage.ts @@ -0,0 +1,14 @@ +type ApiCallbackMessage = { + msg: string, + /** + * 200: 成功 + * 400: 伺服器端無法理解客戶端請求 + * 401: 需要身份驗證 + * 403: 伺服器端拒絕執行客戶端請求 + * 404: Not Found + * 500: 伺服器端錯誤 + * 501: 伺服器端不支持請求的功能 + */ + code: 200 | 400 | 401 | 403 | 404 | 500 | 501, +} +export default ApiCallbackMessage diff --git a/client/api/ApiDeclare.ts b/client/api/ApiDeclare.ts new file mode 100644 index 0000000..a907e67 --- /dev/null +++ b/client/api/ApiDeclare.ts @@ -0,0 +1,3 @@ +export type CallMethod = + "User.register" | + "User.login" diff --git a/client/api/Client.ts b/client/api/Client.ts index 983ea07..55a7d14 100644 --- a/client/api/Client.ts +++ b/client/api/Client.ts @@ -1,4 +1,6 @@ import { io, Socket } from 'https://unpkg.com/socket.io-client@4.8.1/dist/socket.io.esm.min.js' +import { CallMethod } from './ApiDeclare.ts' +import ApiCallbackMessage from './ApiCallbackMessage.ts' class Client { static socket: Socket @@ -6,6 +8,14 @@ class Client { this.socket && this.socket.disconnect() this.socket = io() } + static call(method: CallMethod, args: {}, timeout: number = 5000) { + return new Promise((resolve, reject) => { + this.socket.timeout().emit("The_White_Silk", (err, res: ApiCallbackMessage) => { + if (err) return reject(err) + + }) + }) + } } export default Client