socket_io_adapter

Creator: coderz1093

Last updated:

0 purchases

socket_io_adapter Image
socket_io_adapter Images

Languages

Categories

Add to Cart

Description:

socket io adapter

Getting started #
flutter pub add socket_io_adapter
copied to clipboard
And full installation of socket_io_client via the link #
Usage #
final socket = SocketIOAdapter.initializeOptions(SocketIOOptions(path: 'https://example.com:3000/'));
socket.checkResponse = (data) => data['status']['ok']; // this is method for checking response from server. You can use custom method for checking response
socket.connect();
socket.onAll({
'disconnect': (data) => print('Disconnect'),
'connect': (data) => print('Connect'),
'error': (data) => print('Error'),
'connect_error': (data) => print('Connect Error'),
'your_event': (data) => print('Your Event'),
});
socket.on('connect', (data) => print('Connect 2'));
copied to clipboard
Emit #
socket.emit('sendMessage', {'message' : 'hi'}).then((value) {
this.value = value;
}).catchError((error) {
print('Error: ${error}')
});


copied to clipboard
Interceptor for socket #

class LoggerSocketInterceptor extends SocketInterceptor {
@override
SocketRequest onRequest(SocketRequest request) {
print('On Request: ${[request.data, request.event]}');
return super.onRequest(request);
}

@override
SocketResponse onResponse(SocketResponse response) {
print('On Response: ${response.data}');
return super.onResponse(response);
}

@override
void onError(error) {
print(error);
super.onError(error);
}

@override
dynamic onEvent(event, data) {
print('Event: ${[event, data]}');
super.onEvent(event, data);
}
}

copied to clipboard
print console log #
On Request: [ 'sendMessage', {'message' : 'hi'} ]
On Response: { 'status': { 'ok': true }, 'data': { 'id': 'number', 'message': 'hi' } }
Event: [ 'reveiveMessage', { 'id': 'number', 'message': 'Hi!' } ]
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.