@@ -15,14 +15,14 @@ import 'package:socket_io/src/util/event_emitter.dart';
15
15
16
16
abstract class Adapter {
17
17
Map nsps = {};
18
- Map <String , _Room > rooms;
19
- Map <String , Map > sids;
18
+ Map <String , _Room > rooms = {} ;
19
+ Map <String , Map > sids = {} ;
20
20
21
21
void add (String id, String room, [dynamic Function ([dynamic ]) fn]);
22
22
void del (String id, String room, [dynamic Function ([dynamic ]) fn]);
23
23
void delAll (String id, [dynamic Function ([dynamic ]) fn]);
24
24
void broadcast (Map packet, [Map opts]);
25
- void clients (List rooms, [ dynamic Function ([dynamic ]) fn]);
25
+ void clients ([ List < String > rooms, dynamic Function ([dynamic ]) fn]);
26
26
void clientRooms (String id, [dynamic Function (dynamic , [dynamic ]) fn]);
27
27
28
28
static Adapter newInstance (String key, Namespace nsp) {
@@ -37,15 +37,15 @@ class _MemoryStoreAdapter extends EventEmitter implements Adapter {
37
37
@override
38
38
Map nsps = {};
39
39
@override
40
- Map <String , _Room > rooms;
40
+ Map <String , _Room > rooms = {};
41
+
41
42
@override
42
- Map <String , Map > sids;
43
- Encoder encoder;
44
- Namespace nsp;
45
- _MemoryStoreAdapter (nsp) {
43
+ Map <String , Map > sids = {};
44
+ late Encoder encoder;
45
+ late Namespace nsp;
46
+
47
+ _MemoryStoreAdapter (Namespace nsp) {
46
48
this .nsp = nsp;
47
- rooms = {};
48
- sids = {};
49
49
encoder = nsp.server.encoder;
50
50
}
51
51
@@ -57,11 +57,11 @@ class _MemoryStoreAdapter extends EventEmitter implements Adapter {
57
57
/// @api public
58
58
59
59
@override
60
- void add (String id, String room, [dynamic Function ([dynamic ]) fn]) {
60
+ void add (String id, String room, [dynamic Function ([dynamic ])? fn]) {
61
61
sids[id] = sids[id] ?? {};
62
- sids[id][room] = true ;
62
+ sids[id]! [room] = true ;
63
63
rooms[room] = rooms[room] ?? _Room ();
64
- rooms[room].add (id);
64
+ rooms[room]! .add (id);
65
65
if (fn != null ) scheduleMicrotask (() => fn (null ));
66
66
}
67
67
@@ -72,12 +72,12 @@ class _MemoryStoreAdapter extends EventEmitter implements Adapter {
72
72
/// @param {Function} callback
73
73
/// @api public
74
74
@override
75
- void del (String id, String room, [dynamic Function ([dynamic ]) fn]) {
75
+ void del (String id, String room, [dynamic Function ([dynamic ])? fn]) {
76
76
sids[id] = sids[id] ?? {};
77
- sids[id].remove (room);
77
+ sids[id]! .remove (room);
78
78
if (rooms.containsKey (room)) {
79
- rooms[room].del (id);
80
- if (rooms[room].length == 0 ) rooms.remove (room);
79
+ rooms[room]! .del (id);
80
+ if (rooms[room]! .length == 0 ) rooms.remove (room);
81
81
}
82
82
83
83
if (fn != null ) scheduleMicrotask (() => fn (null ));
@@ -89,13 +89,13 @@ class _MemoryStoreAdapter extends EventEmitter implements Adapter {
89
89
/// @param {Function} callback
90
90
/// @api public
91
91
@override
92
- void delAll (String id, [dynamic Function ([dynamic ]) fn]) {
92
+ void delAll (String id, [dynamic Function ([dynamic ])? fn]) {
93
93
var rooms = sids[id];
94
94
if (rooms != null ) {
95
95
for (var room in rooms.keys) {
96
96
if (this .rooms.containsKey (room)) {
97
- this .rooms[room].del (id);
98
- if (this .rooms[room].length == 0 ) this .rooms.remove (room);
97
+ this .rooms[room]! .del (id);
98
+ if (this .rooms[room]! .length == 0 ) this .rooms.remove (room);
99
99
}
100
100
}
101
101
}
@@ -114,7 +114,7 @@ class _MemoryStoreAdapter extends EventEmitter implements Adapter {
114
114
/// @param {Object} packet object
115
115
/// @api public
116
116
@override
117
- void broadcast (Map packet, [Map opts]) {
117
+ void broadcast (Map packet, [Map ? opts]) {
118
118
opts = opts ?? {};
119
119
List rooms = opts['rooms' ] ?? [];
120
120
List except = opts['except' ] ?? [];
@@ -161,9 +161,8 @@ class _MemoryStoreAdapter extends EventEmitter implements Adapter {
161
161
/// @param {Function} callback
162
162
/// @api public
163
163
@override
164
- void clients (List rooms, [dynamic Function ([dynamic ]) fn]) {
165
- rooms = rooms ?? [];
166
-
164
+ void clients (
165
+ [List <String > rooms = const [], dynamic Function ([dynamic ])? fn]) {
167
166
var ids = {};
168
167
var sids = [];
169
168
var socket;
@@ -200,7 +199,7 @@ class _MemoryStoreAdapter extends EventEmitter implements Adapter {
200
199
/// @param {Function} callback
201
200
/// @api public
202
201
@override
203
- void clientRooms (String id, [dynamic Function (dynamic , [dynamic ]) fn]) {
202
+ void clientRooms (String id, [dynamic Function (dynamic , [dynamic ])? fn]) {
204
203
var rooms = sids[id];
205
204
if (fn != null ) scheduleMicrotask (() => fn (null , rooms? .keys));
206
205
}
@@ -210,12 +209,8 @@ class _MemoryStoreAdapter extends EventEmitter implements Adapter {
210
209
///
211
210
/// @api private
212
211
class _Room {
213
- Map <String , bool > sockets;
214
- int length;
215
- _Room () {
216
- sockets = {};
217
- length = 0 ;
218
- }
212
+ Map <String , bool > sockets = {};
213
+ int length = 0 ;
219
214
220
215
/// Adds a socket to a room.
221
216
///
0 commit comments