Skip to content

Commit

Permalink
ULMS-3116 Added enterClassroom method to ulms client
Browse files Browse the repository at this point in the history
ULMS-3116 Added enterClassroom method to ulms client

---------

Co-authored-by: Vladimir Berdnikov <[email protected]>
  • Loading branch information
alexkonst and dkvovik authored Jun 19, 2024
1 parent 4c88238 commit 2838a4f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulms/api-clients",
"version": "7.8.1",
"version": "7.9.0",
"description": "JavaScript API clients for ULMS platform",
"keywords": [],
"homepage": "https://github.com/foxford/ulms-api-clients-js#readme",
Expand Down
37 changes: 27 additions & 10 deletions src/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable sonarjs/no-duplicate-string */
import Backoff from './backoff'
import Broker from './broker'
import { TimeoutError } from './error'

// eslint-disable-next-line default-param-last
Expand Down Expand Up @@ -59,7 +61,6 @@ export const sleep = async (ms) =>
export async function enterServiceRoom(
client,
httpClient,
eventName,
roomId,
id,
label,
Expand All @@ -68,18 +69,33 @@ export async function enterServiceRoom(
) {
const backoff = new Backoff()
const isTransportConnected = () => client.mqtt.connected
let enterRoomSuccess = false
let enterEventRoomSuccess = false
let enterConferenceRoomSuccess = false
let response

const handler = (event) => {
const handlerEnterEventRoom = (event) => {
if (event.data.agent_id === id) {
enterRoomSuccess = true
console.log('[handlerEnterEventRoom] enterEventRoomSuccess')
enterEventRoomSuccess = true

client.off(eventName, handler)
client.off(Broker.events.EVENT_ROOM_ENTER, handlerEnterEventRoom)
}
}

client.on(eventName, handler)
const handlerEnterConferenceRoom = (event) => {
if (event.data.agent_id === id) {
console.log('[handlerEnterConferenceRoom] enterConferenceRoomSuccess')
enterConferenceRoomSuccess = true

client.off(
Broker.events.CONFERENCE_ROOM_ENTER,
handlerEnterConferenceRoom,
)
}
}

client.on(Broker.events.EVENT_ROOM_ENTER, handlerEnterEventRoom)
client.on(Broker.events.CONFERENCE_ROOM_ENTER, handlerEnterConferenceRoom)

try {
// eslint-disable-next-line no-constant-condition
Expand All @@ -89,25 +105,26 @@ export async function enterServiceRoom(
}

// eslint-disable-next-line no-await-in-loop
response = await httpClient.enterRoom(roomId, label)
response = await httpClient.enterClassroom(roomId, label)

if (!isTransportConnected()) {
throw new Error('MQTT client disconnected')
}

if (enterRoomSuccess) break
if (enterEventRoomSuccess && enterConferenceRoomSuccess) break

// eslint-disable-next-line no-await-in-loop
await sleep(backoff.value)

backoff.next()

if (enterRoomSuccess) break
if (enterEventRoomSuccess && enterConferenceRoomSuccess) break

trackEvent('Debug', `${serviceName}.Subscription.Retry`)
}
} catch (error) {
client.off(eventName, handler)
client.off(Broker.events.EVENT_ROOM_ENTER, handlerEnterEventRoom)
client.off(Broker.events.CONFERENCE_ROOM_ENTER, handlerEnterConferenceRoom)

backoff.reset()

Expand Down
1 change: 1 addition & 0 deletions src/http-conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class HTTPConference extends BasicClient {

/**
* Enter room
* @deprecated
* @param roomId
* @returns {Promise}
*/
Expand Down
3 changes: 2 additions & 1 deletion src/http-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const eventEndpoints = {
editionsDelete: (id) => `/editions/${id}`,
editionsList: (id) => `/event_rooms/${id}/editions`,
eventsCreate: (id) => `/event_rooms/${id}/events`,
eventsRemove: (id) => `/event_rooms/${id}/events`,
eventsList: (id) => `/event_rooms/${id}/events`,
eventsRemove: (id) => `/event_rooms/${id}/events`,
roomEnter: (id) => `/event_rooms/${id}/enter`,
roomRead: (id) => `/event_rooms/${id}`,
roomState: (id) => `/event_rooms/${id}/state`,
Expand Down Expand Up @@ -56,6 +56,7 @@ class HTTPEvent extends BasicClient {

/**
* Enter room
* @deprecated
* @param id
* @param {String} agentLabel
* @param {Boolean} broadcastSubscription
Expand Down
12 changes: 12 additions & 0 deletions src/ulms.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ class ULMS extends BasicClient {
)
}

/**
* Perform enter to classroom
* @param {string} classroomId
* @param {string} agentLabel
* @returns {Promise}
*/
enterClassroom(classroomId, agentLabel) {
return this.post(`${this.baseUrl}/classrooms/${classroomId}/enter`, {
agent_label: agentLabel,
})
}

/**
* Fetch token data for NATS
* @param {string} classroomId
Expand Down

0 comments on commit 2838a4f

Please sign in to comment.