Comments (18)
@jiajun-ifanr I have tried some code where you can so something like this
var options = new SubscribeOptions();
options.addCustomValue("where", (serializerType) => "{}");
final subscription = await session.subscribe(topic, options: options);
This makes it possible to pass a custom field with a custom serializer for either msgpack or json to a subscribe option. I tried it with your code an the server responded with a subscribed as expected. I will publish the code soon. I just need to write some tests and add the custom options to all the other message types as well.
from connectanum-dart.
@jiajun-ifanr The issue is that you printing args instead of argKwds.
print(event.argumentsKeywords);
// or
print((event.argumentsKeywords['after'] as Map)['text']);
this works
from connectanum-dart.
@jiajun-ifanr I'm very eger to make this module work as good as possible. I have not used it in production but I will soon. So having people to test it for me is just perfekt. So you helped me too. 😅
from connectanum-dart.
The SubscribeOptions
are used to support WAMP advanced fatures like Pattern Based Subscription . This is where you need the match
option.
Since dart does not support a reflection api, I hard coded all SubscribeOptions that I knew exists.
What are the information you want to share during the subscription process? What is the router you use? What advanced feature do you want to use that is not supported by this package?
from connectanum-dart.
It would probably be better if I explain it this way:
I have an issue when subscribe to a topic.
I used the PubSub pattern and followed the example given in the main.dart
.
It was originally thought to send a Map as an option to the server on subscribe, and this Map could contain a where
Map, like this:
{"where": {}}
Since the where
key is a custom key required by our server, it will look like this:
[
32,
912873614,
{
"where": {}
},
"com.myapp.topic.emergency"
]
However, even when I execute the below code without an option, there are two errors shown:
- Unhandled Exception: Bad state: No element
- Unhandled Exception: NoSuchMethodError: The getter 'inMilliseconds' was called on null.
Say for example I have the following code in my main.dart
(without a SubscribeOptions
passed):
import 'package:flutter/material.dart';
import 'package:connectanum/connectanum.dart';
import 'package:connectanum/json.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Home(),
);
}
}
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
void initState() {
super.initState();
test();
}
void test() async {
WampImplementation wamp = new WampImplementation();
wamp.subscribe();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test App'),
),
);
}
}
class WampImplementation {
Client client;
void subscribe() async {
String url =
'wss://a4d2d62965ddb57fa4d6.ws.myminapp.com/ws/hydrogen/?x-hydrogen-client-id=a4d2d62965ddb57fa4d6&x-hydrogen-env-id=f1eeb28c9552d4c83df1&authorization=Hydrogen-r1%20580co4jlkysw7rprsgz4edxx9pubot3s';
client = Client(
realm: 'com.ifanrcloud',
transport: WebSocketTransport(
url,
new Serializer(),
WebSocketSerialization.SERIALIZATION_JSON,
),
);
Session session;
try {
session = await client.connect().first;
String topic = 'com.ifanrcloud.schema_event.danmu_jiajun.on_create';
// SubscribeOptions options = new SubscribeOptions();
final subscription = await session.subscribe(topic);
// subscription.eventStream.listen((event) => print(event.arguments[0]));
} on Abort catch (abort) {
print(abort.message.message);
}
}
}
I can't figure out what had happened here with the above errors. Kinda strange.
from connectanum-dart.
However, even when I execute the below code without an option, there are two errors shown:
- Unhandled Exception: Bad state: No element
- Unhandled Exception: NoSuchMethodError: The getter 'inMilliseconds' was called on null.
The exception 1 is thrown because the socket is closed by the router before the subscribe receives the subscription.
I don't get why exception is thrown, because there is a nullpointer check.. weired. I can't reproduce number 2 with my code.
[
32,
912873614,
{
"where": {}
},
"com.myapp.topic.emergency"
]
This is not possible at the moment. I could implement it.
from connectanum-dart.
Many thanks.
How did you know about the cause of exception 1? Is it possible to debug WebSocket via the package or could you recommend any methods (like Charles) to debug by myself? I've searched for answers with no hope for quite some time now.
Also, would it be good to throw an error message with better explanation about the exception rather than Bad state: No element
since it might be confusing and I at first thought it was a Flutter issue.
from connectanum-dart.
@jiajun-ifanr I wrote a little unit test based on you code:
import 'package:connectanum/connectanum.dart';
import 'package:connectanum/json.dart';
import 'package:test/test.dart';
void main() {
test("error", () async {
await WampImplementation.subscribe();
});
}
class WampImplementation {
static void subscribe() async {
String url =
'wss://a4d2d62965ddb57fa4d6.ws.myminapp.com/ws/hydrogen/?x-hydrogen-client-id=a4d2d62965ddb57fa4d6&x-hydrogen-env-id=f1eeb28c9552d4c83df1&authorization=Hydrogen-r1%20580co4jlkysw7rprsgz4edxx9pubot3s';
Client client = Client(
realm: 'com.ifanrcloud',
transport: WebSocketTransport(
url,
new Serializer(),
WebSocketSerialization.SERIALIZATION_JSON,
),
);
Session session;
try {
session = await client.connect().first;
String topic = 'com.ifanrcloud.schema_event.danmu_jiajun.on_create';
// SubscribeOptions options = new SubscribeOptions();
final subscription = await session.subscribe(topic);
// subscription.eventStream.listen((event) => print(event.arguments[0]));
} on Abort catch (abort) {
print(abort.message.message);
}
}
}
You need to know that this package uses the transport streams and wraps a broadcast stream pre session around it. This way the broadcast stream may be closed safely and may be listened to multiple times.
You will see the transport stream is closed before the subscribe
can receive a subscribed
here:
This is not really an error but rather an event. You may have to subscribe to those events:
from connectanum-dart.
I only added custom options for subscriptions for now. If you need it for registrations too, plz open a new issue
from connectanum-dart.
Thanks a lot for your help!
I can now successfully subscribe to a topic and receive responses from our server.
But I still can't print out what the server has responded since the event.arguments
(or anything in event
) is always null
:
SubscribeOptions options = new SubscribeOptions();
options.addCustomValue('where', (serializerType) => '{}');
final subscription = await session.subscribe(topic, options: options);
subscription.eventStream.listen((event) => print(event.arguments[0]));
It is believed that the server has sent valid information to a client (my JS client does receive it correctly) but I will have it checked with my colleagues.
I really appreciate your help. In what way I can buy you a cup of coffee?
from connectanum-dart.
But I still can't print out what the server has responded since the event.arguments (or anything in event) is always null:
I'll check that in a minute.
I really appreciate your help. In what way I can buy you a cup of coffee?
Never mind! 😄 A ⭐ is enough
from connectanum-dart.
@jiajun-ifanr I cannot debug it anymore, I get this error: Permission denied, please call login function first.
from connectanum-dart.
@konsultaner Please try and update the wss
url with the following:
String url =
'wss://a4d2d62965ddb57fa4d6.ws.myminapp.com/ws/hydrogen/?x-hydrogen-client-id=a4d2d62965ddb57fa4d6&x-hydrogen-env-id=f1eeb28c9552d4c83df1&authorization=Hydrogen-r1%20qlnol4csq38uzsne04wzd6y3684g1yy4';
event.arguments
might only be printed out when the server responds. If you need me to send a response to the client, please let me know.
from connectanum-dart.
Could you send a respond every 1000ms?
from connectanum-dart.
@konsultaner Yes, now I send one every 3000ms
from connectanum-dart.
Your server has a wrong message encoding, the null values are wrong:
[36,844427229501,null,{},null,{"after":{"text":"this is example text","_read_perm":["user:anonymous"],"_write_perm":[],"created_at":1604311031,"updated_at":1604311031,"created_by":236097344815877,"id":"5f9fd7f7e9ed7d7681c837b4"},"before":{},"event":"on_create","schema_id":107144,"schema_name":"danmu_jiajun","id":"5f9fd7f7e9ed7d7681c837b4"}]
from connectanum-dart.
sorry. I see this should still work
from connectanum-dart.
@konsultaner Perfect! I can now make it work.
Thank you for all your support and kindness throughout the entire problem-solving process.
from connectanum-dart.
Related Issues (20)
- Add way more logging!
- Resubscribe to Topics on Reconnection HOT 2
- Was there dublicate sessions fix from version 1.0.6 to 1.1.6 HOT 1
- WAMPCRA: Only derive key when `salt` present in Challenge HOT 11
- Session call arguments type HOT 2
- session.publish seem to stuck HOT 4
- Session.publish with PublishOptions(acknowledge: false) waits for `PUBLISHED`
- Strange behaviour of Session.publish and/or Session.subscribe HOT 2
- Session.call seem to block HOT 3
- Cache stored key for scram authentication
- Support multiple serializers HOT 18
- Implement CBOR serializer HOT 15
- Better reconnection handling HOT 1
- Implement Payload PassThru Mode HOT 4
- Flaute WebApp Chrome Webhost is not supporting dart.html HOT 9
- Auth failure response doesn't seem right HOT 19
- not connect websocket HOT 2
- Currently the connection doesn't support authextra HOT 2
- Unable to catch error HOT 7
- Support dart2wasm compilation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connectanum-dart.