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

Function SocketWithoutUpgrade

packages/socket.io/client-dist/socket.io.js:1695–1784  ·  view source on GitHub ↗

* Socket constructor. * * @param {String|Object} uri - uri or options * @param {Object} opts - options

(uri, opts)

Source from the content-addressed store, hash-verified

1693 * @param {Object} opts - options
1694 */
1695 function SocketWithoutUpgrade(uri, opts) {
1696 var _this;
1697 _this = _Emitter.call(this) || this;
1698 _this.binaryType = defaultBinaryType;
1699 _this.writeBuffer = [];
1700 _this._prevBufferLen = 0;
1701 _this._pingInterval = -1;
1702 _this._pingTimeout = -1;
1703 _this._maxPayload = -1;
1704 /**
1705 * The expiration timestamp of the {@link _pingTimeoutTimer} object is tracked, in case the timer is throttled and the
1706 * callback is not fired on time. This can happen for example when a laptop is suspended or when a phone is locked.
1707 */
1708 _this._pingTimeoutTime = Infinity;
1709 if (uri && "object" === _typeof(uri)) {
1710 opts = uri;
1711 uri = null;
1712 }
1713 if (uri) {
1714 var parsedUri = parse(uri);
1715 opts.hostname = parsedUri.host;
1716 opts.secure = parsedUri.protocol === "https" || parsedUri.protocol === "wss";
1717 opts.port = parsedUri.port;
1718 if (parsedUri.query) opts.query = parsedUri.query;
1719 } else if (opts.host) {
1720 opts.hostname = parse(opts.host).host;
1721 }
1722 installTimerFunctions(_this, opts);
1723 _this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol;
1724 if (opts.hostname && !opts.port) {
1725 // if no port is specified manually, use the protocol default
1726 opts.port = _this.secure ? "443" : "80";
1727 }
1728 _this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
1729 _this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : _this.secure ? "443" : "80");
1730 _this.transports = [];
1731 _this._transportsByName = {};
1732 opts.transports.forEach(function (t) {
1733 var transportName = t.prototype.name;
1734 _this.transports.push(transportName);
1735 _this._transportsByName[transportName] = t;
1736 });
1737 _this.opts = _extends({
1738 path: "/engine.io",
1739 agent: false,
1740 withCredentials: false,
1741 upgrade: true,
1742 timestampParam: "t",
1743 rememberUpgrade: false,
1744 addTrailingSlash: true,
1745 rejectUnauthorized: true,
1746 perMessageDeflate: {
1747 threshold: 1024
1748 },
1749 transportOptions: {},
1750 closeOnBeforeunload: false
1751 }, opts);
1752 _this.opts.path = _this.opts.path.replace(/\/$/, "") + (_this.opts.addTrailingSlash ? "/" : "");

Callers

nothing calls this directly

Calls 9

_typeofFunction · 0.85
_extendsFunction · 0.85
_onCloseMethod · 0.80
_openMethod · 0.80
parseFunction · 0.70
installTimerFunctionsFunction · 0.70
decodeFunction · 0.70
createCookieJarFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected