This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
forked from rikulo/socket.io-client-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebase
- Loading branch information
Showing
27 changed files
with
2,070 additions
and
1,522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ doc/api/ | |
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
*/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## 0.9.9 | ||
|
||
**Bug fix:** | ||
|
||
* [#67](https://github.com/rikulo/socket.io-client-dart/issues/67) Retry connection backoff after 54 tries reconnections every 0 second | ||
|
||
## 0.9.8 | ||
|
||
**Bug fix:** | ||
|
||
* [#33](https://github.com/rikulo/socket.io-client-dart/issues/33) socket.on('receiveMessage',(data)=>print("data")) called twice | ||
|
||
|
||
## 0.9.7+2 | ||
|
||
**New Feature:** | ||
|
||
* [#48](https://github.com/rikulo/socket.io-client-dart/issues/48) add links to github repo in pubspec.yaml | ||
|
||
|
||
## 0.9.7+1 | ||
|
||
**New Feature:** | ||
|
||
* [#38](https://github.com/rikulo/socket.io-client-dart/issues/38) Improve pub.dev score | ||
|
||
|
||
## 0.9.6+3 | ||
|
||
**Bug fix:** | ||
|
||
* [#42](https://github.com/rikulo/socket.io-client-dart/issues/42) Error when using emitWithAck | ||
|
||
## 0.9.5 | ||
|
||
**New Feature:** | ||
|
||
* [#34](https://github.com/rikulo/socket.io-client-dart/issues/34) Add support for extraHeaders | ||
|
||
**Bug fix:** | ||
|
||
* [#39](https://github.com/rikulo/socket.io-client-dart/issues/39) The factor of Backoff with 54 retries causes an overflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# socket.io-client-dart example | ||
|
||
Port of awesome JavaScript Node.js library - [Socket.io-client v2.0.1](https://github.com/socketio/socket.io-client) - in Dart | ||
|
||
## Usage | ||
|
||
|
||
import 'package:socket_io/socket_io.dart'; | ||
import 'package:socket_io_client/socket_io_client.dart' as IO; | ||
|
||
main() { | ||
// Dart server | ||
var io = new Server(); | ||
var nsp = io.of('/some'); | ||
nsp.on('connection', (Socket client) { | ||
print('connection /some'); | ||
client.on('msg', (data) { | ||
print('data from /some => $data'); | ||
client.emit('fromServer', "ok 2"); | ||
}); | ||
}); | ||
io.on('connection', (Socket client) { | ||
print('connection default namespace'); | ||
client.on('msg', (data) { | ||
print('data from default => $data'); | ||
client.emit('fromServer', "ok"); | ||
}); | ||
}); | ||
io.listen(3000); | ||
|
||
// Dart client | ||
IO.Socket socket = IO.io('http://localhost:3000'); | ||
socket.on('connect', (_) { | ||
print('connect'); | ||
socket.emit('msg', 'test'); | ||
}); | ||
socket.on('event', (data) => print(data)); | ||
socket.on('disconnect', (_) => print('disconnect')); | ||
socket.on('fromServer', (_) => print(_)); | ||
} | ||
|
||
|
||
|
||
### Connect manually | ||
To connect the socket manually, set the option `autoConnect: false` and call `.connect()`. | ||
|
||
For example, | ||
<pre> | ||
Socket socket = io('http://localhost:3000', <String, dynamic>{ | ||
'transports': ['websocket'], | ||
<b>'autoConnect': false</b>, | ||
'extraHeaders': {'foo': 'bar'} // optional | ||
}); | ||
<b>socket.connect();</b> | ||
</pre> | ||
|
||
Note that `.connect()` should not be called if `autoConnect: true`, as this will cause all event handlers to get registered/fired twice. See [Issue #33](https://github.com/rikulo/socket.io-client-dart/issues/33). | ||
|
||
### Update the extra headers | ||
``` | ||
Socket socket = ... // Create socket. | ||
socket.io.options['extraHeaders'] = {'foo': 'bar'}; // Update the extra headers. | ||
socket.io..disconnect()..connect(); // Reconnect the socket manually. | ||
``` | ||
|
||
### Emit with acknowledgement | ||
``` | ||
Socket socket = ... // Create socket. | ||
socket.on('connect', (_) { | ||
print('connect'); | ||
socket.emitWithAck('msg', 'init', ack: (data) { | ||
print('ack $data') ; | ||
if (data != null) { | ||
print('from server $data'); | ||
} else { | ||
print("Null") ; | ||
} | ||
}); | ||
}); | ||
``` | ||
|
||
### Socket connection events | ||
These events can be listened on. | ||
``` | ||
const List EVENTS = [ | ||
'connect', | ||
'connect_error', | ||
'connect_timeout', | ||
'connecting', | ||
'disconnect', | ||
'error', | ||
'reconnect', | ||
'reconnect_attempt', | ||
'reconnect_failed', | ||
'reconnect_error', | ||
'reconnecting', | ||
'ping', | ||
'pong' | ||
]; | ||
// Replace 'connect' with any of the above events. | ||
socket.on('connect', (_) { | ||
print('connect'); | ||
} | ||
``` | ||
|
||
### Acknowledge with the socket server that an event has been received. | ||
``` | ||
socket.on('eventName', (data) { | ||
final dataList = data as List; | ||
final ack = dataList.last as Function; | ||
ack(null); | ||
}); | ||
``` | ||
|
||
## Usage (Flutter) | ||
In Flutter env. it only works with `dart:io` websocket, not with `dart:html` websocket, so in this case | ||
you have to add `'transports': ['websocket']` when creates the socket instance. | ||
|
||
For example, | ||
``` | ||
IO.Socket socket = IO.io('http://localhost:3000', <String, dynamic>{ | ||
'transports': ['websocket'], | ||
'extraHeaders': {'foo': 'bar'} // optional | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.