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 + }) +} +