Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/socket.io-adapter/dist/index.js

    r59329aa re29cc2e  
    6060    }
    6161    _del(room, id) {
    62         if (this.rooms.has(room)) {
    63             const deleted = this.rooms.get(room).delete(id);
     62        const _room = this.rooms.get(room);
     63        if (_room != null) {
     64            const deleted = _room.delete(id);
    6465            if (deleted) {
    6566                this.emit("leave-room", room, id);
    6667            }
    67             if (this.rooms.get(room).size === 0) {
    68                 this.rooms.delete(room);
     68            if (_room.size === 0 && this.rooms.delete(room)) {
    6969                this.emit("delete-room", room);
    7070            }
     
    9898     */
    9999    broadcast(packet, opts) {
    100         const rooms = opts.rooms;
    101         const except = opts.except || new Set();
    102100        const flags = opts.flags || {};
    103101        const packetOpts = {
     
    106104            compress: flags.compress
    107105        };
    108         const ids = new Set();
    109106        packet.nsp = this.nsp.name;
    110107        const encodedPackets = this.encoder.encode(packet);
     108        this.apply(opts, socket => {
     109            socket.client.writeToEngine(encodedPackets, packetOpts);
     110        });
     111    }
     112    /**
     113     * Gets a list of sockets by sid.
     114     *
     115     * @param {Set<Room>} rooms   the explicit set of rooms to check.
     116     */
     117    sockets(rooms) {
     118        const sids = new Set();
     119        this.apply({ rooms }, socket => {
     120            sids.add(socket.id);
     121        });
     122        return Promise.resolve(sids);
     123    }
     124    /**
     125     * Gets the list of rooms a given socket has joined.
     126     *
     127     * @param {SocketId} id   the socket id
     128     */
     129    socketRooms(id) {
     130        return this.sids.get(id);
     131    }
     132    /**
     133     * Returns the matching socket instances
     134     *
     135     * @param opts - the filters to apply
     136     */
     137    fetchSockets(opts) {
     138        const sockets = [];
     139        this.apply(opts, socket => {
     140            sockets.push(socket);
     141        });
     142        return Promise.resolve(sockets);
     143    }
     144    /**
     145     * Makes the matching socket instances join the specified rooms
     146     *
     147     * @param opts - the filters to apply
     148     * @param rooms - the rooms to join
     149     */
     150    addSockets(opts, rooms) {
     151        this.apply(opts, socket => {
     152            socket.join(rooms);
     153        });
     154    }
     155    /**
     156     * Makes the matching socket instances leave the specified rooms
     157     *
     158     * @param opts - the filters to apply
     159     * @param rooms - the rooms to leave
     160     */
     161    delSockets(opts, rooms) {
     162        this.apply(opts, socket => {
     163            rooms.forEach(room => socket.leave(room));
     164        });
     165    }
     166    /**
     167     * Makes the matching socket instances disconnect
     168     *
     169     * @param opts - the filters to apply
     170     * @param close - whether to close the underlying connection
     171     */
     172    disconnectSockets(opts, close) {
     173        this.apply(opts, socket => {
     174            socket.disconnect(close);
     175        });
     176    }
     177    apply(opts, callback) {
     178        const rooms = opts.rooms;
     179        const except = this.computeExceptSids(opts.except);
    111180        if (rooms.size) {
     181            const ids = new Set();
    112182            for (const room of rooms) {
    113183                if (!this.rooms.has(room))
     
    118188                    const socket = this.nsp.sockets.get(id);
    119189                    if (socket) {
    120                         socket.packet(encodedPackets, packetOpts);
     190                        callback(socket);
    121191                        ids.add(id);
    122192                    }
     
    130200                const socket = this.nsp.sockets.get(id);
    131201                if (socket)
    132                     socket.packet(encodedPackets, packetOpts);
    133             }
    134         }
    135     }
    136     /**
    137      * Gets a list of sockets by sid.
    138      *
    139      * @param {Set<Room>} rooms   the explicit set of rooms to check.
    140      */
    141     sockets(rooms) {
    142         const sids = new Set();
    143         if (rooms.size) {
    144             for (const room of rooms) {
    145                 if (!this.rooms.has(room))
    146                     continue;
    147                 for (const id of this.rooms.get(room)) {
    148                     if (this.nsp.sockets.has(id)) {
    149                         sids.add(id);
    150                     }
     202                    callback(socket);
     203            }
     204        }
     205    }
     206    computeExceptSids(exceptRooms) {
     207        const exceptSids = new Set();
     208        if (exceptRooms && exceptRooms.size > 0) {
     209            for (const room of exceptRooms) {
     210                if (this.rooms.has(room)) {
     211                    this.rooms.get(room).forEach(sid => exceptSids.add(sid));
    151212                }
    152213            }
    153214        }
    154         else {
    155             for (const [id] of this.sids) {
    156                 if (this.nsp.sockets.has(id))
    157                     sids.add(id);
    158             }
    159         }
    160         return Promise.resolve(sids);
    161     }
    162     /**
    163      * Gets the list of rooms a given socket has joined.
    164      *
    165      * @param {SocketId} id   the socket id
    166      */
    167     socketRooms(id) {
    168         return this.sids.get(id);
     215        return exceptSids;
     216    }
     217    /**
     218     * Send a packet to the other Socket.IO servers in the cluster
     219     * @param packet - an array of arguments, which may include an acknowledgement callback at the end
     220     */
     221    serverSideEmit(packet) {
     222        throw new Error("this adapter does not support the serverSideEmit() functionality");
    169223    }
    170224}
Note: See TracChangeset for help on using the changeset viewer.