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/dist/index.js

    r59329aa re29cc2e  
    3030const stream_1 = require("stream");
    3131const path = require("path");
    32 const engine = require("engine.io");
     32const engine_io_1 = require("engine.io");
    3333const client_1 = require("./client");
    3434const events_1 = require("events");
     
    4141const socket_1 = require("./socket");
    4242Object.defineProperty(exports, "Socket", { enumerable: true, get: function () { return socket_1.Socket; } });
    43 const debug = debug_1.default("socket.io:server");
     43const typed_events_1 = require("./typed-events");
     44const uws_js_1 = require("./uws.js");
     45const debug = (0, debug_1.default)("socket.io:server");
    4446const clientVersion = require("../package.json").version;
    4547const dotMapRegex = /\.map/;
    46 class Server extends events_1.EventEmitter {
     48class Server extends typed_events_1.StrictEventEmitter {
    4749    constructor(srv, opts = {}) {
    4850        super();
     
    6668        this.sockets = this.of("/");
    6769        this.opts = opts;
    68         if (srv)
     70        if (srv || typeof srv == "number")
    6971            this.attach(srv);
    7072    }
     
    9597            nextFn.value(name, auth, (err, allow) => {
    9698                if (err || !allow) {
    97                     run();
     99                    return run();
    98100                }
    99                 else {
    100                     fn(this.parentNsps.get(nextFn.value).createChild(name));
     101                if (this._nsps.has(name)) {
     102                    // the namespace was created in the meantime
     103                    debug("dynamic namespace %s already exists", name);
     104                    return fn(this._nsps.get(name));
    101105                }
     106                const namespace = this.parentNsps.get(nextFn.value).createChild(name);
     107                debug("dynamic namespace %s was created", name);
     108                // @ts-ignore
     109                this.sockets.emitReserved("new_namespace", namespace);
     110                fn(namespace);
    102111            });
    103112        };
     
    111120        this.clientPathRegex = new RegExp("^" +
    112121            escapedPath +
    113             "/socket\\.io(\\.min|\\.msgpack\\.min)?\\.js(\\.map)?$");
     122            "/socket\\.io(\\.msgpack|\\.esm)?(\\.min)?\\.js(\\.map)?(?:\\?|$)");
    114123        return this;
    115124    }
     
    174183        return this;
    175184    }
     185    attachApp(app /*: TemplatedApp */, opts = {}) {
     186        // merge the options passed to the Socket.IO server
     187        Object.assign(opts, this.opts);
     188        // set engine.io path to `/socket.io`
     189        opts.path = opts.path || this._path;
     190        // initialize engine
     191        debug("creating uWebSockets.js-based engine with opts %j", opts);
     192        const engine = new engine_io_1.uServer(opts);
     193        engine.attach(app, opts);
     194        // bind to engine events
     195        this.bind(engine);
     196        if (this._serveClient) {
     197            // attach static file serving
     198            app.get(`${this._path}/*`, (res, req) => {
     199                if (!this.clientPathRegex.test(req.getUrl())) {
     200                    req.setYield(true);
     201                    return;
     202                }
     203                const filename = req
     204                    .getUrl()
     205                    .replace(this._path, "")
     206                    .replace(/\?.*$/, "")
     207                    .replace(/^\//, "");
     208                const isMap = dotMapRegex.test(filename);
     209                const type = isMap ? "map" : "source";
     210                // Per the standard, ETags must be quoted:
     211                // https://tools.ietf.org/html/rfc7232#section-2.3
     212                const expectedEtag = '"' + clientVersion + '"';
     213                const weakEtag = "W/" + expectedEtag;
     214                const etag = req.getHeader("if-none-match");
     215                if (etag) {
     216                    if (expectedEtag === etag || weakEtag === etag) {
     217                        debug("serve client %s 304", type);
     218                        res.writeStatus("304 Not Modified");
     219                        res.end();
     220                        return;
     221                    }
     222                }
     223                debug("serve client %s", type);
     224                res.writeHeader("cache-control", "public, max-age=0");
     225                res.writeHeader("content-type", "application/" + (isMap ? "json" : "javascript"));
     226                res.writeHeader("etag", expectedEtag);
     227                const filepath = path.join(__dirname, "../client-dist/", filename);
     228                (0, uws_js_1.serveFile)(res, filepath);
     229            });
     230        }
     231        (0, uws_js_1.patchAdapter)(app);
     232    }
    176233    /**
    177234     * Initialize engine
     
    184241        // initialize engine
    185242        debug("creating engine.io instance with opts %j", opts);
    186         this.eio = engine.attach(srv, opts);
     243        this.eio = (0, engine_io_1.attach)(srv, opts);
    187244        // attach static file serving
    188245        if (this._serveClient)
     
    222279     */
    223280    serve(req, res) {
    224         const filename = req.url.replace(this._path, "");
     281        const filename = req.url.replace(this._path, "").replace(/\?.*$/, "");
    225282        const isMap = dotMapRegex.test(filename);
    226283        const type = isMap ? "map" : "source";
     
    242299        res.setHeader("Content-Type", "application/" + (isMap ? "json" : "javascript"));
    243300        res.setHeader("ETag", expectedEtag);
    244         if (!isMap) {
    245             res.setHeader("X-SourceMap", filename.substring(1) + ".map");
    246         }
    247301        Server.sendFile(filename, req, res);
    248302    }
     
    254308     */
    255309    static sendFile(filename, req, res) {
    256         const readStream = fs_1.createReadStream(path.join(__dirname, "../client-dist/", filename));
     310        const readStream = (0, fs_1.createReadStream)(path.join(__dirname, "../client-dist/", filename));
    257311        const encoding = accepts(req).encodings(["br", "gzip", "deflate"]);
    258312        const onError = (err) => {
     
    264318            case "br":
    265319                res.writeHead(200, { "content-encoding": "br" });
    266                 readStream.pipe(zlib_1.createBrotliCompress()).pipe(res);
    267                 stream_1.pipeline(readStream, zlib_1.createBrotliCompress(), res, onError);
     320                readStream.pipe((0, zlib_1.createBrotliCompress)()).pipe(res);
     321                (0, stream_1.pipeline)(readStream, (0, zlib_1.createBrotliCompress)(), res, onError);
    268322                break;
    269323            case "gzip":
    270324                res.writeHead(200, { "content-encoding": "gzip" });
    271                 stream_1.pipeline(readStream, zlib_1.createGzip(), res, onError);
     325                (0, stream_1.pipeline)(readStream, (0, zlib_1.createGzip)(), res, onError);
    272326                break;
    273327            case "deflate":
    274328                res.writeHead(200, { "content-encoding": "deflate" });
    275                 stream_1.pipeline(readStream, zlib_1.createDeflate(), res, onError);
     329                (0, stream_1.pipeline)(readStream, (0, zlib_1.createDeflate)(), res, onError);
    276330                break;
    277331            default:
    278332                res.writeHead(200);
    279                 stream_1.pipeline(readStream, res, onError);
     333                (0, stream_1.pipeline)(readStream, res, onError);
    280334        }
    281335    }
     
    338392            nsp = new namespace_1.Namespace(this, name);
    339393            this._nsps.set(name, nsp);
     394            if (name !== "/") {
     395                // @ts-ignore
     396                this.sockets.emitReserved("new_namespace", nsp);
     397            }
    340398        }
    341399        if (fn)
     
    354412        }
    355413        this.engine.close();
     414        // restore the Adapter prototype
     415        (0, uws_js_1.restoreAdapter)();
    356416        if (this.httpServer) {
    357417            this.httpServer.close(fn);
     
    374434     * Targets a room when emitting.
    375435     *
     436     * @param room
     437     * @return self
     438     * @public
     439     */
     440    to(room) {
     441        return this.sockets.to(room);
     442    }
     443    /**
     444     * Targets a room when emitting.
     445     *
     446     * @param room
     447     * @return self
     448     * @public
     449     */
     450    in(room) {
     451        return this.sockets.in(room);
     452    }
     453    /**
     454     * Excludes a room when emitting.
     455     *
    376456     * @param name
    377457     * @return self
    378458     * @public
    379459     */
    380     to(name) {
    381         this.sockets.to(name);
    382         return this;
    383     }
    384     /**
    385      * Targets a room when emitting.
    386      *
    387      * @param name
    388      * @return self
    389      * @public
    390      */
    391     in(name) {
    392         this.sockets.in(name);
    393         return this;
     460    except(name) {
     461        return this.sockets.except(name);
    394462    }
    395463    /**
     
    414482    }
    415483    /**
     484     * Emit a packet to other Socket.IO servers
     485     *
     486     * @param ev - the event name
     487     * @param args - an array of arguments, which may include an acknowledgement callback at the end
     488     * @public
     489     */
     490    serverSideEmit(ev, ...args) {
     491        return this.sockets.serverSideEmit(ev, ...args);
     492    }
     493    /**
    416494     * Gets a list of socket ids.
    417495     *
     
    429507     */
    430508    compress(compress) {
    431         this.sockets.compress(compress);
    432         return this;
     509        return this.sockets.compress(compress);
    433510    }
    434511    /**
     
    441518     */
    442519    get volatile() {
    443         this.sockets.volatile;
    444         return this;
     520        return this.sockets.volatile;
    445521    }
    446522    /**
     
    451527     */
    452528    get local() {
    453         this.sockets.local;
    454         return this;
     529        return this.sockets.local;
     530    }
     531    /**
     532     * Returns the matching socket instances
     533     *
     534     * @public
     535     */
     536    fetchSockets() {
     537        return this.sockets.fetchSockets();
     538    }
     539    /**
     540     * Makes the matching socket instances join the specified rooms
     541     *
     542     * @param room
     543     * @public
     544     */
     545    socketsJoin(room) {
     546        return this.sockets.socketsJoin(room);
     547    }
     548    /**
     549     * Makes the matching socket instances leave the specified rooms
     550     *
     551     * @param room
     552     * @public
     553     */
     554    socketsLeave(room) {
     555        return this.sockets.socketsLeave(room);
     556    }
     557    /**
     558     * Makes the matching socket instances disconnect
     559     *
     560     * @param close - whether to close the underlying connection
     561     * @public
     562     */
     563    disconnectSockets(close = false) {
     564        return this.sockets.disconnectSockets(close);
    455565    }
    456566}
     
    469579module.exports = (srv, opts) => new Server(srv, opts);
    470580module.exports.Server = Server;
     581module.exports.Namespace = namespace_1.Namespace;
     582module.exports.Socket = socket_1.Socket;
Note: See TracChangeset for help on using the changeset viewer.