MCPcopy
hub / github.com/socketio/socket.io / onMessage

Function onMessage

packages/socket.io-adapter/lib/cluster-adapter.ts:197–352  ·  view source on GitHub ↗

* Called when receiving a message from another member of the cluster. * * @param message * @param offset * @protected

(message: ClusterMessage, offset?: string)

Source from the content-addressed store, hash-verified

195 * @protected
196 */
197 protected onMessage(message: ClusterMessage, offset?: string) {
198 if (message.uid === this.uid) {
199 return debug("[%s] ignore message from self", this.uid);
200 }
201
202 if (message.nsp !== this.nsp.name) {
203 return debug(
204 "[%s] ignore message from another namespace (%s)",
205 this.uid,
206 message.nsp,
207 );
208 }
209
210 debug(
211 "[%s] new event of type %d from %s",
212 this.uid,
213 message.type,
214 message.uid,
215 );
216
217 switch (message.type) {
218 case MessageType.BROADCAST: {
219 const withAck = message.data.requestId !== undefined;
220 if (withAck) {
221 super.broadcastWithAck(
222 message.data.packet,
223 decodeOptions(message.data.opts),
224 (clientCount) => {
225 debug(
226 "[%s] waiting for %d client acknowledgements",
227 this.uid,
228 clientCount,
229 );
230 this.publishResponse(message.uid, {
231 type: MessageType.BROADCAST_CLIENT_COUNT,
232 data: {
233 requestId: message.data.requestId,
234 clientCount,
235 },
236 });
237 },
238 (arg) => {
239 debug(
240 "[%s] received acknowledgement with value %j",
241 this.uid,
242 arg,
243 );
244 this.publishResponse(message.uid, {
245 type: MessageType.BROADCAST_ACK,
246 data: {
247 requestId: message.data.requestId,
248 packet: arg,
249 },
250 });
251 },
252 );
253 } else {
254 const packet = message.data.packet;

Callers

nothing calls this directly

Calls 10

debugFunction · 0.85
decodeOptionsFunction · 0.85
broadcastWithAckMethod · 0.80
addSocketsMethod · 0.80
delSocketsMethod · 0.80
_onServerSideEmitMethod · 0.80
broadcastMethod · 0.45
disconnectSocketsMethod · 0.45
fetchSocketsMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected