I am new to Janus with javascript, I have a room like this:
{
"janus": "success",
"session_id": 266646464364358,
"transaction": "MUcPg6Wu5jhr",
"sender": 4377145860586972,
"plugindata": {
"plugin": "janus.plugin.videoroom",
"data": {
"videoroom": "success",
"list": [
{
"room": 11,
"description": "Room 11",
"pin_required": false,
"is_private": false,
"max_publishers": 3,
"bitrate": 0,
"fir_freq": 0,
"require_pvtid": false,
"require_e2ee": false,
"dummy_publisher": false,
"notify_joining": false,
"audiocodec": "opus",
"videocodec": "vp8",
"opus_fec": true,
"record": false,
"lock_record": false,
"num_participants": 0,
"audiolevel_ext": true,
"audiolevel_event": false,
"videoorient_ext": true,
"playoutdelay_ext": true,
"transport_wide_cc_ext": true
}
]
}
}
THen I using join request with body like this:
join params {
janus: 'message',
plugin: 'janus.plugin.videoroom',
session_id: 8568607942621781,
handle_id: 3267543887867048,
transaction: 'VeENHRbBTHWI',
body: { request: 'join', room: 11, ptype: 'publisher', display: 'test' }
}
But the response is ack only, I dont know why it's not return joined event, can someone help?
{
"janus": "ack",
"session_id": 8568607942621781,
"transaction": "VeENHRbBTHWI"
}
Note that after this, I checked the participants inside room but it's still empty:
{
"janus": "success",
"session_id": 4397550774641519,
"transaction": "h8LgvUJxVXGk",
"sender": 8580331991428173,
"plugindata": {
"plugin": "janus.plugin.videoroom",
"data": {
"videoroom": "participants",
"room": 11,
"participants": []
}
}
}
All my https call work nomally(such as create video room/ destroy, listroom, list participants,...) but only joinroom api have trouble, here is my javascript code:
joinRoom = async(options) => {
await this.ensureAttachedToSessionId()
const promise = new Promise((resolve, reject) => {
const params = {
janus: 'message',
plugin: this.plugin,
session_id: this.sessionID,
handle_id: this.handleID,
transaction: JanusUtils.randomString(12),
body: {
request: 'join',
...options
}
}
console.log('join params', params)
fetch(this.janusUrl, {
method: 'POST',
body: JSON.stringify(params),
...JanusUtils.defaultHeader()
}).then(result => result.json())
.then(result => {
resolve(result)
})
.catch(error => { reject(error) })
})
return promise
}
Once you get that "ack" response you can use GET
/janus/12345678endpoint to get the "joined" event you expect. 12345678 - is your session ID. This is because requests like "join" are async. This what the docs say.Also check this article https://janus.conf.meetecho.com/docs/rest.htm. This is shows how to use Janus REST API
You can establish a long polling request to poll for events. However, I would recomment to take a look on Janode. https://github.com/meetecho/janode. It has great examples built in JS.