Closed ramsestom closed 4 years ago
OK found the origin of the issue.
the socket.onack()
method is using the Function.apply
method. But when this method is passed a List , each element of this List is considered an argument of this function (https://api.dartlang.org/stable/2.6.1/dart-core/Function/apply.html). So if the object returned by the ack is a List=a json array (which was my case), the callback do not behave as expected
To fix this bug, line 323 of the socket.dart file needs to be changed to:
Function.apply(ack, [packet['data']]);
so that even if the result of the ack is a List, it would be treated as a unique single object to be passed as argument to the ack callback.
Bytheway, The emitBuffered function is bugged also. It should be:
emitBuffered() {
var i;
for (i = 0; i < this.receiveBuffer.length; i++) {
List args = this.receiveBuffer[i];
if (args.length > 2) {
Function.apply(super.emit, [args.first, args.sublist(1)]);
} else {
Function.apply(super.emit, args);
}
}
this.receiveBuffer = [];
for (i = 0; i < this.sendBuffer.length; i++) {
this.packet(this.sendBuffer[i]);
}
this.sendBuffer = [];
}
Same fix should also probably be applied to other 'Function.apply' calls (I didn't inspect the whole lib code, only the socket.dart file so the same issue can potentially afect other functions in other files) where function argument type are not known (=are dynamic) and can potentially be a List
@ramsestom I released a 0.9.6 version, please give it a try.
Thanks. I have seen you fix and it is pretty much the changes I have done in my local copy so it should work ;)
FYI, your fix https://github.com/rikulo/socket.io-client-dart/commit/0e1e3abef4d61e4cf5a6241dacb5db701b172918 has an unecessary is List
test, you can simplify it by wrapping packet['data'] into a list each time (that would work even if packet['data'] isn't a List so no need to test for it and the code would be simpler)
okay, thanks.
@ramsestom After I take some times to test this issue, the original implementation works well with our socket.io dart server without any error in either List type or single element which is passed by server's ack function. So, which socket.io server are you using? I am afraid its protocols may be different from our assumption.
I refix it again for both nodejs and dart server version.
Thanks. I am using the node.js (feathersjs) version for my server
I'm using 0.9.11. same issue here.
_socket.once('connect', (_) {
logger.i("connect");
_socket.emitWithAck(
messageName,
{
"fromUserId": "5f58dc9a0af1377e642f14b9",
"toSessionId": "5f58dc9a0af1377e642f14ba",
"content": "here hello",
"timestamp": 123132,
"type": 0
},
ack: () {},
binary: false);
});
error
E/flutter ( 5858): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: Closure call with mismatched arguments: function 'createConnection.<anonymous closure>.<anonymous closure>'
E/flutter ( 5858): Receiver: Closure: () => Null
E/flutter ( 5858): Tried calling: createConnection.<anonymous closure>.<anonymous closure>(true)
E/flutter ( 5858): Found: createConnection.<anonymous closure>.<anonymous closure>() => Null
E/flutter ( 5858): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter ( 5858): #1 Function._apply (dart:core-patch/function_patch.dart:11:30)
E/flutter ( 5858): #2 Function.apply (dart:core-patch/function_patch.dart:34:12)
E/flutter ( 5858): #3 Socket.onack (package:socket_io_client/src/socket.dart:318:18)
E/flutter ( 5858): #4 Socket.onpacket (package:socket_io_client/src/socket.dart:240:9)
E/flutter ( 5858): #5 EventEmitter.emit.<anonymous closure> (package:socket_io_common/src/util/event_emitter.dart:52:14)
E/flutter ( 5858): #6 List.forEach (dart:core-patch/growable_array.dart:302:8)
E/flutter ( 5858): #7 EventEmitter.emit (package:socket_io_common/src/util/event_emitter.dart:51:11)
E/flutter ( 5858): #8 Manager.ondecoded (package:socket_io_client/src/manager.dart:308:5)
E/flutter ( 5858): #9 EventEmitter.emit.<anonymous closure> (package:socket_io_common/src/util/event_emitter.dart:52:14)
E/flutter ( 5858): #10 List.forEach (dart:core-patch/growable_array.dart:302:8)
E/flutter ( 5858): #11 EventEmitter.emit (package:socket_io_common/src/util/event_emitter.dart:51:11)
E/flutter ( 5858): #12 Decoder.add (package:socket_io_common/src/parser/parser.dart:159:14)
E/flutter ( 5858): #13 Manager.ondata (package:socket_io_client/src/manager.dart:299:13)
E/flutter ( 5858): #14 EventEmitter.emit.<anonymous closure> (package:socket_io_common/src/util/event_emitter.dart:52:14)
E/flutter ( 5858): #15 List.forEach (dart:core-patch/growable_array.dart:302:8)
E/flutter ( 5858): #16 EventEmitter.emit (package:socket_io_common/src/util/event_emitter.dart:51:11)
E/flutter ( 5858): #17 Socket.onPacket (package:socket_io_client/src/engine/socket.dart:465:11)
E/flutter ( 5858): #18 Socket.setTransport.<anonymous closure> (package:socket_io_client/src/engine/socket.dart:290:34)
E/flutter ( 5858): #19 EventEmitter.emit.<anonymous closure> (package:socket_io_common/src/util/event_emitter.dart:52:14)
E/flutter ( 5858): #20 List.forEach (dart:core-patch/growable_array.dart:302:8)
E/flutter ( 5858): #21 EventEmitter.emit (package:socket_io_common/src/util/event_emitter.dart:51:11)
E/flutter ( 5858): #22 Transport.onPacket (package:socket_io_client/src/engine/transport/transport.dart:127:5)
E/flutter ( 5858): #23 Transport.onData (package:socket_io_client/src/engine/transport/transport.dart:121:5)
E/flutter ( 5858): #24 IOWebSocketTransport.addEventListeners.<anonymous closure> (package:socket_io_client/src/engine/transport/io_websocket_transport.dart:67:7)
E/flutter ( 5858): #25 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5858): #26 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5858): #27 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5858): #28 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 5858): #29 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 5858): #30 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter ( 5858): #31 _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter ( 5858): #32 _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter ( 5858): #33 new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1145:21)
E/flutter ( 5858): #34 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5858): #35 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5858): #36 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5858): #37 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 5858): #38 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 5858): #39 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:69:11)
E/flutter ( 5858): #40 _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
E/flutter ( 5858): #41 _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:338:23)
E/flutter ( 5858): #42 _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:232:46)
E/flutter ( 5858): #43 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:121:24)
E/flutter ( 5858): #44 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5858): #45 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5858): #46 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5858): #47 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 5858): #48 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 5858): #49 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter ( 5858): #50 _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter ( 5858): #51 _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter ( 5858): #52 _Socket._onData (dart:io-patch/socket_patch.dart:2020:41)
E/flutter ( 5858): #53 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 5858): #54 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5858): #55 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5858): #56 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 5858): #57 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 5858): #58 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter ( 5858): #59 _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter ( 5858): #60 _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter ( 5858): #61 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1556:33)
E/flutter ( 5858): #62 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1052:14)
E/flutter ( 5858): #63 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 5858): #64 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter ( 5858):
And as same as ramsestom, it was totally ok with just emit().
Ok, I found the problem. In the ack parameter function, you need to set the right parameter you wish to get from server, and it can't be omitted. If you don't know what you would get, use dynamic.
ack: (dynamic acked) {
logger.i(acked);
}
I am trying to use this lib but it doesn't seem to work I tried with a really simple example like this:
but it is throwing an error. Here is the exception call stack:
and the Log from the lib is as follow:
Strange thing is that even if I call a simple emit function instead of emitWithAck, like this:
_socket.emit("authenticate", {"strategy":"local", "email":"test@yahoo.fr", "password":"test69"});
no error is thrown by the app but the log still hang on after the "readyState opening" message and the rest of the log is only printed when the app is killed... So here is the log I have in this case:
any idea of what might be the issue and how to solve it?