Move devices array to lounge api class

This commit is contained in:
Brahim Hadriche committed 2024-02-22 18:58:47 -05:00
1 parent f38115171b
commit 4f3512023f
2 files changed
+7 -34

No files matched your search

@@ -27,6 +27,7 @@ class LoungeApi
public loungeToken public loungeToken
public sessionId public sessionId
public gSessionId public gSessionId
public devices
private ofs private ofs
private lastProcessedCommandIndex = -1 private lastProcessedCommandIndex = -1
@@ -46,6 +47,7 @@ class LoungeApi
m.ofs = 0 m.ofs = 0
m.poller = invalid m.poller = invalid
m.outgoingMessagesRequests = {} m.outgoingMessagesRequests = {}
m.devices = {}
commandHandlers = {} commandHandlers = {}
commandHandlers[COMMAND_TYPE_NOOP] = m.HandleIgnoreCommand commandHandlers[COMMAND_TYPE_NOOP] = m.HandleIgnoreCommand
@@ -55,13 +57,13 @@ class LoungeApi
commandHandlers[COMMAND_TYPE_DPAD_COMMAND] = m.HandleIgnoreCommand commandHandlers[COMMAND_TYPE_DPAD_COMMAND] = m.HandleIgnoreCommand
commandHandlers[COMMAND_TYPE_VOICE_COMMAND] = m.HandleIgnoreCommand commandHandlers[COMMAND_TYPE_VOICE_COMMAND] = m.HandleIgnoreCommand
commandHandlers[COMMAND_TYPE_ON_USER_ACTIVITY] = m.HandleIgnoreCommand commandHandlers[COMMAND_TYPE_ON_USER_ACTIVITY] = m.HandleIgnoreCommand
commandHandlers[COMMAND_TYPE_REMOTE_DISCONNECTED] = m.HandleIgnoreCommand
commandHandlers[COMMAND_TYPE_GET_NOW_PLAYING] = m.HandleGetPlayingNow commandHandlers[COMMAND_TYPE_GET_NOW_PLAYING] = m.HandleGetPlayingNow
commandHandlers[COMMAND_TYPE_SESSION_ID] = m.HandleSessionId commandHandlers[COMMAND_TYPE_SESSION_ID] = m.HandleSessionId
commandHandlers[COMMAND_TYPE_G_SESSION_ID] = m.HandleGSessionId commandHandlers[COMMAND_TYPE_G_SESSION_ID] = m.HandleGSessionId
commandHandlers[COMMAND_TYPE_LOUNGE_STATUS] = m.HandleLoungeStatus commandHandlers[COMMAND_TYPE_LOUNGE_STATUS] = m.HandleLoungeStatus
commandHandlers[COMMAND_TYPE_REMOTE_CONNECTED] = m.HandleRemoteConnected commandHandlers[COMMAND_TYPE_REMOTE_CONNECTED] = m.HandleRemoteConnected
commandHandlers[COMMAND_TYPE_REMOTE_DISCONNECTED] = m.HandleRemoteDisconnected
commandHandlers[COMMAND_TYPE_SET_VOLUME] = m.HandleSetVolume commandHandlers[COMMAND_TYPE_SET_VOLUME] = m.HandleSetVolume
commandHandlers[COMMAND_TYPE_SET_PLAYLIST] = m.HandleSetPlaylist commandHandlers[COMMAND_TYPE_SET_PLAYLIST] = m.HandleSetPlaylist
commandHandlers[COMMAND_TYPE_UPDATE_PLAYLIST] = m.HandleUpdatePlaylist commandHandlers[COMMAND_TYPE_UPDATE_PLAYLIST] = m.HandleUpdatePlaylist
@@ -336,12 +338,9 @@ class LoungeApi
return return
end if end if
devicesDict = {}
for each device in devices for each device in devices
devicesDict[device.id] = device m.devices[device.id] = device
end for end for
m.loungeServiceNode.devices = devicesDict
end function end function
function HandleRemoteConnected(commandId as integer, commandType as string, commandArgs as object, messagesToSend as object) as void function HandleRemoteConnected(commandId as integer, commandType as string, commandArgs as object, messagesToSend as object) as void
@@ -352,19 +351,13 @@ class LoungeApi
return return
end if end if
devices = m.loungeServiceNode.devices if m.devices.DoesExist(id)
if devices = invalid device = m.devices[id]
devices = {}
end if
if devices.DoesExist(id)
device = devices[id]
device.Append(newDevice) device.Append(newDevice)
newDevice = device newDevice = device
end if end if
devices[id] = newDevice m.devices[id] = newDevice
m.loungeServiceNode.devices = devices
userName = newDevice.user userName = newDevice.user
deviceName = newDevice.name deviceName = newDevice.name
@@ -373,24 +366,6 @@ class LoungeApi
LoungeDeviceConnected.ShowNotifcation(m.notificationsNode, deviceName, userName, userAvatarUri) LoungeDeviceConnected.ShowNotifcation(m.notificationsNode, deviceName, userName, userAvatarUri)
end function end function
function HandleRemoteDisconnected(commandId as integer, commandType as string, commandArgs as object, messagesToSend as object) as void
LogInfo(commandType)
device = commandArgs
id = device.id
if StringUtils.IsNullOrEmpty(id)
return
end if
devices = m.loungeServiceNode.devices
if devices = invalid
devices = {}
end if
if devices.Delete(id)
m.loungeServiceNode.devices = devices
end if
' TODO:P1 disconnect notification
end function
function HandleSetVolume(commandId as integer, commandType as string, commandArgs as object, messagesToSend as object) as void function HandleSetVolume(commandId as integer, commandType as string, commandArgs as object, messagesToSend as object) as void
player = m.videoQueueNode.player player = m.videoQueueNode.player
if player = invalid if player = invalid
@@ -6,8 +6,6 @@
<field id="screenId" type="string" /> <field id="screenId" type="string" />
<field id="loungeToken" type="string" /> <field id="loungeToken" type="string" />
<field id="devices" type="assocarray" />
<field id="join" type="boolean" alwaysNotify="true" /> <field id="join" type="boolean" alwaysNotify="true" />
<field id="outgoingMessages" type="array" alwaysNotify="true" /> <field id="outgoingMessages" type="array" alwaysNotify="true" />