Skip to content

Commit

Permalink
ULMS-3199 Added new entity events
Browse files Browse the repository at this point in the history
  • Loading branch information
dkvovik committed Aug 1, 2024
1 parent abebb19 commit 6800afd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 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.9.7",
"version": "7.9.8",
"description": "JavaScript API clients for ULMS platform",
"keywords": [],
"homepage": "https://github.com/foxford/ulms-api-clients-js#readme",
Expand Down
8 changes: 8 additions & 0 deletions src/broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import Codec from './codec'
const entityEventsEnum = {
AGENT_UPDATE: 'agent.update',
AGENT_WRITER_CONFIG_UPDATE: 'agent_writer_config.update',
CLASSROOM_CLOSE: 'classroom.close',
CLASSROOM_ENTER: 'classroom.enter',
CLASSROOM_LEAVE: 'classroom.leave',
CLASSROOM_UPDATE: 'classroom.update',
CONFERENCE_ROOM_CLOSE: 'conference_room.close',
CONFERENCE_ROOM_ENTER: 'conference_room.enter',
CONFERENCE_ROOM_LEAVE: 'conference_room.leave',
Expand All @@ -44,6 +48,10 @@ class Broker {
* @returns {{
* AGENT_UPDATE: string,
* AGENT_WRITER_CONFIG_UPDATE: string,
* CLASSROOM_CLOSE: string,
* CLASSROOM_ENTER: string,
* CLASSROOM_LEAVE: string,
* CLASSROOM_UPDATE: string,
* CONFERENCE_ROOM_CLOSE: string,
* CONFERENCE_ROOM_ENTER: string,
* CONFERENCE_ROOM_LEAVE: string,
Expand Down
24 changes: 22 additions & 2 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function enterServiceRoom(
const isTransportConnected = () => client.mqtt.connected
let enterEventRoomSuccess = false
let enterConferenceRoomSuccess = false
let enterClassroomSuccess = false
let response

const handlerEnterEventRoom = (event) => {
Expand All @@ -94,8 +95,18 @@ export async function enterServiceRoom(
}
}

const handlerEnterClassroom = (event) => {
if (event.data.agent_id === id) {
console.log('[handlerEnterClassroom] enterClassroomSuccess')
enterClassroomSuccess = true

client.off(Broker.events.CLASSROOM_ENTER, handlerEnterClassroom)
}
}

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

try {
// eslint-disable-next-line no-constant-condition
Expand All @@ -111,20 +122,29 @@ export async function enterServiceRoom(
throw new Error('MQTT client disconnected')
}

if (enterEventRoomSuccess && enterConferenceRoomSuccess) break
if (
enterClassroomSuccess ||
(enterEventRoomSuccess && enterConferenceRoomSuccess)
)
break

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

backoff.next()

if (enterEventRoomSuccess && enterConferenceRoomSuccess) break
if (
enterClassroomSuccess ||
(enterEventRoomSuccess && enterConferenceRoomSuccess)
)
break

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

backoff.reset()

Expand Down

0 comments on commit 6800afd

Please sign in to comment.