centrifugal / centrifuge-dart

Dart (Flutter) client SDK for bidirectional communication with Centrifugo and Centrifuge-based server over WebSocket

Home Page:https://pub.dartlang.org/packages/centrifuge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Publish Message with JWT

sh0umik opened this issue · comments

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);
  }

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

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

@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"}

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.