diff --git a/package-lock.json b/package-lock.json index a493712..293eb0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ulms/api-clients", - "version": "7.9.7", + "version": "7.9.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ulms/api-clients", - "version": "7.9.7", + "version": "7.9.8", "license": "MIT", "dependencies": { "axios": "1.6.2", diff --git a/package.json b/package.json index 3f22fdd..1834694 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/broker.js b/src/broker.js index 9e86758..6c8c221 100644 --- a/src/broker.js +++ b/src/broker.js @@ -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', @@ -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, diff --git a/src/common.js b/src/common.js index c43dba6..cdd832f 100644 --- a/src/common.js +++ b/src/common.js @@ -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) => { @@ -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 @@ -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()