Last active
April 16, 2022 17:39
-
-
Save jsinai/26ec467dc910fa3ce31b1c3350799e47 to your computer and use it in GitHub Desktop.
A canonical BrightScript that shows how to launch an HTML site that is resident on the player. The entry point is index.html. Works in tandem with canonical.css.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Main(args) | |
url$ = "file:///index.html" | |
if args <> invalid and args.Count() > 0 then | |
url$ = args[0] | |
end if | |
print "url = ";url$ | |
DoCanonicalInit() | |
CreateHtmlWidget(url$) | |
HandleEvents() | |
End Sub | |
Function DoCanonicalInit() | |
gaa = GetGlobalAA() | |
EnableZoneSupport(1) | |
' Enable mouse cursor | |
gaa.touchScreen = CreateObject("roTouchScreen") | |
gaa.touchScreen.EnableCursor(true) | |
gaa.mp = CreateObject("roMessagePort") | |
gaa.gpioPort = CreateObject("roGpioControlPort") | |
gaa.gpioPort.SetPort(gaa.mp) | |
gaa.vm = CreateObject("roVideoMode") | |
gaa.vm.setMode("auto") | |
' set DWS on device | |
nc = CreateObject("roNetworkConfiguration", 0) | |
if type(nc) <> "roNetworkConfiguration" then | |
nc = CreateObject("roNetworkConfiguration", 1) | |
endif | |
if type(nc) = "roNetworkConfiguration" then | |
dwsAA = CreateObject("roAssociativeArray") | |
dwsAA["port"] = "80" | |
nc.SetupDWS(dwsAA) | |
nc.Apply() | |
endif | |
gaa.hp = CreateObject("roNetworkHotplug") | |
gaa.hp.setPort(gaa.mp) | |
End Function | |
Sub CreateHtmlWidget(url$ as String) | |
gaa = GetGlobalAA() | |
width=gaa.vm.GetResX() | |
height=gaa.vm.GetResY() | |
rect=CreateObject("roRectangle", 0, 0, width, height) | |
config = { | |
' Uncomment if using node.js features | |
' nodejs_enabled: true | |
inspector_server: { port: 2999 } | |
' Uncomment if communicating with BrightScript http server | |
' security_params: { websecurity: false } | |
brightsign_js_objects_enabled: true | |
user_stylesheet: "sd:/canonical.css" | |
mouse_enabled: true | |
hwz_default: "on" | |
port: gaa.mp | |
url: url$ | |
} | |
gaa.htmlWidget = CreateObject("roHtmlWidget", rect, config) | |
End Sub | |
Sub HandleEvents() | |
gaa = GetGlobalAA() | |
receivedIpAddr = false | |
nc = CreateObject("roNetworkConfiguration", 0) | |
currentConfig = nc.GetCurrentConfig() | |
if currentConfig.ip4_address <> "" then | |
' We already have an IP addr | |
receivedIpAddr = true | |
print "=== BS: already have an IP addr: ";currentConfig.ip4_address | |
end if | |
receivedLoadFinished = false | |
while true | |
ev = wait(0, gaa.mp) | |
print "=== BS: Received event ";type(ev) | |
if type(ev) = "roNetworkAttached" then | |
print "=== BS: Received roNetworkAttached" | |
receivedIpAddr = true | |
else if type(ev) = "roHtmlWidgetEvent" then | |
eventData = ev.GetData() | |
if type(eventData) = "roAssociativeArray" and type(eventData.reason) = "roString" then | |
if eventData.reason = "load-error" then | |
print "=== BS: HTML load error: "; eventData.message | |
else if eventData.reason = "load-finished" then | |
print "=== BS: Received load finished" | |
receivedLoadFinished = true | |
else if eventData.reason = "message" then | |
' To use this: msgPort.PostBSMessage({text: "my message"}); | |
endif | |
else | |
print "=== BS: Unknown eventData: "; type(eventData) | |
endif | |
else if type(ev) = "roGpioButton" then | |
if ev.GetInt() = 12 then stop | |
else | |
print "=== BS: Unhandled event: "; type(ev) | |
end if | |
if receivedIpAddr and receivedLoadFinished then | |
print "=== BS: OK to show HTML, showing widget now" | |
gaa.htmlWidget.Show() | |
gaa.htmlWidget.PostJSMessage({msgtype:"htmlloaded"}) | |
receivedIpAddr = false | |
receivedLoadFinished = false | |
endif | |
endwhile | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: white; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment