Skip to content

Commit c5fe156

Browse files
committed
fine tune and add the contributor @guilhermecaldas for #16
1 parent e6dc00e commit c5fe156

File tree

7 files changed

+86
-9
lines changed

7 files changed

+86
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
## 0.9.0+3
2-
- Apply Pedantic recommendations
1+
## 0.9.1
2+
3+
**New Feature:**
4+
5+
* [#16](https://github.com/rikulo/socket.io-dart/pull/16) Apply Pedantic recommendations

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@ If you are new to Git or GitHub, please read [this guide](https://help.github.co
8888

8989
## Contributors
9090
* Thanks [@felangel](https://github.com/felangel) for https://github.com/rikulo/socket.io-dart/issues/7
91-
* Thanks [@ThinkDigitalSoftware](https://github.com/ThinkDigitalSoftware) for https://github.com/rikulo/socket.io-dart/pull/15
91+
* Thanks [@ThinkDigitalSoftware](https://github.com/ThinkDigitalSoftware) for https://github.com/rikulo/socket.io-dart/pull/15
92+
* Thanks [@guilhermecaldas](https://github.com/guilhermecaldas) for https://github.com/rikulo/socket.io-dart/pull/16

example/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# socket.io-dart
2+
3+
Port of awesome JavaScript Node.js library - [Socket.io v2.0.1](https://github.com/socketio/socket.io) - in Dart
4+
5+
## Usage
6+
7+
```dart
8+
import 'package:socket_io/socket_io.dart';
9+
10+
main() {
11+
var io = new Server();
12+
var nsp = io.of('/some');
13+
nsp.on('connection', (client) {
14+
print('connection /some');
15+
client.on('msg', (data) {
16+
print('data from /some => $data');
17+
client.emit('fromServer', "ok 2");
18+
});
19+
});
20+
io.on('connection', (client) {
21+
print('connection default namespace');
22+
client.on('msg', (data) {
23+
print('data from default => $data');
24+
client.emit('fromServer', "ok");
25+
});
26+
});
27+
io.listen(3000);
28+
}
29+
```
30+
31+
```js
32+
// JS client
33+
var socket = io('http://localhost:3000');
34+
socket.on('connect', function(){console.log('connect')});
35+
socket.on('event', function(data){console.log(data)});
36+
socket.on('disconnect', function(){console.log('disconnect')});
37+
socket.on('fromServer', function(e){console.log(e)});
38+
```
39+
40+
```dart
41+
// Dart client
42+
import 'package:socket_io_client/socket_io_client.dart' as IO;
43+
44+
IO.Socket socket = IO.io('http://localhost:3000');
45+
socket.on('connect', (_) {
46+
print('connect');
47+
socket.emit('msg', 'test');
48+
});
49+
socket.on('event', (data) => print(data));
50+
socket.on('disconnect', (_) => print('disconnect'));
51+
socket.on('fromServer', (_) => print(_));
52+
```
53+
54+
## Multiplexing support
55+
56+
Same as Socket.IO, this project allows you to create several Namespaces, which will act as separate communication channels but will share the same underlying connection.
57+
58+
## Room support
59+
60+
Within each Namespace, you can define arbitrary channels, called Rooms, that sockets can join and leave. You can then broadcast to any given room, reaching every socket that has joined it.
61+
62+
## Transports support
63+
Refers to [engine.io](https://github.com/socketio/engine.io)
64+
65+
- `polling`: XHR / JSONP polling transport.
66+
- `websocket`: WebSocket transport.
67+
68+
## Adapters support
69+
70+
* Default socket.io in-memory adapter class. Refers to [socket.io-adapter](https://github.com/socketio/socket.io-adapter)

lib/src/engine/server.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class Server extends Engine {
287287
}
288288
var socket = Socket(id, this, transport, connect);
289289

290-
if (false != cookie) {
290+
if (cookie?.isNotEmpty == true) {
291291
transport.on('headers', (headers) {
292292
headers['Set-Cookie'] = '${cookie}=${Uri.encodeComponent(id)}' +
293293
(cookiePath?.isNotEmpty == true ? '; Path=${cookiePath}' : '') +
@@ -373,6 +373,7 @@ class Server extends Engine {
373373
var req = connect.request;
374374
var transport = Transports.newInstance(
375375
req.uri.queryParameters['transport'], connect);
376+
// ignore: unrelated_type_equality_checks
376377
if (req.uri.queryParameters['b64'] == true) {
377378
transport.supportsBinary = false;
378379
} else {

lib/src/engine/transport/polling_transport.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class PollingTransport extends Transport {
189189
}
190190

191191
self.onPacket(packet);
192+
return true;
192193
};
193194

194195
PacketParser.decodePayload(data, callback: callback);

lib/src/namespace.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Namespace extends EventEmitter {
7979
}
8080

8181
//TODO: Figure out return type for this method
82-
static run0(int index, List<Function> fns, Socket socket, Function fn) {
82+
static Object run0(int index, List<Function> fns, Socket socket, Function fn) {
8383
return fns[index](socket, (err) {
8484
// upon error, short-circuit
8585
if (err) return fn(err);
@@ -88,7 +88,7 @@ class Namespace extends EventEmitter {
8888
if (fns.length <= index + 1) return fn(null);
8989

9090
// go on to next
91-
run0(index + 1, fns, socket, fn);
91+
return run0(index + 1, fns, socket, fn);
9292
});
9393
}
9494

@@ -169,7 +169,7 @@ class Namespace extends EventEmitter {
169169
// @todo check how to handle it with Dart
170170
// if (hasBin(args)) { parserType = ParserType.binaryEvent; } // binary
171171

172-
var data = arg == null ? [ev] : [ev, arg];
172+
// ignore: omit_local_variable_types
173173
List data = argument == null ? [event] : [event, argument];
174174

175175
final packet = {'type': EVENT, 'data': data};
@@ -201,6 +201,7 @@ class Namespace extends EventEmitter {
201201
///
202202
/// TODO: Fix this description or code. Add type parameters to [fn([_])]
203203
///
204+
// ignore: use_function_type_syntax_for_parameters
204205
Namespace clients(fn([_])) {
205206
adapter.clients(rooms, fn);
206207
rooms = [];

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: socket_io
22
description: >
33
Port of JS/Node library Socket.io. It enables real-time, bidirectional and
44
event-based communication cross-platform.
5-
version: 0.9.1+1
6-
# author: jumperchen <jumperchen@potix.com>
5+
version: 0.9.1
6+
author: jumperchen <jumperchen@potix.com>
77
homepage: https://www.zkoss.org
88
repository: https://github.com/rikulo/socket.io-dart
99
issue_tracker: https://github.com/rikulo/socket.io-dart/issues

0 commit comments

Comments
 (0)