mfeckie / phoenix_wings Goto Github PK
View Code? Open in Web Editor NEWPhoenix Channels client for Dart / Flutter
License: MIT License
Phoenix Channels client for Dart / Flutter
License: MIT License
Hello,
I have encountered an Unhandled Exception
Log from ADB:
E/flutter (13139): #0 PhoenixSocket._onConnMessage.<anonymous closure> (package:phoenix_wings/src/phoenix_socket.dart:165:37)
E/flutter (13139): #1 WhereIterator.moveNext (dart:_internal/iterable.dart:437:13)
E/flutter (13139): #2 Iterable.forEach (dart:core/iterable.dart:257:23)
E/flutter (13139): #3 PhoenixSocket._onConnMessage (package:phoenix_wings/src/phoenix_socket.dart:167:10)
E/flutter (13139): #4 PhoenixIoConnection.onMessage.<anonymous closure> (package:phoenix_wings/src/phoenix_io_connection.dart:67:15)
E/flutter (13139): #5 _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter (13139): #6 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (13139): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (13139): #8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter (13139): #9 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (13139): #10 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
E/flutter (13139): #11 _StreamController._add (dart:async/stream_controller.dart:607:7)
E/flutter (13139): #12 _StreamController.add (dart:async/stream_controller.dart:554:5)
E/flutter (13139): #13 new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1145:21)
E/flutter (13139): #14 _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter (13139): #15 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (13139): #16 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (13139): #17 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter (13139): #18 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (13139): #19 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
E/flutter (13139): #20 _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
E/flutter (13139): #21 _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:338:23)
E/flutter (13139): #22 _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:232:46)
E/flutter (13139): #23 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
E/flutter (13139): #24 _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter (13139): #25 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (13139): #26 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (13139): #27 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter (13139): #28 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (13139): #29 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
E/flutter (13139): #30 _StreamController._add (dart:async/stream_controller.dart:607:7)
E/flutter (13139): #31 _StreamController.add (dart:async/stream_controller.dart:554:5)
E/flutter (13139): #32 _Socket._onData (dart:io-patch/socket_patch.dart:2160:41)
E/flutter (13139): #33 _rootRunUnary (dart:async/zone.dart:1370:13)
E/flutter (13139): #34 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (13139): #35 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (13139): #36 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter (13139): #37 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (13139): #38 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
E/flutter (13139): #39 _StreamController._add (dart:async/stream_controller.dart:607:7)
E/flutter (13139): #40 _StreamController.add (dart:async/stream_controller.dart:554:5)
E/flutter (13139): #41 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1696:33)
E/flutter (13139): #42 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1208:14)
E/flutter (13139): #43 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (13139): #44 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
On Phoenix I sent this:
APP.Endpoint.broadcast!("room:chat", "new:msg", %{user: "SYSTEM", body: "PING"})
I was able to fix this by updating:
bool isMember(
String topicParam, String event, Map payload, String joinRefParam) {
to
bool isMember(
String topicParam, String event, Map payload, String? joinRefParam) {
I am fairly new to Dart so I am not sure if there was maybe some missing Null safety implementation?
Hi,
I get this error in flutter when device goes in bad network state
Unhandled Exception: Bad state: StreamSink is closed
#0 _StreamSinkImpl.add (dart:_http/http_impl.dart:536:7)
#1 _WebSocketImpl.add (dart:_http/websocket_impl.dart:1213:11)
#2 PhoenixIoConnection.send
package:phoenix_wings/src/phoenix_io_connection.dart:37
#3 PhoenixSocket.push.<anonymous closure>
package:phoenix_wings/src/phoenix_socket.dart:221
#4 PhoenixSocket.push
package:phoenix_wings/src/phoenix_socket.dart:225
#5 PhoenixSocket.sendHeartbeat
package:phoenix_wings/src/phoenix_socket.dart:214
There is also a piece of custom logic behind, maybe you can suggest what am I doing wrong
connectivity = new Connectivity();
final connRes = await connectivity.checkConnectivity();
connectivity.onConnectivityChanged.listen((ConnectivityResult result) {
if (result == ConnectivityResult.none) {
_socket.disconnect();
onConnectionChange.value = false;
} else if (!_socket.isConnected) {
_socket.connect();
onConnectionChange.value = true;
}
});
Thanks for putting this package together. I'm currently getting an error not being able to match the heartbeat message. Should the heartbeat be optional? It looks the heartbeat option was removed from the phoenix server phoenixframework/phoenix@7b252f4. Looking in phoenix.js it looks like there is a skipHeartbeat. I'm wondering if it exists for backwards compatibility. I haven't looked much deeper and I could be reading it wrong.
It would be nice to have support of the Presence
class which is present in the phoenix.js
.
Sample Javascript implementation: https://github.com/phoenixframework/phoenix/blob/master/assets/js/phoenix.js#L1148
Hi,
I've been trying to create a websocket connection and when I've tried to pass 2 required params to the socketOptions it won't just work, not even trying to connect.
This is a sample of my code
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:random_string/random_string.dart';
import 'package:phoenix_wings/phoenix_wings.dart';
class LiveEventsDeviceWidget extends StatefulWidget {
const LiveEventsDeviceWidget({Key? key}) : super(key: key);
@override
_LiveEventsDeviceWidgetState createState() => _LiveEventsDeviceWidgetState();
}
class _LiveEventsDeviceWidgetState extends State<LiveEventsDeviceWidget> {
List<dynamic> messages = [];
late String roomName;
String realmName = "demorealm";
late PhoenixSocket _wingsSocket;
Future<String> fetchToken() async {
final prefs = await SharedPreferences.getInstance();
final jwtToken = prefs.getString('access_token_shared') ?? ''; //this is not null by default
return jwtToken;
}
@override
void initState() {
super.initState();
roomName = randomAlphaNumeric(7);
fetchToken().then((tokenJwt) async {
_wingsSocket = PhoenixSocket("wss://url.it/appengine/v1/socket/websocket", socketOptions: PhoenixSocketOptions(params: {'realm':realmName,'token':tokenJwt,}),);
await _wingsSocket.connect();
final chatChannel = _wingsSocket.channel("rooms:demorealm:B616NCs8RS6RtELDt-P5fg_$roomName");
chatChannel.on('incoming_data', (payload, ref, joinRef) {
print('chatChannel: $chatChannel');
print('payload: $payload, $ref, $joinRef');
});
chatChannel.join();
});
}
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: messages.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(messages[index]['message']),
);
},
);
}
}
It probably happened when calling socket.disconnect()
before its full connected. But I am not sure about that.
E/flutter ( 4834): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter ( 4834): NoSuchMethodError: The method 'onClose' was called on null.
E/flutter ( 4834): Receiver: null
E/flutter ( 4834): Tried calling: onClose(Closure: () => dynamic from Function 'reconnect':.)
E/flutter ( 4834): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:48:5)
E/flutter ( 4834): #1 PhoenixSocket.connect (package:phoenix_wings/src/phoenix_socket.dart:107:11)
E/flutter ( 4834): #2 _RootZone.runUnary (dart:async/zone.dart:1379:54)
E/flutter ( 4834): #3 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
E/flutter ( 4834): #4 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
E/flutter ( 4834): #5 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
E/flutter ( 4834): #6 Future._complete (dart:async/future_impl.dart:476:7)
E/flutter ( 4834): #7 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
E/flutter ( 4834): #8 _AsyncAwaitCompleter.complete (dart:async/runtime/libasync_patch.dart:28:18)
E/flutter ( 4834): #9 _completeOnAsyncReturn (dart:async/runtime/libasync_patch.dart:295:13)
E/flutter ( 4834): #10 PhoenixIoConnection.waitForConnection (package:phoenix_wings/src/phoenix_io_connection.dart)
E/flutter ( 4834): #11 _RootZone.runUnary (dart:async/zone.dart:1379:54)
E/flutter ( 4834): #12 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
E/flutter ( 4834): #13 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
E/flutter ( 4834): #14 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
E/flutter ( 4834): #15 Future._addListener.<anonymous closure> (dart:async/future_impl.dart:351:9)
E/flutter ( 4834): #16 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 4834): #17 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
After I connect on the channel the dart kept receiving this error:
E/flutter ( 3789): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Concurrent modification during iteration: Instance(length:5) of '_GrowableList'. E/flutter ( 3789): #0 ListIterator.moveNext (dart:_internal/iterable.dart:338:7) E/flutter ( 3789): #1 WhereIterator.moveNext (dart:_internal/iterable.dart:440:22) E/flutter ( 3789): #2 Iterable.forEach (dart:core/iterable.dart:325:23) E/flutter ( 3789): #3 PhoenixChannel.trigger (package:phoenix_wings/src/phoenix_channel.dart:204:54) E/flutter ( 3789): #4 PhoenixSocket._onConnMessage.<anonymous closure> (package:phoenix_wings/src/phoenix_socket.dart:166:39) E/flutter ( 3789): #5 Iterable.forEach (dart:core/iterable.dart:325:35) E/flutter ( 3789): #6 PhoenixSocket._onConnMessage (package:phoenix_wings/src/phoenix_socket.dart:166:10) E/flutter ( 3789): #7 PhoenixIoConnection.onMessage.<anonymous closure> (package:phoenix_wings/src/phoenix_io_connection.dart:67:15) E/flutter ( 3789): #8 _RootZone.runUnaryGuarded (dart:async/zone.dart:1593:10) E/flutter ( 3789): #9 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) E/flutter ( 3789): #10 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) E/flutter ( 3789): #11 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19) E/flutter ( 3789): #12 _StreamController._add (dart:async/stream_controller.dart:648:7) E/flutter ( 3789): #13 _StreamController.add (dart:async/stream_controller.dart:596:5) E/flutter ( 3789): #14 new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1144:21) E/flutter ( 3789): #15 _RootZone.runUnaryGuarded (dart:async/zone.dart:1593:10) E/flutter ( 3789): #16 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) E/flutter ( 3789): #17 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) E/flutter ( 3789): #18 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11) E/flutter ( 3789): #19 _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11) E/flutter ( 3789): #20 _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:332:23) E/flutter ( 3789): #21 _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:226:46) E/flutter ( 3789): #22 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24) E/flutter ( 3789): #23 _RootZone.runUnaryGuarded (dart:async/zone.dart:1593:10) E/flutter ( 3789): #24 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) E/flutter ( 3789): #25 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) E/flutter ( 3789): #26 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19) E/flutter ( 3789): #27 _StreamController._add (dart:async/stream_controller.dart:648:7) E/flutter ( 3789): #28 _StreamController.add (dart:async/stream_controller.dart:596:5) E/flutter ( 3789): #29 _Socket._onData (dart:io-patch/socket_patch.dart:2355:41) E/flutter ( 3789): #30 _RootZone.runUnaryGuarded (dart:async/zone.dart:1593:10) E/flutter ( 3789): #31 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) E/flutter ( 3789): #32 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) E/flutter ( 3789): #33 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19) E/flutter ( 3789): #34 _StreamController._add (dart:async/stream_controller.dart:648:7) E/flutter ( 3789): #35 _StreamController.add (dart:async/stream_controller.dart:596:5) E/flutter ( 3789): #36 _RawSecureSocket._sendReadEvent (dart:io/secure_socket.dart:1111:19) E/flutter ( 3789): #37 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15) E/flutter ( 3789): #38 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19) E/flutter ( 3789): #39 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5) E/flutter ( 3789): #40 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
Is it possible to update with null-safety? This is one of the packages stopping us from going to null safety.
The library does not work properly with Dart 2.
Flutter's Dart 1 support will be dropped in Beta 3 (https://github.com/flutter/flutter/wiki/Opting-out-of-Dart-2-with-Flutter-beta-2)
E/flutter ( 5081): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 5081): type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' of 'message' where
E/flutter ( 5081): _InternalLinkedHashMap is from dart:collection
E/flutter ( 5081): String is from dart:core
E/flutter ( 5081): String is from dart:core
E/flutter ( 5081): #1 PhoenixPush.matchReceive.<anonymous closure> (package:phoenix_wings/src/phoenix_push.dart:38)
E/flutter ( 5081): #2 Iterable.forEach (dart:core/iterable.dart:292)
E/flutter ( 5081): #3 PhoenixPush.matchReceive (package:phoenix_wings/src/phoenix_push.dart:38)
E/flutter ( 5081): #4 PhoenixPush.startTimeout.<anonymous closure> (package:phoenix_wings/src/phoenix_push.dart:78)
E/flutter ( 5081): #5 PhoenixChannel.trigger.<anonymous closure> (package:phoenix_wings/src/phoenix_channel.dart:204)
E/flutter ( 5081): #6 Iterable.forEach (dart:core/iterable.dart:292)
E/flutter ( 5081): #7 PhoenixChannel.trigger (package:phoenix_wings/src/phoenix_channel.dart:203)
E/flutter ( 5081): #8 new PhoenixChannel.<anonymous closure> (package:phoenix_wings/src/phoenix_channel.dart:73)
E/flutter ( 5081): #9 PhoenixChannel.trigger.<anonymous closure> (package:phoenix_wings/src/phoenix_channel.dart:204)
E/flutter ( 5081): #10 Iterable.forEach (dart:core/iterable.dart:292)
E/flutter ( 5081): #11 PhoenixChannel.trigger (package:phoenix_wings/src/phoenix_channel.dart:203)
E/flutter ( 5081): #12 PhoenixSocket._onConnMessage.<anonymous closure> (package:phoenix_wings/src/phoenix_socket.dart:134)
E/flutter ( 5081): #13 Iterable.forEach (dart:core/iterable.dart:292)
E/flutter ( 5081): #14 PhoenixSocket._onConnMessage (package:phoenix_wings/src/phoenix_socket.dart:134)
The crash is caused by the JSON libary. See "What is breaking?": https://groups.google.com/forum/#!topic/flutter-dev/H8dDhWg_c8I
First off, thank you for this great package... I'm learning a lot from it!
Secondly, I'm a complete newbie to Flutter, Elixir, Phoenix, Dart, and websockets, so take all of this with a grain of salt.
While trying to put together a simple Flutter chat app talking to this simple Phoenix chat server:
https://github.com/stevegrossi/phoenix_chat
I ran into what appears to be an incompatibility with the phoenix.js version for the "phx_join"
message.
Specifically, my Flutter app was sending this:
payload: "[\"2\",\"2\",\"room:lobby\",\"phx_join\",{}]",
(phoenix) lib/phoenix/socket/message.ex:21: Phoenix.Socket.Message.from_map!(["2", "2", "room:lobby", "phx_join", %{}])
but the phoenix.js version was sending this:
payload: "{\"topic\":\"room:lobby\",\"event\":\"phx_join\",\"payload\":{},\"ref\":\"73\"}",
When I changed phoenix_message.dart
from this:
String toJSON() {
return json.encode([joinRef, ref, topic, event, payload]);
}
to this:
String toJSON() {
//GML return json.encode([joinRef, ref, topic, event, payload]);
var msg = {
'joinRef': joinRef,
'ref': ref,
'topic': topic,
'event': event,
'payload': payload,
};
return JSON.encode(msg);
}
the phx_join
started working. Any ideas why this might be the case?
WebSocket connection to ws://x.x.x.x/socket/websocket?vsn=2.0.0&user=lobby failed!: Unsupported operation: Platform._version
If the server is not available, there is no way to stop the .connect()
retries.
I expect that if I call socket.disconnect
the connect
method will stop retrying.
You can reproduce this by using an invalid socket url.
WebSocket connection to ws://192.168.187.25:4001/socket?id=1234&vsn=2.0.0 failed!: WebSocketException: Connection to 'http://192.168.187.25:4001/socket?id=1234&vsn=2.0.0#' was not upgraded to websocket
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.