You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -145,3 +145,4 @@ If you are new to Git or GitHub, please read [this guide](https://help.github.co
145
145
* Thanks [@Oskang09](https://github.com/Oskang09) for https://github.com/rikulo/socket.io-client-dart/issues/21
146
146
* Thanks [@bruce3x](https://github.com/bruce3x) for https://github.com/rikulo/socket.io-client-dart/issues/25
147
147
* Thanks [@Kavantix](https://github.com/Kavantix) for https://github.com/rikulo/socket.io-client-dart/issues/26
148
+
* Thanks [@luandnguyen](https://github.com/luandnguyen) for https://github.com/rikulo/socket.io-client-dart/issues/59
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).
58
+
59
+
### Update the extra headers
60
+
```
61
+
Socket socket = ... // Create socket.
62
+
socket.io.options['extraHeaders'] = {'foo': 'bar'}; // Update the extra headers.
63
+
socket.io..disconnect()..connect(); // Reconnect the socket manually.
64
+
```
65
+
66
+
### Emit with acknowledgement
67
+
```
68
+
Socket socket = ... // Create socket.
69
+
socket.on('connect', (_) {
70
+
print('connect');
71
+
socket.emitWithAck('msg', 'init', ack: (data) {
72
+
print('ack $data') ;
73
+
if (data != null) {
74
+
print('from server $data');
75
+
} else {
76
+
print("Null") ;
77
+
}
78
+
});
79
+
});
80
+
```
81
+
82
+
### Socket connection events
83
+
These events can be listened on.
84
+
```
85
+
const List EVENTS = [
86
+
'connect',
87
+
'connect_error',
88
+
'connect_timeout',
89
+
'connecting',
90
+
'disconnect',
91
+
'error',
92
+
'reconnect',
93
+
'reconnect_attempt',
94
+
'reconnect_failed',
95
+
'reconnect_error',
96
+
'reconnecting',
97
+
'ping',
98
+
'pong'
99
+
];
100
+
101
+
// Replace 'connect' with any of the above events.
102
+
socket.on('connect', (_) {
103
+
print('connect');
104
+
}
105
+
```
106
+
107
+
### Acknowledge with the socket server that an event has been received.
108
+
```
109
+
socket.on('eventName', (data) {
110
+
final dataList = data as List;
111
+
final ack = dataList.last as Function;
112
+
ack(null);
113
+
});
114
+
```
115
+
42
116
## Usage (Flutter)
43
117
In Flutter env. it only works with `dart:io` websocket, not with `dart:html` websocket, so in this case
44
118
you have to add `'transports': ['websocket']` when creates the socket instance.
0 commit comments