(pubClient: any, subClient: any, opts?: RedisEngineOptions)
| 135 | private readonly _channelPrefix: string; |
| 136 | |
| 137 | constructor(pubClient: any, subClient: any, opts?: RedisEngineOptions) { |
| 138 | super(opts); |
| 139 | this._pubClient = pubClient; |
| 140 | this._channelPrefix = opts?.channelPrefix || "engine.io"; |
| 141 | const channels = [ |
| 142 | channelName(this._channelPrefix), |
| 143 | channelName(this._channelPrefix, this._nodeId), |
| 144 | ]; |
| 145 | |
| 146 | debug("subscribing to redis channels: %s", channels); |
| 147 | SUBSCRIBE(subClient, channels, (buffer: Buffer) => { |
| 148 | let message: Message & { _source?: string; _primaryId?: string }; |
| 149 | try { |
| 150 | message = decode(buffer) as Message; |
| 151 | } catch (e) { |
| 152 | debug("ignore malformed buffer"); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | if (message._source !== MESSAGE_SOURCE) { |
| 157 | debug("ignore message from unknown source"); |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | debug("received message: %j", message); |
| 162 | this.onMessage(message); |
| 163 | }); |
| 164 | } |
| 165 | |
| 166 | publishMessage(message: Message & { _source?: string }): void { |
| 167 | // @ts-expect-error recipientId is not defined for all messages |
nothing calls this directly
no test coverage detected