Files
2026-07-26 18:25:37 +09:00

100 lines
4.7 KiB
JavaScript

import { redisClient } from "../db/redis.js";
import config from "../config/index.js";
class Publisher {
publish = (channel, type, value)=>{
const message = type == null ? value : value == null ? {
type: type,
body: null
} : {
type: type,
body: value
};
redisClient.publish(config.redis.prefix ?? config.host, JSON.stringify({
channel: channel,
message: message
}));
};
publishInternalEvent = (type, value)=>{
this.publish("internal", type, typeof value === "undefined" ? null : value);
};
publishUserEvent = (userId, type, value)=>{
this.publish(`user:${userId}`, type, typeof value === "undefined" ? null : value);
};
publishBroadcastStream = (type, value)=>{
this.publish("broadcast", type, typeof value === "undefined" ? null : value);
};
publishMainStream = (userId, type, value)=>{
this.publish(`mainStream:${userId}`, type, typeof value === "undefined" ? null : value);
};
publishDriveStream = (userId, type, value)=>{
this.publish(`driveStream:${userId}`, type, typeof value === "undefined" ? null : value);
};
publishNoteStream = (noteId, type, value)=>{
const object = {
id: noteId,
body: value
};
this.publish(`noteStream:${noteId}`, type, object);
};
publishNoteUpdatesStream = (type, value)=>{
this.publish('noteUpdatesStream', type, value);
};
publishChannelStream = (channelId, type, value)=>{
this.publish(`channelStream:${channelId}`, type, typeof value === "undefined" ? null : value);
};
publishUserListStream = (listId, type, value)=>{
this.publish(`userListStream:${listId}`, type, typeof value === "undefined" ? null : value);
};
publishAntennaStream = (antennaId, type, value)=>{
this.publish(`antennaStream:${antennaId}`, type, typeof value === "undefined" ? null : value);
};
publishMessagingStream = (userId, otherpartyId, type, value)=>{
this.publish(`messagingStream:${userId}-${otherpartyId}`, type, typeof value === "undefined" ? null : value);
};
publishGroupMessagingStream = (groupId, type, value)=>{
this.publish(`messagingStream:${groupId}`, type, typeof value === "undefined" ? null : value);
};
publishMessagingIndexStream = (userId, type, value)=>{
this.publish(`messagingIndexStream:${userId}`, type, typeof value === "undefined" ? null : value);
};
publishNotesStream = (note)=>{
this.publish("notesStream", null, note);
};
publishAdminStream = (userId, type, value)=>{
this.publish(`adminStream:${userId}`, type, typeof value === "undefined" ? null : value);
};
publishReversiStream = (userId, type, value)=>{
this.publish(`reversiStream:${userId}`, type, typeof value === "undefined" ? null : value);
};
publishReversiGameStream = (gameId, type, value)=>{
this.publish(`reversiGameStream:${gameId}`, type, typeof value === "undefined" ? null : value);
};
publishShogiStream = (userId, type, value)=>{
this.publish(`shogiStream:${userId}`, type, typeof value === "undefined" ? null : value);
};
publishShogiGameStream = (gameId, type, value)=>{
this.publish(`shogiGameStream:${gameId}`, type, typeof value === "undefined" ? null : value);
};
}
const publisher = new Publisher();
export default publisher;
export const publishInternalEvent = publisher.publishInternalEvent;
export const publishUserEvent = publisher.publishUserEvent;
export const publishBroadcastStream = publisher.publishBroadcastStream;
export const publishMainStream = publisher.publishMainStream;
export const publishDriveStream = publisher.publishDriveStream;
export const publishNoteStream = publisher.publishNoteStream;
export const publishNotesStream = publisher.publishNotesStream;
export const publishNoteUpdatesStream = publisher.publishNoteUpdatesStream;
export const publishChannelStream = publisher.publishChannelStream;
export const publishUserListStream = publisher.publishUserListStream;
export const publishAntennaStream = publisher.publishAntennaStream;
export const publishMessagingStream = publisher.publishMessagingStream;
export const publishGroupMessagingStream = publisher.publishGroupMessagingStream;
export const publishMessagingIndexStream = publisher.publishMessagingIndexStream;
export const publishAdminStream = publisher.publishAdminStream;
export const publishReversiStream = publisher.publishReversiStream;
export const publishReversiGameStream = publisher.publishReversiGameStream;
export const publishShogiStream = publisher.publishShogiStream;
export const publishShogiGameStream = publisher.publishShogiGameStream;