Muting users
Access Manager enables you to manage access for individual users so they can be muted on specific channels.
Mute user in channels
To mute user-1
in specific channels, call the grant token method and request only read
permissions on these channels.
- Node.js
- Python
- Java
- Kotlin
1pubnub.grantToken(
2 {
3 ttl: 15,
4 authorizedUserId: "user-1",
5 resources: {
6 spaces: {
7 "channel-a": {
8 read: true
9 },
10 "channel-b": {
11 read: true
12 }
13 }
14 }
15 }, function(status, token) {
show all 18 lines1spaces = [
2 Space.id("channel-a").read(),
3 Space.id("channel-b").read()
4 ]
5envelope = pubnub.grant_token()
6 .spaces(spaces)
7 .ttl(15)
8 .authorized_user("user-1")
9 .sync()
1pubnub.grantToken()
2 .ttl(15)
3 .authorizedUserId("user-1")
4 .spacesPermissions(Arrays.asList(
5 SpacePermissions.id(SpaceId("channel-a")).read()
6 SpacePermissions.id(SpaceId("channel-b")).read()))
7 .async(result -> { /* check result */ });
1pubnub.grantToken(
2 ttl = 15,
3 authorizedUserId = "user-1",
4 spacesPermissions = listOf(
5 SpacesPermissions.name(name = "channel-a", read = true, write = false),
6 SpacesPermissions.name(name = "channel-b", read = true, write = false)
7 )
8)
9 .async { result, status ->
10 if (status.error) {
11 // Handle error
12 } else {
13 // Handle result
14 }
15 }