Socket constructor
Implementation
Socket(String uri, Map? initialOpts) {
opts = initialOpts ?? <dynamic, dynamic>{};
if (uri.isNotEmpty) {
this.uri = Uri.parse(uri);
opts['hostname'] = this.uri.host;
opts['secure'] = this.uri.scheme == 'https' || this.uri.scheme == 'wss';
opts['port'] = this.uri.port;
if (this.uri.hasQuery) opts['query'] = this.uri.query;
} else if (opts.containsKey('host')) {
opts['hostname'] = Uri.parse(opts['host']).host;
}
secure = opts['secure'] /*?? (window.location.protocol == 'https:')*/;
if (opts['hostname'] != null && !opts.containsKey('port')) {
// if no port is specified manually, use the protocol default
opts['port'] = secure ? '443' : '80';
}
agent = opts['agent'] ?? false;
hostname =
opts['hostname'] /*?? (window.location.hostname ?? 'localhost')*/;
port = opts[
'port'] /*??
(window.location.port.isNotEmpty
? int.parse(window.location.port)
: (this.secure ? 443 : 80))*/
;
var query = opts['query'] ?? {};
if (query is String) {
this.query = decode(query);
} else if (query is Map) {
this.query = query;
}
upgrade = opts['upgrade'] != false;
path = opts['path'] ?? '/engine.io';
if (path is String) {
path = path
.toString()
.replaceFirst(RegExp(r'\/$'), '') +
'/';
}
forceJSONP = opts['forceJSONP'] == true;
jsonp = opts['jsonp'] != false;
forceBase64 = opts['forceBase64'] == true;
enablesXDR = opts['enablesXDR'] == true;
timestampParam = opts['timestampParam'] ?? 't';
timestampRequests = opts['timestampRequests'];
transports = opts['transports'] ?? ['polling', 'websocket'];
transportOptions = opts['transportOptions'] ?? {};
policyPort = opts['policyPort'] ?? 843;
rememberUpgrade = opts['rememberUpgrade'] ?? false;
binaryType = null;
onlyBinaryUpgrades = opts['onlyBinaryUpgrades'] ?? false;
if (!opts.containsKey('perMessageDeflate') ||
opts['perMessageDeflate'] == true) {
perMessageDeflate =
opts['perMessageDeflate'] is Map ? opts['perMessageDeflate'] : {};
if (!perMessageDeflate.containsKey('threshold')) {
perMessageDeflate['threshold'] = 1024;
}
}
extraHeaders = opts['extraHeaders'] ?? <String, dynamic>{};
// SSL options for Node.js client
// this.pfx = opts.pfx || null;
// this.key = opts.key || null;
// this.passphrase = opts.passphrase || null;
// this.cert = opts.cert || null;
// this.ca = opts.ca || null;
// this.ciphers = opts.ciphers || null;
// this.rejectUnauthorized = opts.rejectUnauthorized === undefined ? true : opts.rejectUnauthorized;
// this.forceNode = !!opts.forceNode;
// other options for Node.js client
// var freeGlobal = typeof global === 'object' && global;
// if (freeGlobal.global === freeGlobal) {
// if (opts.extraHeaders && Object.keys(opts.extraHeaders).length > 0) {
// this.extraHeaders = opts.extraHeaders;
// }
//
// if (opts.localAddress) {
// this.localAddress = opts.localAddress;
// }
// }
// set on handshake
// this.id = null;
// this.upgrades = null;
// this.pingInterval = null;
// this.pingTimeout = null;
// set on heartbeat
// this.pingIntervalTimer = null;
// this.pingTimeoutTimer = null;
open();
}