centrifugal / centrifuge-dart

Dart (Flutter) client SDK for bidirectional communication with Centrifugo and Centrifuge-based server over WebSocket
https://pub.dartlang.org/packages/centrifuge
MIT License
102 stars 29 forks source link

Publish Message with JWT #23

Closed sh0umik closed 5 years ago

sh0umik commented 5 years ago

I can successfully connect to Centrifugo server using JWT and setToken() method. Tested with admin panel and i can only receive message.

Whenever i try to send message i get this Unhandled Exception: Error{code: 103, message: permission denied}

Here is what i am trying

 void sendMessage(SendChatMessage message) async {
    final output = jsonEncode({'token': profileInfo.chatToken, 'data' : {'msg': message.message}});
    final data = utf8.encode(output);
    await _subscriptions[message.channel].publish(data);
  }
sh0umik commented 5 years ago

Setting the publish = true in server config solved the problem. Thanks for quick response in gitter chat.

More about this, are described here.

https://centrifugal.github.io/centrifugo/faq/#can-i-publish-new-messages-over-websocket-connection-from-client

autocorrectoff commented 2 months ago

the link is dead. anyplace else where one could find how to do this?

FZambia commented 2 months ago

@autocorrectoff https://centrifugal.dev/docs/faq#can-i-publish-new-messages-over-a-websocket-connection-from-a-client

autocorrectoff commented 2 months ago

@FZambia it says:

It's possible to publish messages into channels directly from a client (when publish channel option is enabled).

It should actually be allow_publish_for_subscriber ?

Because if I just add publish: true to config I get:

centrifugo | {"level":"warn","key":"publish","namespace_name":"test","time":"2024-05-07T07:54:24Z","message":"unknown key found in the namespace object"}

FZambia commented 2 months ago

It should actually be allow_publish_for_subscriber ?

Yep. Some option names changed since 2019, use https://centrifugal.dev/docs/server/channels#channel-options as a source of truth.