Skip to content

Commit

Permalink
removed unused subscribeWithNotification method
Browse files Browse the repository at this point in the history
  • Loading branch information
dkvovik committed Jun 19, 2024
1 parent 89f5769 commit 752530d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 76 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-dev.5-ULMS-3116",
"version": "7.8.1-dev.6-ULMS-3116",
"description": "JavaScript API clients for ULMS platform",
"keywords": [],
"homepage": "https://github.com/foxford/ulms-api-clients-js#readme",
Expand Down
75 changes: 2 additions & 73 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,17 @@ export async function enterServiceRoom(
let response

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

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

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

client.off(
Expand Down Expand Up @@ -184,70 +180,3 @@ export const timeout = async (delay) => {

return promise
}

export async function subscribeWithNotification(
client,
httpClient,
eventName,
roomId,
id,
label,
trackEvent,
serviceName,
) {
const backoff = new Backoff()
const isTransportConnected = () => client.mqtt.connected
let subscribeRoomSuccess = false
let response

const handler = (event) => {
if (event.data.agent_id === id) {
console.log(
'[subscribeWithNotification] subscribeRoomSuccess = true',
eventName,
)
subscribeRoomSuccess = true

client.off(eventName, handler)
}
}

client.on(eventName, handler)

try {
// eslint-disable-next-line no-constant-condition
while (true) {
if (!isTransportConnected()) {
throw new Error('MQTT client disconnected')
}

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

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

if (subscribeRoomSuccess) break

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

backoff.next()

if (subscribeRoomSuccess) break

trackEvent('Debug', `${serviceName}.Subscription.Retry`)
}
} catch (error) {
client.off(eventName, handler)

backoff.reset()

throw error
}

backoff.reset()

return response
}

0 comments on commit 752530d

Please sign in to comment.