diff --git a/analysis_options.yaml b/analysis_options.yaml index 3d63a9f..5df03dc 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -11,8 +11,7 @@ linter: cancel_subscriptions: true close_sinks: true hash_and_equals: true - iterable_contains_unrelated_type: true - list_remove_unrelated_type: true + collection_methods_unrelated_type: true test_types_in_equals: true unrelated_type_equality_checks: true valid_regexps: true diff --git a/lib/src/engine/socket.dart b/lib/src/engine/socket.dart index a9af997..34f83cd 100644 --- a/lib/src/engine/socket.dart +++ b/lib/src/engine/socket.dart @@ -53,11 +53,11 @@ class Socket extends EventEmitter { opts = opts ?? {}; if (uri.isNotEmpty) { - var _uri = Uri.parse(uri); - opts['hostname'] = _uri.host; - opts['secure'] = _uri.scheme == 'https' || _uri.scheme == 'wss'; - opts['port'] = _uri.port; - if (_uri.hasQuery) opts['query'] = _uri.query; + var uri0 = Uri.parse(uri); + opts['hostname'] = uri0.host; + opts['secure'] = uri0.scheme == 'https' || uri0.scheme == 'wss'; + opts['port'] = uri0.port; + if (uri0.hasQuery) opts['query'] = uri0.query; } else if (opts.containsKey('host')) { opts['hostname'] = Uri.parse(opts['host']).host; } @@ -101,7 +101,7 @@ class Socket extends EventEmitter { this.opts['path'] = - this.opts['path'].toString().replaceFirst(RegExp(r'\/$'), '') + + this.opts['path'].toString().replaceFirst(RegExp(r'/$'), '') + (this.opts['addTrailingSlash'] ? '/' : ''); if (opts['query'] is String) { @@ -155,9 +155,9 @@ class Socket extends EventEmitter { ...this.opts, 'query': query, 'socket': this, - 'hostname': this.hostname, - 'secure': this.secure, - 'port': this.port, + 'hostname': hostname, + 'secure': secure, + 'port': port, ...transportOptions, }; @@ -170,7 +170,7 @@ class Socket extends EventEmitter { /// @api private void open() { dynamic transport; - if (this.opts['rememberUpgrade'] != null && + if (opts['rememberUpgrade'] != null && priorWebsocketSuccess && transports.contains('websocket')) { transport = 'websocket'; @@ -325,7 +325,7 @@ class Socket extends EventEmitter { once('close', onclose); once('upgrading', onupgrade); - if (this.upgrades!.indexOf('webtransport') != -1 && name != 'webtransport') { + if (upgrades!.contains('webtransport') && name != 'webtransport') { // favor WebTransport Timer(Duration(milliseconds: 200), () { if (!failed) { @@ -351,7 +351,7 @@ class Socket extends EventEmitter { // we check for `readyState` in case an `open` // listener already closed the socket if ('open' == readyState && - this.opts['upgrade'] == true && + opts['upgrade'] == true && transport?.name == 'polling') { _logger.fine('starting upgrade probes'); for (var i = 0, l = upgrades!.length; i < l; i++) { diff --git a/lib/src/engine/transport.dart b/lib/src/engine/transport.dart index 627417e..1652d5b 100644 --- a/lib/src/engine/transport.dart +++ b/lib/src/engine/transport.dart @@ -1,6 +1,6 @@ -/// Copyright (C) 2019 Potix Corporation. All Rights Reserved -/// History: 2019-01-21 12:27 -/// Author: jumperchen +// Copyright (C) 2019 Potix Corporation. All Rights Reserved +// History: 2019-01-21 12:27 +// Author: jumperchen import 'dart:convert'; import 'package:logging/logging.dart'; @@ -19,8 +19,7 @@ abstract class Transport extends EventEmitter { String? readyState; Socket? socket; - Transport(Map opts) { - this.opts = opts; + Transport(this.opts) { query = opts['query']; readyState = ''; socket = opts['socket']; @@ -105,7 +104,7 @@ abstract class Transport extends EventEmitter { } get name; - void pause(onPause()) {} + void pause(Function() onPause) {} String createUri(String schema, Map query) { return '$schema://${_hostname()}${_port()}${opts["path"]}${_query(query)}'; diff --git a/lib/src/engine/transport/io_websocket_transport.dart b/lib/src/engine/transport/io_websocket_transport.dart index 4590c32..c2735cc 100644 --- a/lib/src/engine/transport/io_websocket_transport.dart +++ b/lib/src/engine/transport/io_websocket_transport.dart @@ -120,10 +120,10 @@ class IOWebSocketTransport extends Transport { /// @api private String uri() { var query = this.query ?? {}; - var schema = this.opts['secure'] ? 'wss' : 'ws'; + var schema = opts['secure'] ? 'wss' : 'ws'; // append timestamp to URI - if (this.opts['timestampRequests'] == true) { - query[this.opts['timestampRequests']] = + if (opts['timestampRequests'] == true) { + query[opts['timestampRequests']] = DateTime.now().millisecondsSinceEpoch.toRadixString(36); } diff --git a/lib/src/engine/transport/polling_transport.dart b/lib/src/engine/transport/polling_transport.dart index 85de5bd..aad9970 100644 --- a/lib/src/engine/transport/polling_transport.dart +++ b/lib/src/engine/transport/polling_transport.dart @@ -1,14 +1,14 @@ -/// -/// polling_transport.dart -/// -/// Purpose: -/// -/// Description: -/// -/// History: -/// 26/04/2017, Created by jumperchen -/// -/// Copyright (C) 2017 Potix Corporation. All Rights Reserved. +// +// polling_transport.dart +// +// Purpose: +// +// Description: +// +// History: +// 26/04/2017, Created by jumperchen +// +// Copyright (C) 2017 Potix Corporation. All Rights Reserved. import 'dart:async'; import 'dart:html'; @@ -39,8 +39,8 @@ class PollingTransport extends Transport { String? name = 'polling'; bool polling = false; - dynamic? pollXhr; - dynamic? cookieJar; + dynamic pollXhr; + dynamic cookieJar; late bool xd; /// @@ -83,6 +83,7 @@ class PollingTransport extends Transport { /// /// @param {Function} callback upon buffers are flushed and transport is paused /// @api private + @override void pause(onPause) { var self = this; @@ -222,11 +223,11 @@ class PollingTransport extends Transport { /// @api private String uri() { final query = this.query ?? {}; - var schema = this.opts['secure'] ? 'https' : 'http'; + var schema = opts['secure'] ? 'https' : 'http'; // cache busting is forced - if (this.opts['timestampRequests'] != null) { - query[this.opts['timestampRequests']] = + if (opts['timestampRequests'] != null) { + query[opts['timestampRequests']] = DateTime.now().millisecondsSinceEpoch.toRadixString(36); } @@ -241,11 +242,11 @@ class PollingTransport extends Transport { opts = opts ?? {}; final mergedOpts = { ...opts, - xd: this.xd, - cookieJar: this.cookieJar, + xd: xd, + cookieJar: cookieJar, ...this.opts }; - return Request(this.uri(), mergedOpts); + return Request(uri(), mergedOpts); } /// /// Sends data. @@ -253,7 +254,6 @@ class PollingTransport extends Transport { /// @param {String} data to send. /// @param {Function} called upon flush. /// @api private - @override void doWrite(data, fn) { var isBinary = data is! String; var req = request({'method': 'POST', 'data': data, 'isBinary': isBinary}); @@ -267,7 +267,6 @@ class PollingTransport extends Transport { /// Starts a poll cycle. /// /// @api private - @override void doPoll() { _logger.fine('xhr poll'); var req = request(); @@ -290,11 +289,9 @@ class Request extends EventEmitter { int? index; StreamSubscription? readyStateChange; - Request(uri, Map opts) { - this.opts = opts; - this.method = opts['method'] ?? 'GET'; - this.uri = uri; - this.data = opts['data']; + Request(this.uri, this.opts) { + method = opts['method'] ?? 'GET'; + data = opts['data']; create(); } diff --git a/lib/src/engine/transport/transports.dart b/lib/src/engine/transport/transports.dart index d98f925..c602383 100644 --- a/lib/src/engine/transport/transports.dart +++ b/lib/src/engine/transport/transports.dart @@ -1,6 +1,6 @@ -/// Copyright (C) 2017 Potix Corporation. All Rights Reserved -/// History: 2017-04-26 12:27 -/// Author: jumperchen +// Copyright (C) 2017 Potix Corporation. All Rights Reserved +// History: 2017-04-26 12:27 +// Author: jumperchen import 'package:socket_io_client/src/engine/transport.dart'; import 'package:socket_io_client/src/engine/transport/polling_transport.dart'; import 'package:socket_io_client/src/engine/transport/websocket_transport.dart'; diff --git a/lib/src/engine/transport/websocket_transport.dart b/lib/src/engine/transport/websocket_transport.dart index bf81736..4f7ff0d 100644 --- a/lib/src/engine/transport/websocket_transport.dart +++ b/lib/src/engine/transport/websocket_transport.dart @@ -7,7 +7,6 @@ import 'dart:html'; import 'package:logging/logging.dart'; import 'package:socket_io_client/src/engine/transport.dart'; import 'package:socket_io_common/src/engine/parser/parser.dart'; -import 'package:socket_io_client/src/engine/parseqs.dart'; class WebSocketTransport extends Transport { static final Logger _logger = @@ -25,9 +24,9 @@ class WebSocketTransport extends Transport { @override void doOpen() { var uri = this.uri(); - var protocols = this.opts['protocols']; - if (this.opts.containsKey('extraHeaders')) { - this.opts['headers'] = this.opts['extraHeaders']; + var protocols = opts['protocols']; + if (opts.containsKey('extraHeaders')) { + opts['headers'] = opts['extraHeaders']; } try { @@ -40,7 +39,7 @@ class WebSocketTransport extends Transport { supportsBinary = false; } - ws!.binaryType = this.socket!.binaryType; + ws!.binaryType = socket!.binaryType; addEventListeners(); } @@ -111,10 +110,10 @@ class WebSocketTransport extends Transport { /// @api private String uri() { var query = this.query ?? {}; - var schema = this.opts['secure'] ? 'wss' : 'ws'; + var schema = opts['secure'] ? 'wss' : 'ws'; // append timestamp to URI - if (this.opts['timestampRequests'] == true) { - query[this.opts['timestampRequests']] = + if (opts['timestampRequests'] == true) { + query[opts['timestampRequests']] = DateTime.now().millisecondsSinceEpoch.toRadixString(36); } diff --git a/lib/src/manager.dart b/lib/src/manager.dart index c77207d..eb2f8b8 100644 --- a/lib/src/manager.dart +++ b/lib/src/manager.dart @@ -1,6 +1,6 @@ -/// Copyright (C) 2017 Potix Corporation. All Rights Reserved -/// History: 2017-04-26 15:27 -/// Author: jumperchen +// Copyright (C) 2017 Potix Corporation. All Rights Reserved +// History: 2017-04-26 15:27 +// Author: jumperchen import 'dart:async'; import 'dart:math' as math; @@ -169,7 +169,7 @@ class Manager extends EventEmitter { if (callback != null) callback(); }); - var onError; + Function(dynamic error) onError; // emit `connect_error` var errorSub = util.on(socket, 'error', onError = (error) { _logger.fine('error'); diff --git a/lib/src/socket.dart b/lib/src/socket.dart index ec500f7..0fdc4cf 100644 --- a/lib/src/socket.dart +++ b/lib/src/socket.dart @@ -1,14 +1,14 @@ -/// -/// socket.dart -/// -/// Purpose: -/// -/// Description: -/// -/// History: -/// 26/04/2017, Created by jumperchen -/// -/// Copyright (C) 2017 Potix Corporation. All Rights Reserved. +// +// socket.dart +// +// Purpose: +// +// Description: +// +// History: +// 26/04/2017, Created by jumperchen +// +// Copyright (C) 2017 Potix Corporation. All Rights Reserved. import 'dart:async'; import 'dart:typed_data'; @@ -44,7 +44,7 @@ class Socket extends EventEmitter { dynamic auth; List receiveBuffer = []; List sendBuffer = []; - List _queue = []; + final List _queue = []; int _queueSeq = 0; String nsp; @@ -54,8 +54,8 @@ class Socket extends EventEmitter { List? subs; Map flags = {}; String? query; - List _anyListeners = []; - List _anyOutgoingListeners = []; + final List _anyListeners = []; + final List _anyOutgoingListeners = []; Socket(this.io, this.nsp, this._opts) { if (_opts != null) {