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

Function patchAdapter

packages/socket.io/lib/uws.ts:13–92  ·  packages/socket.io/lib/uws.ts::patchAdapter
(app /* : TemplatedApp */)

Source from the content-addressed store, hash-verified

11const { addAll, del, broadcast } = Adapter.prototype;
12
13export function patchAdapter(app /* : TemplatedApp */) {
14 Adapter.prototype.addAll = function (id, rooms) {
15 const isNew = !this.sids.has(id);
16 addAll.call(this, id, rooms);
17 const socket: Socket =
18 this.nsp.sockets.get(id) || this.nsp._preConnectSockets.get(id);
19 if (!socket) {
20 return;
21 }
22 if (socket.conn.transport.name === class="st">"websocket") {
23 subscribe(this.nsp.name, socket, isNew, rooms);
24 return;
25 }
26 if (isNew) {
27 socket.conn.on(class="st">"upgrade", () => {
28 const rooms = this.sids.get(id);
29 if (rooms) {
30 subscribe(this.nsp.name, socket, isNew, rooms);
31 }
32 });
33 }
34 };
35
36 Adapter.prototype.del = function (id, room) {
37 del.call(this, id, room);
38 const socket: Socket =
39 this.nsp.sockets.get(id) || this.nsp._preConnectSockets.get(id);
40 if (socket && socket.conn.transport.name === class="st">"websocket") {
41 class="cm">// @ts-ignore
42 const sessionId = socket.conn.id;
43 class="cm">// @ts-ignore
44 const websocket: WebSocket = socket.conn.transport.socket;
45 const topic = `${this.nsp.name}${SEPARATOR}${room}`;
46 debug(class="st">"unsubscribe connection %s from topic %s", sessionId, topic);
47 websocket.unsubscribe(topic);
48 }
49 };
50
51 Adapter.prototype.broadcast = function (packet, opts) {
52 const useFastPublish = opts.rooms.size <= 1 && opts.except!.size === 0;
53 if (!useFastPublish) {
54 broadcast.call(this, packet, opts);
55 return;
56 }
57
58 const flags = opts.flags || {};
59 const basePacketOpts = {
60 preEncoded: true,
61 volatile: flags.volatile,
62 compress: flags.compress,
63 };
64
65 packet.nsp = this.nsp.name;
66 const encodedPackets = this.encoder.encode(packet);
67
68 const topic =
69 opts.rooms.size === 0
70 ? this.nsp.name

Callers 1

attachAppMethod · 0.90

Calls 8

subscribeFunction · 0.85
debugFunction · 0.85
keysMethod · 0.80
applyMethod · 0.80
writeToEngineMethod · 0.80
encodeMethod · 0.65
onMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected