Skip to content

Commit c642728

Browse files
authored
Merge pull request #2345 from SmartThingsCommunity/bugfix/sonos-oauth-reconnect
Bugfix/sonos oauth reconnect
2 parents fcdc5f8 + 0095654 commit c642728

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/SmartThings/sonos/src/api/sonos_websocket_router.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ cosock.spawn(function()
4444
if wss ~= nil then
4545
log.trace(string.format("Closing websocket for player %s", unique_key))
4646
wss:close(CloseCode.normal(), "Shutdown requested by client")
47+
local ws_id = wss.id
48+
for _, uuid in ipairs((listener_ids_for_socket[ws_id] or {})) do
49+
local listener = listeners[uuid]
50+
51+
if listener ~= nil then
52+
listener.on_close(uuid)
53+
end
54+
listeners[uuid] = nil
55+
end
56+
listener_ids_for_socket[ws_id] = nil
4757
end
4858
websockets[unique_key] = nil
4959
end
@@ -292,17 +302,7 @@ function SonosWebSocketRouter.close_socket_for_player(target)
292302
local ws = websockets[target]
293303

294304
if ws ~= nil then
295-
local ws_id = ws.id
296305
table.insert(pending_close, target)
297-
for _, uuid in ipairs((listener_ids_for_socket[ws_id] or {})) do
298-
local listener = listeners[uuid]
299-
300-
if listener ~= nil then
301-
listener.on_close(uuid)
302-
end
303-
listeners[uuid] = nil
304-
end
305-
listener_ids_for_socket[ws_id] = nil
306306
return true
307307
else
308308
return nil, string.format("No currently open connection for %s", target)

0 commit comments

Comments
 (0)