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
pubnub.grantToken(
{
ttl: 15,
authorizedUserId: "user-1",
resources: {
spaces: {
"channel-a": {
read: true
},
"channel-b": {
read: true
}
}
}
}, function(status, token) {
show all 18 linesspaces = [
Space.id("channel-a").read(),
Space.id("channel-b").read()
]
envelope = pubnub.grant_token()
.spaces(spaces)
.ttl(15)
.authorized_user("user-1")
.sync()
pubnub.grantToken()
.ttl(15)
.authorizedUserId("user-1")
.spacesPermissions(Arrays.asList(
SpacePermissions.id(SpaceId("channel-a")).read()
SpacePermissions.id(SpaceId("channel-b")).read()))
.async(result -> { /* check result */ });
pubnub.grantToken(
ttl = 15,
authorizedUserId = "user-1",
spacesPermissions = listOf(
SpacesPermissions.name(name = "channel-a", read = true, write = false),
SpacesPermissions.name(name = "channel-b", read = true, write = false)
)
)
.async { result, status ->
if (status.error) {
// Handle error
} else {
// Handle result
}
}