问卷
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user