This commit is contained in:
luying
2022-04-11 20:32:08 +08:00
parent d4a103a6b1
commit c6ebb62c6a
14 changed files with 124 additions and 49 deletions
+21 -1
View File
@@ -2,9 +2,29 @@ import { Channel, pinus } from "pinus";
import { CHANNEL_PREFIX, PUSH_BATCH, PUSH_INTERVAL, PUSH_ROUTE, STATUS } from "../consts";
import { resResult } from "../pubUtils/util";
import { getCityChannelSid, getGuildChannelSid, getWorldChannelSid, groupRoomId } from "./chatService";
import { getRoleOnlineInfo } from "./redisService";
import { getAllOnlineRoles, getRoleOnlineInfo } from "./redisService";
import { errlogger, infologger } from '../util/logger';
export async function sendMessageToAllWithSuc(route: string, data: any) {
await sendMessageToAll(route, resResult(STATUS.SUCCESS, data));
}
export async function sendMessageToAll(route: string, data: any) {
let allOnlineUsers = await getAllOnlineRoles();
let n = Math.ceil(allOnlineUsers.length / PUSH_BATCH); // 一共多少批
let i = -1;
let interval = setInterval(() => {
if (++i < n) {
let users = allOnlineUsers.slice(i * PUSH_BATCH, (i + 1) * PUSH_BATCH - 1);
let uids = users.map(cur => ({ uid: cur.roleId, sid: cur.sid }));
pinus.app.channelService.pushMessageByUids(route, data, uids);
} else {
clearInterval(interval);
}
}, PUSH_INTERVAL);
}
export async function sendMessageToServerWithSuc(serverId: number, route: string, data: any, isBatch = false) {
await sendMessageToServer(serverId, route, resResult(STATUS.SUCCESS, data), isBatch);
}