From 0252c39e182cb1cf1231be1975eae3eade0c471b Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 28 Apr 2021 20:57:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=87=A0=E4=B8=AA=E5=B8=B8?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E5=90=91=E6=B8=B8=E6=88=8F=E6=9C=8D=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=B6=88=E6=81=AF=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/WsSvr.ts | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/services/WsSvr.ts diff --git a/src/services/WsSvr.ts b/src/services/WsSvr.ts new file mode 100644 index 0000000..d729b9c --- /dev/null +++ b/src/services/WsSvr.ts @@ -0,0 +1,66 @@ +import axios from 'axios' + + +const apiBase = 'http://127.0.0.1:2567/api' +/** + * 发送私信给玩家 + * @param roomId + * @param clientId + * @param type + * @param msg + * @return {Promise>} + */ +export async function sendMsg(roomId, clientId, type, msg) { + const url = `${apiBase}/room/call` + const args = [clientId, type, msg] + const data = { + roomId, + method: 'smsg', + args: JSON.stringify(args) + } + return axios.get(url, {params: data}) + .then(res => { + return res.data + }) +} + +/** + * 发送广播消息 + * @param roomId + * @param type + * @param msg + * @return {Promise>} + */ +export async function broadcast(roomId, type, msg) { + const url = `${apiBase}/broadcast` + const data = { + roomId, + type, + msg + } + return axios.get(url, {params: data}) + .then(res => { + return res.data + }) +} + +/** + * 从房间踢掉玩家 + * @param roomId + * @param clientId + * @return {Promise>} + */ +export async function kickClient(roomId, clientId) { + const url = `${apiBase}/room/call` + const args = [clientId] + const data = { + roomId, + method: '_forceClientDisconnect', + args: JSON.stringify(args) + } + return axios.get(url, {params: data}) + .then(res => { + return res.data + }) +} +