123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- "use strict";
- const sockjs = require("sockjs");
- const BaseServer = require("./BaseServer");
- {
-
- const SockjsSession = require("sockjs/lib/transport").Session;
- const decorateConnection = SockjsSession.prototype.decorateConnection;
-
-
- SockjsSession.prototype.decorateConnection = function (req) {
- decorateConnection.call(this, req);
- const connection = this.connection;
- if (
- connection.headers &&
- !("origin" in connection.headers) &&
- "origin" in req.headers
- ) {
- connection.headers.origin = req.headers.origin;
- }
- };
- }
- module.exports = class SockJSServer extends BaseServer {
-
-
- constructor(server) {
- super(server);
- const webSocketServerOptions =
-
- (
-
- (this.server.options.webSocketServer).options
- );
-
- const getSockjsUrl = (options) => {
- if (typeof options.sockjsUrl !== "undefined") {
- return options.sockjsUrl;
- }
- return "/__webpack_dev_server__/sockjs.bundle.js";
- };
- this.implementation = sockjs.createServer({
-
- sockjs_url: getSockjsUrl(webSocketServerOptions),
-
-
- log: (severity, line) => {
- if (severity === "error") {
- this.server.logger.error(line);
- } else if (severity === "info") {
- this.server.logger.log(line);
- } else {
- this.server.logger.debug(line);
- }
- },
- });
-
- const getPrefix = (options) => {
- if (typeof options.prefix !== "undefined") {
- return options.prefix;
- }
- return options.path;
- };
- const options = {
- ...webSocketServerOptions,
- prefix: getPrefix(webSocketServerOptions),
- };
- this.implementation.installHandlers(
- (this.server.server),
- options
- );
- this.implementation.on("connection", (client) => {
-
-
- client.send = client.write;
-
- client.terminate = client.close;
- this.clients.push( (client));
- client.on("close", () => {
- this.clients.splice(
- this.clients.indexOf( (client)),
- 1
- );
- });
- });
-
- this.implementation.close = (callback) => {
- callback();
- };
- }
- };
|