* Socket constructor. * * @param {String|Object} uri - uri or options * @param {Object} opts - options
(uri)
| 1844 | * @param {Object} opts - options |
| 1845 | */ |
| 1846 | function Socket(uri) { |
| 1847 | var _this; |
| 1848 | var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 1849 | _classCallCheck(this, Socket); |
| 1850 | _this = _super.call(this); |
| 1851 | _this.binaryType = defaultBinaryType; |
| 1852 | _this.writeBuffer = []; |
| 1853 | if (uri && "object" === _typeof(uri)) { |
| 1854 | opts = uri; |
| 1855 | uri = null; |
| 1856 | } |
| 1857 | if (uri) { |
| 1858 | uri = parse(uri); |
| 1859 | opts.hostname = uri.host; |
| 1860 | opts.secure = uri.protocol === "https" || uri.protocol === "wss"; |
| 1861 | opts.port = uri.port; |
| 1862 | if (uri.query) opts.query = uri.query; |
| 1863 | } else if (opts.host) { |
| 1864 | opts.hostname = parse(opts.host).host; |
| 1865 | } |
| 1866 | installTimerFunctions(_assertThisInitialized(_this), opts); |
| 1867 | _this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol; |
| 1868 | if (opts.hostname && !opts.port) { |
| 1869 | // if no port is specified manually, use the protocol default |
| 1870 | opts.port = _this.secure ? "443" : "80"; |
| 1871 | } |
| 1872 | _this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost"); |
| 1873 | _this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : _this.secure ? "443" : "80"); |
| 1874 | _this.transports = opts.transports || ["polling", "websocket", "webtransport"]; |
| 1875 | _this.writeBuffer = []; |
| 1876 | _this.prevBufferLen = 0; |
| 1877 | _this.opts = _extends({ |
| 1878 | path: "/engine.io", |
| 1879 | agent: false, |
| 1880 | withCredentials: false, |
| 1881 | upgrade: true, |
| 1882 | timestampParam: "t", |
| 1883 | rememberUpgrade: false, |
| 1884 | addTrailingSlash: true, |
| 1885 | rejectUnauthorized: true, |
| 1886 | perMessageDeflate: { |
| 1887 | threshold: 1024 |
| 1888 | }, |
| 1889 | transportOptions: {}, |
| 1890 | closeOnBeforeunload: false |
| 1891 | }, opts); |
| 1892 | _this.opts.path = _this.opts.path.replace(/\/$/, "") + (_this.opts.addTrailingSlash ? "/" : ""); |
| 1893 | if (typeof _this.opts.query === "string") { |
| 1894 | _this.opts.query = decode(_this.opts.query); |
| 1895 | } |
| 1896 | // set on handshake |
| 1897 | _this.id = null; |
| 1898 | _this.upgrades = null; |
| 1899 | _this.pingInterval = null; |
| 1900 | _this.pingTimeout = null; |
| 1901 | // set on heartbeat |
| 1902 | _this.pingTimeoutTimer = null; |
| 1903 | if (typeof addEventListener === "function") { |
nothing calls this directly
no test coverage detected