-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.brs
194 lines (189 loc) · 6.57 KB
/
Main.brs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
sub main(args)
'######################### DEVELOPER VARIABLES ##########################
showDeviceInfo = false ' show device info in the console
showAppInfo = false ' show app info in the console
showBandwidth = false ' show bandwidth utilization
showHttpErrors = false ' show http and url errors
'########################################################################
'########################### DEVICE/APP INFO ############################
' create device info object
deviceInfo = setDeviceInfo()
' create app/manifest info object
appInfo = setAppInfo()
' print device info to console
if showDeviceInfo then getDeviceInfo(deviceInfo)
' print app info to console
if showAppInfo then getAppInfo(appInfo)
'########################################################################
'########################## SCENEGRAPH SETUP ############################
' create message event listener
port = createObject("roMessagePort")
' create root scenegraph node
screen = createObject("roSGScreen")
' set global values using info obtained from device and app
setGlobals(screen, deviceInfo, appInfo, args)
' set the message port for screen events
screen.setMessagePort(port)
' create the initial scenegraph object
scene = screen.createScene("HomeScene")
' render the initial scenegraph object
screen.show()
' observe changes to exitApp interface on HomeScene
scene.observeField("exitApp", port)
'########################################################################
'########################## LOG SYSTEM EVENTS ###########################
' create system logging events
syslog = CreateObject("roSystemLog")
' set the message port for logging events
syslog.setMessagePort(port)
' enable http error logging
syslog.EnableType("http.error")
' enable bandwidth measurement logging
syslog.EnableType("bandwidth.minute")
'########################################################################
'################### START APP AND LISTEN FOR EVENTS ####################
' create loop to track opening and closing of app
while(true)
' wait indefinitely
msg = wait(0, port)
' get message type
msgType = type(msg)
' check exitApp field on HomeScene - closes app (ends while loop) when set to true
if (scene.exitApp)
' exit app / end while loop
return
end if
' check if the message type is logging event and if developer variables are true
if (msgType = "roSystemLogEvent" and (showHttpErrors or showBandwidth))
' Handle the roSystemLogEvents:
i = msg.GetInfo()
if (i.LogType = "http.error" and showHttpErrors)
? "HTTP error: "; i.HttpCode
? "Status error: "; i.Status
? "URL error: "; i.origUrl
? "IP: "; i.TargetIp
? " "
else if (i.LogType = "bandwidth.minute" and showBandwidth)
bandwidth = i.Bandwidth / 1000
? "Bandwidth: "; bandwidth.toStr() + " Mbps"
? " "
end if
end if
end while
'########################################################################
end sub
function setDeviceInfo()
' create device info object
deviceInfo = createObject("roDeviceInfo")
' create HDMI info object
hdmiInfo = createObject("roHdmiStatus")
' check for an active version of hdcp or a device type of "TV" - all others refer to a set top box
if len(hdmiInfo.getHdcpVersion()) > 0 or deviceInfo.getModelType() = "TV" then hdcpStatus = true else hdcpStatus = false
' get OS version
os = deviceInfo.getOSVersion().major + "." + deviceInfo.getOSVersion().minor
' determine if device will return internet status
internetStatus = findMemberFunction(deviceInfo, "getInternetStatus")
if (internetStatus <> invalid)
' required minimum OS version 10.0
internet = deviceInfo.getInternetStatus()
else
internet = deviceInfo.getLinkStatus()
end if
device = {
"id": deviceInfo.GetChannelClientId(),
"model": deviceInfo.getModel(),
"type": deviceInfo.getModelType(),
"os": os.toFloat(),
"language": deviceInfo.getCurrentLocale(),
"graphics": deviceInfo.getGraphicsPlatform(),
"display": {
"name": deviceInfo.getModelDisplayName(),
"type": deviceInfo.GetDisplayType(),
"ui": {
"width": deviceInfo.getUIResolution().width,
"height": deviceInfo.getUIResolution().height,
"name": deviceInfo.getUIResolution().name
},
"video": deviceInfo.getVideoMode()
},
"network": {
"internet": internet,
"type": deviceInfo.getConnectionType(),
"externalIP": deviceInfo.getExternalIp()
},
"hdmi": {
"connected": hdmiInfo.isConnected(),
"hdcp": hdcpStatus
}
}
return device
end function
function setAppInfo()
appInfo = createObject("roAppInfo")
app = {
"id": appInfo.getID(),
"isDev": appInfo.isDev(),
"devId": appInfo.getDevID(),
"title": appInfo.getTitle(),
"version": appInfo.getVersion()
}
return app
end function
sub getDeviceInfo(deviceInfo)
' show information about device
? "- - - - - - - - - - - - - - - - - - -"
? "Model: "; deviceInfo.model
? "Type: "; deviceInfo.type
? "OS Version: "; deviceInfo.os
? "Language: "; deviceInfo.language
? "Graphics: "; deviceInfo.graphics
? "Display Name: "; deviceInfo.display.name
? "Display Type: "; deviceInfo.display.type
? "UI Resolution: "; deviceInfo.display.ui.name
? "Video Mode: "; deviceInfo.display.video
? "Internet Status: "; deviceInfo.network.internet
? "Connection Type: "; deviceInfo.network.type
? "External IP: "; deviceInfo.network.externalIP
? "HDMI Status: "; deviceInfo.hdmi.connected
? "HDCP Valid: "; deviceInfo.hdmi.hdcp
? "- - - - - - - - - - - - - - - - - - -"
? " "
end sub
sub getAppInfo(appInfo)
' show information about app
? "- - - - - - - - - - - - - - - - - - -"
? "App ID: "; appInfo.id
? "Is Dev: "; appInfo.isDev
? "Dev ID: "; appInfo.devId
? "Title: "; appInfo.title
? "Version: "; appInfo.version
? "- - - - - - - - - - - - - - - - - - -"
? " "
end sub
sub setGlobals(screen, deviceInfo, appInfo, deepLinkArgs)
' get the global reference object
m.global = screen.getGlobalNode()
' assign variables to global object
m.global.addFields({
"deviceId": deviceInfo.id,
"model": deviceInfo.model,
"os": deviceInfo.os,
"internet": deviceInfo.network.internet,
"language": deviceInfo.language,
"graphics": deviceInfo.graphics,
"ui": deviceInfo.display.ui,
"hdcp": deviceInfo.hdmi.hdcp,
"deeplink": getDeepLinks(deepLinkArgs)
})
end sub
function getDeepLinks(args) as object
deeplink = invalid
' check if both contentId and mediaType are valid
if (args.contentId <> invalid and args.mediaType <> invalid)
deeplink = {
id: args.contentId
type: args.mediaType
}
end if
return deeplink
end function