PubNub best practice: How to manage private rooms?

后端 未结 2 1438
被撕碎了的回忆
被撕碎了的回忆 2021-02-11 02:54

I\'m learning pubnub and I read their documentation but I just can\'t find how to manage a multi room chat box.

By default, a channel can be listened by anyone. Subscri

2条回答
  •  走了就别回头了
    2021-02-11 03:11

    The answers above were correct in 2012, but a lot has changed since then. Private chat rooms can be enabled with PubNub Access Manager, which explicitly grants Publish/Subscribe access on specific channels.

    The way this works is through access tokens (aka an "Auth Key"). The developer (you) creates an Auth Key (basically any string of characters) and passes it to PubNub Access Manager. You then set the rules for this Auth Key (i.e. which channels the Auth Key can publish and/or subscribe to).

    This Auth Key is provided to any device that needs access to the channel, and used when the device subscribes or publishes to the channel.

    Basic docs are available here: http://www.pubnub.com/docs/javascript/tutorial/access-manager.html

    Grant 60 minute read/write privilege to channel "privateChat" to an auth_key:

     pubnub.grant({
     channel  : 'privateChat',
     auth_key : 'abxyz12-auth-key-987tuv',
     read     : true,
     write    : true,
     ttl      : 60
     });
    

提交回复
热议问题