Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate device id on login and use for API calls #1441

Merged
merged 4 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/GetPlaybackInfoTask.brs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end function
' Returns an array of playback info to be displayed during playback.
' In the future, with a custom playback info view, we can return an associated array.
sub getPlaybackInfoTask()
sessions = api.sessions.Get()
sessions = api.sessions.Get({ "deviceId": m.global.device.serverDeviceName })

m.playbackInfo = ItemPostPlaybackInfo(m.top.videoID)

Expand Down
4 changes: 0 additions & 4 deletions source/ShowScenes.brs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ function LoginFlow()
else
print "Success! Auth token is still valid"
session.user.Login(currentUser, true)
session.user.LoadUserPreferences()
LoadUserAbilities()
return true
end if
Expand All @@ -132,7 +131,6 @@ function LoginFlow()
if isValid(userData)
print "login success!"
session.user.Login(userData, true)
session.user.LoadUserPreferences()
LoadUserAbilities()
return true
else
Expand Down Expand Up @@ -175,7 +173,6 @@ function LoginFlow()
if isValid(userData)
print "login success!"
session.user.Login(userData, true)
session.user.LoadUserPreferences()
LoadUserAbilities()
return true
else
Expand All @@ -201,7 +198,6 @@ function LoginFlow()
goto start_login
end if

session.user.LoadUserPreferences()
LoadUserAbilities()
m.global.sceneManager.callFunc("clearScenes")

Expand Down
3 changes: 2 additions & 1 deletion source/VideoPlayer.brs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ end sub
' Returns an array of playback info to be displayed during playback.
' In the future, with a custom playback info view, we can return an associated array.
function GetPlaybackInfo()
sessions = api.sessions.Get()
sessions = api.sessions.Get({ "deviceId": m.global.device.serverDeviceName })
cewert marked this conversation as resolved.
Show resolved Hide resolved

if isValid(sessions) and sessions.Count() > 0
return GetTranscodingStats(sessions[0])
end if
Expand Down
6 changes: 1 addition & 5 deletions source/api/baserequest.brs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,7 @@ function authRequest(request as object) as object
auth = auth + ", UserId=" + QUOTE + m.global.session.user.id + QUOTE
end if

if m.global.session.user <> invalid and m.global.session.user.friendlyName <> invalid
auth = auth + ", DeviceId=" + QUOTE + m.global.device.id + m.global.session.user.friendlyName + QUOTE
else
auth = auth + ", DeviceId=" + QUOTE + m.global.device.id + QUOTE
end if
auth = auth + ", DeviceId=" + QUOTE + m.global.device.serverDeviceName + QUOTE

if m.global.session.user.authToken <> invalid
auth = auth + ", Token=" + QUOTE + m.global.session.user.authToken + QUOTE
Expand Down
2 changes: 1 addition & 1 deletion source/api/sdk.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ namespace api
end function

' Gets a list of sessions.
function Get(params = { "deviceId": m.global.device.id } as object)
1hitsong marked this conversation as resolved.
Show resolved Hide resolved
function Get(params = { "deviceId": m.global.device.serverDeviceName } as object)
req = APIRequest("/sessions", params)
return getJson(req)
end function
Expand Down
1 change: 1 addition & 0 deletions source/utils/globals.brs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ sub SaveDeviceToGlobal()
uuid: deviceInfo.GetRandomUUID(),
name: displayName,
friendlyName: filteredFriendly,
serverDeviceName: deviceInfo.getChannelClientID(),
model: deviceInfo.GetModel(),
modelType: deviceInfo.GetModelType(),
modelDetails: deviceInfo.GetModelDetails(),
Expand Down
17 changes: 17 additions & 0 deletions source/utils/session.bs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,24 @@ namespace session
set_user_setting("token", tmpSession.user.authToken)
set_user_setting("username", tmpSession.user.name)
end if

session.user.LoadUserPreferences()
end sub

' Sets the global service device name value used by the API
1hitsong marked this conversation as resolved.
Show resolved Hide resolved
sub SetServerDeviceName()
if isValid(m.global.session.user) and isValid(m.global.session.user.friendlyName)
m.global.device.serverDeviceName = m.global.device.id + m.global.session.user.friendlyName
else
m.global.device.serverDeviceName = m.global.device.id
1hitsong marked this conversation as resolved.
Show resolved Hide resolved
end if
end sub

' Load and parse Display Settings from server
sub LoadUserPreferences()
' Save device id so we don't calculate it every time we need it
session.user.SetServerDeviceName()

id = m.global.session.user.id
' Currently using client "emby", which is what website uses so we get same Display prefs as web.
' May want to change to specific Roku display settings
Expand Down Expand Up @@ -337,6 +351,9 @@ namespace session
session.user.settings.Save(item, get_setting(item))
end if
end for

' Reset server device name state
session.user.SetServerDeviceName()
end sub

' Saves the user setting to the global session.
Expand Down