import { EventEmitter } from "events" ; import * as util from "util" ; import * as core from "@fluidframework/server-services-core" ; import Redis from "ioredis" ; import { Emitter as SocketIoEmitter } from "@socket.io/redis-emitter" ; export class SocketIoRedisTopic implements core . ITopic { constructor ( private readonly topic ) { } public emit ( event , ... args ) { this . topic . emit ( event , ... args ) ; } } export class SocketIoRedisPublisher implements core . IPublisher { private readonly redisClient : Redis . Redis ; private readonly io : any ; private readonly events = new EventEmitter ( ) ; constructor ( options ) { this . redisClient = new Redis ( options ) ; this . io = new SocketIoEmitter ( this . redisClient ) ; this . redisClient . on ( "error" , ( error ) => { this . events . emit ( "error" , error ) ; } ) ; } public on ( event , listener ) { this . events . on ( event , listener ) ; } public to ( topic ) { return new SocketIoRedisTopic ( this . io . to ( topic ) ) ; } public async emit ( topic , event , ... args ) { this . io . to ( topic ) . emit ( event , ... args ) ; } public close ( ) { return util . promisify ( ( ( callback ) => this . redisClient . quit ( callback ) ) as any ) ( ) ; } }