This message was deleted.
# helpdesk
s
This message was deleted.
a
Yeah that’s the design of the API, you don’t need to create rooms
m
The first user to join a room, implicitly creates the room (if it wasn’t created a priori using server APIs).
a
If you don’t want users to be able to create rooms, then when you create a token for the user you need to give it
roomCreate: false
in the access token grants
🙏 1
(details in the docs here)
t
this is the permission, the roomCreate is set to false
Copy code
getMonitorToken ({ roomId } = {}) {
    const at = new AccessToken(key, secret, { identity: this.userId })

    // <https://docs.livekit.io/concepts/authentication/#video-grant>
    at.addGrant({
      room: roomId,
      roomCreate: false,
      roomJoin: true,
      canPublish: false,
      canSubscribe: true,
      canPublishData: false,
      roomRecord: false,
    })

    const token = at.toJwt()

    return token
  },
what am i trying to do is show a offline status if publisher is not started
a
hmm. For that use case would it work to use the ListRooms API on your server?
t
@acoustic-engineer-41666 ok thanks
a
It is surprising that the roomCreate grant isn’t working for you, though. If you can provide a minimal repro, I’d appreciate it. I’ll look into this soon
t
yes, i think it would like to return a status failed, i’ll try to make a reproduce.
🙏 1
client
Copy code
const url = '<wss://live-dev-k5mhurx4.livekit.cloud>'
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2aWRlbyI6eyJyb29tSm9pbiI6dHJ1ZSwicm9vbSI6Im5hbWUtb2Ytcm9vbSIsInJvb21DcmVhdGUiOmZhbHNlLCJjYW5QdWJsaXNoIjpmYWxzZSwiY2FuU3Vic2NyaWJlIjp0cnVlLCJjYW5QdWJsaXNoRGF0YSI6ZmFsc2UsInJvb21SZWNvcmQiOmZhbHNlfSwiaWF0IjoxNjkwNTE4MzYzLCJuYmYiOjE2OTA1MTgzNjMsImV4cCI6MTY5MDUzOTk2MywiaXNzIjoiQVBJRVFXaDg0aXM0Y1I4Iiwic3ViIjoidXNlci1uYW1lIiwianRpIjoidXNlci1uYW1lIn0.yX9Y6hB8vtwoXCRXHbTEUQ1PwPbQr4yU7O92NBiPuSY'

const connect = function () {
  const room = new LivekitClient.Room()
  room.on(LivekitClient.RoomEvent.ConnectionStateChanged, console.log)
  room.prepareConnection(url)
  room.connect(url, token)
}
                   
                   
connect()
server grant
Copy code
const { AccessToken } = require('livekit-server-sdk')
const roomName = 'name-of-room'
const participantName = 'user-name'
const at = new AccessToken('APIEQWh84is4cR8', '67nYbTwKafZwOVf9CLtzL1VQ27nCeox6EmXrsuGJ0dgB', {
  identity: participantName,
})
at.addGrant({
  roomJoin: true,
  room: roomName,
  roomCreate: false,
  roomJoin: true,
  canPublish: false,
  canSubscribe: true,
  canPublishData: false,
  roomRecord: false,
})
const token = at.toJwt()
console.log('access token', token)
d
roomCreate
is for users that are calling
CreateRoom
API explicitly
when
autoCreate
is allowed, users do not require
roomCreate
for the room to be automatically created
p
just to add context, using cloud this is a setting in
Settings/Project
where you can disable the checkmark for auto room creation. It is enabled by default.
👍 1