Skip to content

Commit

Permalink
Fixed pub points improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
jumperchen committed Feb 16, 2024
1 parent b53525a commit fb9a9e4
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 78 deletions.
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions lib/src/engine/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class Socket extends EventEmitter {
opts = opts ?? <dynamic, dynamic>{};

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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
};

Expand All @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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++) {
Expand Down
11 changes: 5 additions & 6 deletions lib/src/engine/transport.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Copyright (C) 2019 Potix Corporation. All Rights Reserved
/// History: 2019-01-21 12:27
/// Author: jumperchen<[email protected]>
// Copyright (C) 2019 Potix Corporation. All Rights Reserved
// History: 2019-01-21 12:27
// Author: jumperchen<[email protected]>
import 'dart:convert';

import 'package:logging/logging.dart';
Expand All @@ -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'];
Expand Down Expand Up @@ -105,7 +104,7 @@ abstract class Transport extends EventEmitter {
}
get name;

void pause(onPause()) {}
void pause(Function() onPause) {}

String createUri(String schema, Map<String, dynamic> query) {
return '$schema://${_hostname()}${_port()}${opts["path"]}${_query(query)}';
Expand Down
6 changes: 3 additions & 3 deletions lib/src/engine/transport/io_websocket_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
49 changes: 23 additions & 26 deletions lib/src/engine/transport/polling_transport.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;

///
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand All @@ -241,19 +242,18 @@ 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.
///
/// @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});
Expand All @@ -267,7 +267,6 @@ class PollingTransport extends Transport {
/// Starts a poll cycle.
///
/// @api private
@override
void doPoll() {
_logger.fine('xhr poll');
var req = request();
Expand All @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/engine/transport/transports.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Copyright (C) 2017 Potix Corporation. All Rights Reserved
/// History: 2017-04-26 12:27
/// Author: jumperchen<[email protected]>
// Copyright (C) 2017 Potix Corporation. All Rights Reserved
// History: 2017-04-26 12:27
// Author: jumperchen<[email protected]>
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';
Expand Down
15 changes: 7 additions & 8 deletions lib/src/engine/transport/websocket_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 {
Expand All @@ -40,7 +39,7 @@ class WebSocketTransport extends Transport {
supportsBinary = false;
}

ws!.binaryType = this.socket!.binaryType;
ws!.binaryType = socket!.binaryType;

addEventListeners();
}
Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/manager.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Copyright (C) 2017 Potix Corporation. All Rights Reserved
/// History: 2017-04-26 15:27
/// Author: jumperchen<[email protected]>
// Copyright (C) 2017 Potix Corporation. All Rights Reserved
// History: 2017-04-26 15:27
// Author: jumperchen<[email protected]>
import 'dart:async';
import 'dart:math' as math;

Expand Down Expand Up @@ -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');
Expand Down
28 changes: 14 additions & 14 deletions lib/src/socket.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -44,7 +44,7 @@ class Socket extends EventEmitter {
dynamic auth;
List receiveBuffer = [];
List sendBuffer = [];
List _queue = [];
final List _queue = [];
int _queueSeq = 0;

String nsp;
Expand All @@ -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) {
Expand Down

0 comments on commit fb9a9e4

Please sign in to comment.