Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add socket.io ack support #35

Merged
merged 3 commits into from
Aug 4, 2019
Merged

Add socket.io ack support #35

merged 3 commits into from
Aug 4, 2019

Conversation

vornado22
Copy link

Add callback support upon server ack after emit:

socket.emitWithAck("message", ["Hello world!"]).then( (data) {
  // this callback runs when this specific message is acknowledged by the server
  print(data);
});

When ACK is requested, a Future is returned, which will be completed once the
server acknowledges the request. Note that there is no guarantee that the server
will ever acknowledge the request, and the current implementation does not provide
any timeout or garbage collection mechanism.

Brian Scott added 3 commits June 22, 2019 10:00
socket.emitWithAck("message", ["Hello world!"]).then( (data) {
  // this callback runs when this specific message is acknowledged by the server
  print(data);
});

When ACK is requested, a Future is returned, which will be completed once the
server acknowledges the request. Note that there is no guarantee that the server
will ever acknowledge the request, and the current implementation does not provide
any timeout or garbage collection mechanism.
arguments = arguments.where((_) {
//TODO this works around difference in ios (doesn't eat nulls) and android (eats nulls)
return _ != null;
}).toList().map((_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This toList can be skipped as .map is applicable on an Iterable

@@ -98,6 +129,18 @@ class SocketIO {
'arguments': arguments,
});
}
///send data to socket server, return expected Ack as a Future
emitWithAck(String eventName, List<dynamic> arguments) async {
Copy link
Contributor

@tiholic tiholic Jul 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A return type in method signature would be good as it is returning!

Copy link
Contributor

@tiholic tiholic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vornado22 an example to test in example/socket.io.server/index.js would be great!

@tiholic
Copy link
Contributor

tiholic commented Jul 13, 2019

#10 #37

@tiholic tiholic merged commit 0af6edd into infitio:master Aug 4, 2019
@Vardiak
Copy link
Contributor

Vardiak commented Aug 8, 2019

I'm having this error when trying to run it on branch master, and it might be related with the pull request :

Launching lib/main.dart on Nokia 7 plus in debug mode...
/Users/***/Documents/flutter/.pub-cache/git/flutter_socket_io-d66994666f8c947e9c264393c5c521d9488088e9/android/src/main/java/com/infitio/adharasocketio/AdharaSocket.java:137: error: cannot find symbol
                    socket.emit(eventName, array, new Ack() {
                                                      ^
  symbol:   class Ack
  location: class AdharaSocket
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':adhara_socket_io:compileDebugJavaWithJavac'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants