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

i want to trigger client to client event when pusher successfully subscribe on a presence channel but i cache this error in try catch block "Event is not for this channel" #134

Open
mehdidavar opened this issue Oct 10, 2023 · 6 comments

Comments

@mehdidavar
Copy link

this is my method

Future testTrigger() async {
try{
await channel.trigger(PusherEvent(channelName: currentChannelName,eventName: "client-my-event", ));

}catch(e){
debugPrint(e.toString());
}
}

@benw-pusher
Copy link

You can read about how to trigger an event at https://github.com/pusher/pusher-channels-flutter#triggering-events. Looking at the parameters you are using (channelName: currentChannelName,eventName: "client-my-event", ) it appears you are triggering using the global pusher instance - however you are also using channel.trigger which means you are triggering directly on the channel.
What happens if you use await pusher.trigger(channelName: currentChannelName, eventName: "client-my-event", data: ["myName": "Bob"]);

@mehdidavar
Copy link
Author

mehdidavar commented Oct 10, 2023

i modify my code to

Future<void> testTrigger() async {
try{
 // await ch.trigger(PusherEvent(channelName: currentChannelName,eventName: "client-my-event", ));
  await pusher.trigger(PusherEvent(channelName: currentChannelName, eventName: "client-my-event", data: {"myName": "Bob"}));
}catch(e){
  debugPrint(e.toString());
}
 } 

but got this

PlatformException(error, java.util.HashMap cannot be cast to java.lang.String, null, java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
at com.pusher.channels_flutter.PusherChannelsFlutterPlugin.onMethodCall(PusherChannelsFlutterPlugin.kt:79)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:322)
at io.flutter.embedding.engine.dart.DartMessenger.$r8$lambda$2j2MERcK825A5j1fv5sZ7xB2Iuo(Unknown Source:0)
at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)

then i change method to

 Future<void> testTrigger() async {
try{
 // await ch.trigger(PusherEvent(channelName: currentChannelName,eventName: "client-my-event", ));
  await pusher.trigger(PusherEvent(channelName: currentChannelName, eventName: "client-my-event"));
}catch(e){
  debugPrint(e.toString());
}
 } 

and go this
java.lang.NullPointerException
at com.pusher.channels_flutter.PusherChannelsFlutterPlugin.onMethodCall(PusherChannelsFlutterPlugin.kt:79)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:322)
at io.flutter.embedding.engine.dart.DartMessenger.$r8$lambda$2j2MERcK825A5j1fv5sZ7xB2Iuo(Unknown Source:0)
at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8757)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

@benw-pusher
Copy link

Can you try with this code as previously shared?

await pusher.trigger(channelName: currentChannelName, eventName: "client-my-event", data: ["myName": "Bob"]);

@mehdidavar
Copy link
Author

yes i will inform you soon

@AhmedHusseinHafez
Copy link

AhmedHusseinHafez commented Feb 9, 2024

same problem with me
i tried
await pusher.trigger(channelName: currentChannelName, eventName: "client-my-event", data: ["myName": "Bob"]);
as in flutter docs but i must have to pass PusherEvent
and still my problem not have solution
Future trigger(PusherEvent event)
Type: Future Function(PusherEvent)

i modify my code to

Future<void> testTrigger() async {
try{
 // await ch.trigger(PusherEvent(channelName: currentChannelName,eventName: "client-my-event", ));
  await pusher.trigger(PusherEvent(channelName: currentChannelName, eventName: "client-my-event", data: {"myName": "Bob"}));
}catch(e){
  debugPrint(e.toString());
}
 } 

but got this

PlatformException(error, java.util.HashMap cannot be cast to java.lang.String, null, java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String at com.pusher.channels_flutter.PusherChannelsFlutterPlugin.onMethodCall(PusherChannelsFlutterPlugin.kt:79) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258) at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:322) at io.flutter.embedding.engine.dart.DartMessenger.$r8$lambda$2j2MERcK825A5j1fv5sZ7xB2Iuo(Unknown Source:0) at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method)

then i change method to

 Future<void> testTrigger() async {
try{
 // await ch.trigger(PusherEvent(channelName: currentChannelName,eventName: "client-my-event", ));
  await pusher.trigger(PusherEvent(channelName: currentChannelName, eventName: "client-my-event"));
}catch(e){
  debugPrint(e.toString());
}
 } 

and go this java.lang.NullPointerException at com.pusher.channels_flutter.PusherChannelsFlutterPlugin.onMethodCall(PusherChannelsFlutterPlugin.kt:79) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258) at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:322) at io.flutter.embedding.engine.dart.DartMessenger.$r8$lambda$2j2MERcK825A5j1fv5sZ7xB2Iuo(Unknown Source:0) at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8757) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

@benw-pusher
Copy link

await pusher.trigger(channelName: currentChannelName, eventName: "client-my-event", data: ["myName": "Bob"]);
This is working in my implementation so interested to see more about your implementation, can you share the full code and error?

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

No branches or pull requests

3 participants