1 parent
cf6d89f44f
commit
190dcdffe3
37 files changed
+416
-290
No files matched your search
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- New logger: less features, and less rendezvous
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- `roku-log` package
|
||||||
|
|
||||||
## [0.12.0] - 2023-09-17
|
## [0.12.0] - 2023-09-17
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -39,7 +39,6 @@
|
|||||||
],
|
],
|
||||||
"lintConfig": "./config/bslint.jsonc",
|
"lintConfig": "./config/bslint.jsonc",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"roku-log-bsc-plugin",
|
|
||||||
"@rokucommunity/bslint",
|
"@rokucommunity/bslint",
|
||||||
"../tools/bs-plugins/asynctask-plugin.ts",
|
"../tools/bs-plugins/asynctask-plugin.ts",
|
||||||
"../tools/bs-plugins/manifest-edit-plugin.ts",
|
"../tools/bs-plugins/manifest-edit-plugin.ts",
|
||||||
@@ -48,7 +47,8 @@
|
|||||||
"../tools/bs-plugins/oninit-plugin.ts",
|
"../tools/bs-plugins/oninit-plugin.ts",
|
||||||
"../tools/bs-plugins/track-transpiled-plugin.ts",
|
"../tools/bs-plugins/track-transpiled-plugin.ts",
|
||||||
"../tools/bs-plugins/json-yaml-plugin.ts",
|
"../tools/bs-plugins/json-yaml-plugin.ts",
|
||||||
"../tools/bs-plugins/validation-plugin.ts"
|
"../tools/bs-plugins/validation-plugin.ts",
|
||||||
|
"../tools/bs-plugins/logger-plugin.ts"
|
||||||
],
|
],
|
||||||
"retainStagingDir": true,
|
"retainStagingDir": true,
|
||||||
"require": [
|
"require": [
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
"!**/*.transpiled.*"
|
"!**/*.transpiled.*"
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"roku-log-bsc-plugin",
|
|
||||||
"@rokucommunity/bslint",
|
"@rokucommunity/bslint",
|
||||||
"rooibos-roku",
|
"rooibos-roku",
|
||||||
"../tools/bs-plugins/asynctask-plugin.ts",
|
"../tools/bs-plugins/asynctask-plugin.ts",
|
||||||
@@ -24,7 +23,8 @@
|
|||||||
"../tools/bs-plugins/oninit-plugin.ts",
|
"../tools/bs-plugins/oninit-plugin.ts",
|
||||||
"../tools/bs-plugins/track-transpiled-plugin.ts",
|
"../tools/bs-plugins/track-transpiled-plugin.ts",
|
||||||
"../tools/bs-plugins/json-yaml-plugin.ts",
|
"../tools/bs-plugins/json-yaml-plugin.ts",
|
||||||
"../tools/bs-plugins/validation-plugin.ts"
|
"../tools/bs-plugins/validation-plugin.ts",
|
||||||
|
"../tools/bs-plugins/logger-plugin.ts"
|
||||||
],
|
],
|
||||||
"rooibos": {
|
"rooibos": {
|
||||||
"logLevel": 2,
|
"logLevel": 2,
|
||||||
|
|||||||
Generated
-95
@@ -25,7 +25,6 @@
|
|||||||
"ip": "^1.1.8",
|
"ip": "^1.1.8",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"roku-deploy": "^3.10.3",
|
"roku-deploy": "^3.10.3",
|
||||||
"roku-log-bsc-plugin": "^0.8.1",
|
|
||||||
"rooibos-roku": "^5.7.0",
|
"rooibos-roku": "^5.7.0",
|
||||||
"ropm": "^0.10.16",
|
"ropm": "^0.10.16",
|
||||||
"semver": "^7.5.4",
|
"semver": "^7.5.4",
|
||||||
@@ -2251,12 +2250,6 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/get-own-enumerable-property-symbols": {
|
|
||||||
"version": "3.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.2.tgz",
|
|
||||||
"integrity": "sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"node_modules/get-stdin": {
|
"node_modules/get-stdin": {
|
||||||
"version": "8.0.0",
|
"version": "8.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz",
|
||||||
@@ -2740,15 +2733,6 @@
|
|||||||
"node": ">=0.12.0"
|
"node": ">=0.12.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/is-obj": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
|
|
||||||
"integrity": "sha512-l4RyHgRqGN4Y3+9JHVrNqO+tN0rV5My76uW5/nuO4K1b6vw5G8d/cmFjP9tRfEsdhZNt0IFdZuK/c2Vr4Nb+Qg==",
|
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/is-path-cwd": {
|
"node_modules/is-path-cwd": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.2.0.tgz",
|
||||||
@@ -2767,15 +2751,6 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/is-regexp": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-regexp/-/is-regexp-1.0.0.tgz",
|
|
||||||
"integrity": "sha512-7zjFAPO4/gwyQAAgRRmqeEeyIICSdmCqa3tsVHMdBzaXXRiqopZL4Cyghg/XulGWrtABTpbnYYzzIRffLkP4oA==",
|
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/is-typedarray": {
|
"node_modules/is-typedarray": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||||
@@ -3999,62 +3974,6 @@
|
|||||||
"node": ">=4.0.0"
|
"node": ">=4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/roku-log-bsc-plugin": {
|
|
||||||
"version": "0.8.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/roku-log-bsc-plugin/-/roku-log-bsc-plugin-0.8.1.tgz",
|
|
||||||
"integrity": "sha512-GL/fM4vx1BCLHny9yC1RR81v8LY6FDAWx4jGkivGz36/wZfRDnM9MqSSIgJ4z7p0Jns4AL2o80MNd9Ytaulo/A==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"@types/node": "^16.18.10",
|
|
||||||
"source-map": "^0.7.3",
|
|
||||||
"stringify-object": "^3.3.0",
|
|
||||||
"vscode-languageserver": "~6.1.1",
|
|
||||||
"vscode-languageserver-protocol": "~3.15.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/roku-log-bsc-plugin/node_modules/@types/node": {
|
|
||||||
"version": "16.18.36",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.36.tgz",
|
|
||||||
"integrity": "sha512-8egDX8dE50XyXWH6C6PRCNkTP106DuUrvdrednFouDSmCi7IOvrqr0frznfZaHifHH/3aq/7a7v9N4wdXMqhBQ==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"node_modules/roku-log-bsc-plugin/node_modules/vscode-jsonrpc": {
|
|
||||||
"version": "5.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.0.1.tgz",
|
|
||||||
"integrity": "sha512-JvONPptw3GAQGXlVV2utDcHx0BiY34FupW/kI6mZ5x06ER5DdPG/tXWMVHjTNULF5uKPOUUD0SaXg5QaubJL0A==",
|
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.0.0 || >=10.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/roku-log-bsc-plugin/node_modules/vscode-languageserver": {
|
|
||||||
"version": "6.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-6.1.1.tgz",
|
|
||||||
"integrity": "sha512-DueEpkUAkD5XTR4MLYNr6bQIp/UFR0/IPApgXU3YfCBCB08u2sm9hRCs6DxYZELkk++STPjpcjksR2H8qI3cDQ==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"vscode-languageserver-protocol": "^3.15.3"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"installServerIntoExtension": "bin/installServerIntoExtension"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/roku-log-bsc-plugin/node_modules/vscode-languageserver-protocol": {
|
|
||||||
"version": "3.15.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.3.tgz",
|
|
||||||
"integrity": "sha512-zrMuwHOAQRhjDSnflWdJG+O2ztMWss8GqUUB8dXLR/FPenwkiBNkMIJJYfSN6sgskvsF0rHAoBowNQfbyZnnvw==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"vscode-jsonrpc": "^5.0.1",
|
|
||||||
"vscode-languageserver-types": "3.15.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/roku-log-bsc-plugin/node_modules/vscode-languageserver-types": {
|
|
||||||
"version": "3.15.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz",
|
|
||||||
"integrity": "sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"node_modules/rooibos-roku": {
|
"node_modules/rooibos-roku": {
|
||||||
"version": "5.7.0",
|
"version": "5.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/rooibos-roku/-/rooibos-roku-5.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/rooibos-roku/-/rooibos-roku-5.7.0.tgz",
|
||||||
@@ -4654,20 +4573,6 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/stringify-object": {
|
|
||||||
"version": "3.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/stringify-object/-/stringify-object-3.3.0.tgz",
|
|
||||||
"integrity": "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"get-own-enumerable-property-symbols": "^3.0.0",
|
|
||||||
"is-obj": "^1.0.1",
|
|
||||||
"is-regexp": "^1.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/strip-ansi": {
|
"node_modules/strip-ansi": {
|
||||||
"version": "6.0.1",
|
"version": "6.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
"ip": "^1.1.8",
|
"ip": "^1.1.8",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"roku-deploy": "^3.10.3",
|
"roku-deploy": "^3.10.3",
|
||||||
"roku-log-bsc-plugin": "^0.8.1",
|
|
||||||
"rooibos-roku": "^5.7.0",
|
"rooibos-roku": "^5.7.0",
|
||||||
"ropm": "^0.10.16",
|
"ropm": "^0.10.16",
|
||||||
"semver": "^7.5.4",
|
"semver": "^7.5.4",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<field id="launchArgs" type="assocarray" />
|
<field id="launchArgs" type="assocarray" />
|
||||||
<field id="inputArgs" type="assocarray" alwaysNotify="true" />
|
<field id="inputArgs" type="assocarray" alwaysNotify="true" />
|
||||||
<field id="playletLibLoadedUrl" type="assocarray" />
|
<field id="playletLibLoadedUrl" type="assocarray" />
|
||||||
|
<field id="systemLogEvent" type="assocarray" />
|
||||||
</interface>
|
</interface>
|
||||||
<script type="text/brightscript" uri="pkg:/source/Dialog.bs" />
|
<script type="text/brightscript" uri="pkg:/source/Dialog.bs" />
|
||||||
<script type="text/brightscript" uri="pkg:/source/Manifest.bs" />
|
<script type="text/brightscript" uri="pkg:/source/Manifest.bs" />
|
||||||
|
|||||||
@@ -16,16 +16,17 @@
|
|||||||
|
|
||||||
function Main(args as object) as void
|
function Main(args as object) as void
|
||||||
screen = CreateObject("roSGScreen")
|
screen = CreateObject("roSGScreen")
|
||||||
m.port = CreateObject("roMessagePort")
|
port = CreateObject("roMessagePort")
|
||||||
screen.setMessagePort(m.port)
|
screen.setMessagePort(port)
|
||||||
m.global = screen.getGlobalNode()
|
m.global = screen.getGlobalNode()
|
||||||
|
m.global.addFields({ port: port })
|
||||||
|
|
||||||
ClearPlayletLibUrlsIfNeeded(args)
|
ClearPlayletLibUrlsIfNeeded(args)
|
||||||
|
|
||||||
scene = screen.CreateScene("BootstrapScene")
|
scene = screen.CreateScene("BootstrapScene")
|
||||||
screen.show()
|
screen.show()
|
||||||
|
|
||||||
scene.ObserveField("exitChannel", m.port)
|
scene.ObserveField("exitChannel", port)
|
||||||
scene.launchArgs = args
|
scene.launchArgs = args
|
||||||
|
|
||||||
' These vars are needed to pass certification.
|
' These vars are needed to pass certification.
|
||||||
@@ -42,7 +43,16 @@ function Main(args as object) as void
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
input = CreateObject("roInput")
|
input = CreateObject("roInput")
|
||||||
input.setMessagePort(m.port)
|
input.setMessagePort(port)
|
||||||
|
|
||||||
|
' TODO:P1 follow up on bug where roSystemLog does not fire for a video player in ComponentLibrary
|
||||||
|
' https://community.roku.com/t5/Roku-Developer-Program/BUG-roSystemLog-not-firing-with-ComponentLibrary/td-p/906075
|
||||||
|
systemLog = CreateObject("roSystemLog")
|
||||||
|
systemLog.SetMessagePort(port)
|
||||||
|
systemLog.EnableType("http.connect")
|
||||||
|
systemLog.EnableType("http.error")
|
||||||
|
systemLog.EnableType("http.complete")
|
||||||
|
systemLog.EnableType("bandwidth.minute")
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
' The following comment is to enable the SceneGraph inspector
|
' The following comment is to enable the SceneGraph inspector
|
||||||
@@ -54,9 +64,11 @@ function Main(args as object) as void
|
|||||||
#end if
|
#end if
|
||||||
|
|
||||||
while true
|
while true
|
||||||
msg = wait(0, m.port)
|
msg = wait(0, port)
|
||||||
msgType = type(msg)
|
msgType = type(msg)
|
||||||
if msgType = "roSGScreenEvent"
|
if msgType = "roSystemLogEvent"
|
||||||
|
scene.systemLogEvent = msg.GetInfo()
|
||||||
|
else if msgType = "roSGScreenEvent"
|
||||||
if msg.isScreenClosed()
|
if msg.isScreenClosed()
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|||||||
Generated
+1
-19
@@ -9,8 +9,7 @@
|
|||||||
"version": "0.12.0",
|
"version": "0.12.0",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bslib": "npm:@rokucommunity/bslib@^0.1.1",
|
"bslib": "npm:@rokucommunity/bslib@^0.1.1"
|
||||||
"log": "npm:roku-log@^0.9.3"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/bslib": {
|
"node_modules/bslib": {
|
||||||
@@ -18,15 +17,6 @@
|
|||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@rokucommunity/bslib/-/bslib-0.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@rokucommunity/bslib/-/bslib-0.1.1.tgz",
|
||||||
"integrity": "sha512-2ox6EUL+UTtccTbD4dbVjZK3QHa0PHCqpoKMF8lZz9ayzzEP3iVPF8KZR6hOi6bxsIcbGXVjqmtCVkpC4P9SrA=="
|
"integrity": "sha512-2ox6EUL+UTtccTbD4dbVjZK3QHa0PHCqpoKMF8lZz9ayzzEP3iVPF8KZR6hOi6bxsIcbGXVjqmtCVkpC4P9SrA=="
|
||||||
},
|
|
||||||
"node_modules/log": {
|
|
||||||
"name": "roku-log",
|
|
||||||
"version": "0.9.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/roku-log/-/roku-log-0.9.3.tgz",
|
|
||||||
"integrity": "sha512-YzvtSCdmZJeimyZZ/C5Y7tdw6vpNMrZV90pg8EPn3vLAtRjtxN3dOt73s48BVOx2W00M0BEGmeaECObS2RdIqg==",
|
|
||||||
"dependencies": {
|
|
||||||
"bslib": "npm:@rokucommunity/bslib@^0.1.1"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -34,14 +24,6 @@
|
|||||||
"version": "npm:@rokucommunity/bslib@0.1.1",
|
"version": "npm:@rokucommunity/bslib@0.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@rokucommunity/bslib/-/bslib-0.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@rokucommunity/bslib/-/bslib-0.1.1.tgz",
|
||||||
"integrity": "sha512-2ox6EUL+UTtccTbD4dbVjZK3QHa0PHCqpoKMF8lZz9ayzzEP3iVPF8KZR6hOi6bxsIcbGXVjqmtCVkpC4P9SrA=="
|
"integrity": "sha512-2ox6EUL+UTtccTbD4dbVjZK3QHa0PHCqpoKMF8lZz9ayzzEP3iVPF8KZR6hOi6bxsIcbGXVjqmtCVkpC4P9SrA=="
|
||||||
},
|
|
||||||
"log": {
|
|
||||||
"version": "npm:roku-log@0.9.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/roku-log/-/roku-log-0.9.3.tgz",
|
|
||||||
"integrity": "sha512-YzvtSCdmZJeimyZZ/C5Y7tdw6vpNMrZV90pg8EPn3vLAtRjtxN3dOt73s48BVOx2W00M0BEGmeaECObS2RdIqg==",
|
|
||||||
"requires": {
|
|
||||||
"bslib": "npm:@rokucommunity/bslib@^0.1.1"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,7 @@
|
|||||||
"version": "0.12.0",
|
"version": "0.12.0",
|
||||||
"description": "Unofficial Youtube client for Roku",
|
"description": "Unofficial Youtube client for Roku",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bslib": "npm:@rokucommunity/bslib@^0.1.1",
|
"bslib": "npm:@rokucommunity/bslib@^0.1.1"
|
||||||
"log": "npm:roku-log@^0.9.3"
|
|
||||||
},
|
},
|
||||||
"ropm": {
|
"ropm": {
|
||||||
"rootDir": "./src"
|
"rootDir": "./src"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import "pkg:/source/utils/Types.bs"
|
|||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
import "pkg:/source/utils/FocusManagement.bs"
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
@@ -10,8 +10,6 @@ function Init()
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnNodeReady()
|
function OnNodeReady()
|
||||||
m.log = new log.Logger("AppController")
|
|
||||||
|
|
||||||
NodeSetFocus(m.top.root, true)
|
NodeSetFocus(m.top.root, true)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -97,7 +95,7 @@ end function
|
|||||||
function OnExitDialog(event as object)
|
function OnExitDialog(event as object)
|
||||||
buttonIndex = event.GetData()
|
buttonIndex = event.GetData()
|
||||||
if buttonIndex = 0 ' Exit
|
if buttonIndex = 0 ' Exit
|
||||||
m.log.info("Exiting app")
|
LogInfo("Exiting app")
|
||||||
m.top.getScene().exitChannel = true
|
m.top.getScene().exitChannel = true
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
|
||||||
import "pkg:/source/utils/FocusManagement.bs"
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.log = new log.Logger("ChannelView")
|
|
||||||
|
|
||||||
m.banner = m.top.findNode("banner")
|
m.banner = m.top.findNode("banner")
|
||||||
m.thumbnail = m.top.findNode("thumbnail")
|
m.thumbnail = m.top.findNode("thumbnail")
|
||||||
m.authorLabel = m.top.findNode("authorLabel")
|
m.authorLabel = m.top.findNode("authorLabel")
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function OnChannelContentTaskResult(output as object) as void
|
|||||||
error = output.result.error
|
error = output.result.error
|
||||||
end if
|
end if
|
||||||
error = ErrorUtils.Format(error)
|
error = ErrorUtils.Format(error)
|
||||||
m.log.error(error)
|
LogError(error)
|
||||||
playlistId = output.task.input.content.playlistId
|
playlistId = output.task.input.content.playlistId
|
||||||
message = `Failed to load playlist ${playlistId}\n${error}`
|
message = `Failed to load playlist ${playlistId}\n${error}`
|
||||||
DialogUtils.ShowDialog(message, "Playlist load fail", true)
|
DialogUtils.ShowDialog(message, "Playlist load fail", true)
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ end function
|
|||||||
|
|
||||||
function LaunchArgumentsReceived() as void
|
function LaunchArgumentsReceived() as void
|
||||||
launchArgs = m.scene.launchArgs
|
launchArgs = m.scene.launchArgs
|
||||||
m.log.info("LaunchArgumentsReceived", launchArgs)
|
LogInfo("LaunchArgumentsReceived", launchArgs)
|
||||||
ProcessArguments(launchArgs)
|
ProcessArguments(launchArgs)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function InputArgumentsReceived() as void
|
function InputArgumentsReceived() as void
|
||||||
inputArgs = m.scene.inputArgs
|
inputArgs = m.scene.inputArgs
|
||||||
m.log.info("InputArgumentsReceived", inputArgs)
|
LogInfo("InputArgumentsReceived", inputArgs)
|
||||||
ProcessArguments(inputArgs)
|
ProcessArguments(inputArgs)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
m.top.functionName = "LoggerLoop"
|
||||||
|
|
||||||
|
port = CreateObject("roMessagePort")
|
||||||
|
|
||||||
|
m.top.ObserveField("logLine", port)
|
||||||
|
|
||||||
|
scene = m.top.getScene()
|
||||||
|
if scene.hasField("systemLogEvent")
|
||||||
|
scene.ObserveFieldScoped("systemLogEvent", port)
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.port = port
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LoggerLoop()
|
||||||
|
port = m.port
|
||||||
|
|
||||||
|
buffer = CreateObject("roByteArray")
|
||||||
|
previousLogsFile = m.top.folder + "/" + m.top.filenamePrevious
|
||||||
|
logsFile = m.top.folder + "/" + m.top.filename
|
||||||
|
|
||||||
|
CreateDirectory(m.top.folder)
|
||||||
|
DeleteFile(previousLogsFile)
|
||||||
|
MoveFile(logsFile, previousLogsFile)
|
||||||
|
|
||||||
|
while true
|
||||||
|
msg = wait(0, port)
|
||||||
|
msgType = type(msg)
|
||||||
|
if msgType = "roSGNodeEvent"
|
||||||
|
field = msg.getField()
|
||||||
|
if field = "logLine"
|
||||||
|
OnLineLog(msg, logsFile, buffer)
|
||||||
|
else if field = "systemLogEvent"
|
||||||
|
OnLineSysLog(msg, logsFile, buffer)
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
end while
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnLineLog(event as object, logsFile as string, buffer as object)
|
||||||
|
line = event.getData()
|
||||||
|
' bs:disable-next-line LINT3012
|
||||||
|
print line
|
||||||
|
|
||||||
|
buffer.FromAsciiString(line + `\n`)
|
||||||
|
buffer.AppendFile(logsFile)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnLineSysLog(event as object, logsFile as string, buffer as object) as void
|
||||||
|
info = event.getData()
|
||||||
|
if info.LogType <> "http.error"
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
line = `[SysLog] ${FormatJson(info)}`
|
||||||
|
' bs:disable-next-line LINT3012
|
||||||
|
print line
|
||||||
|
|
||||||
|
buffer.FromAsciiString(line + `\n`)
|
||||||
|
buffer.AppendFile(logsFile)
|
||||||
|
end function
|
||||||
+3
-3
@@ -1,10 +1,10 @@
|
|||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
<component name='log_FileTransport' extends='Node'>
|
<component name='Logger' extends='Task'>
|
||||||
<interface>
|
<interface>
|
||||||
|
<field id='logLevel' type='int' value='2' />
|
||||||
|
<field id='logLine' type='string' />
|
||||||
<field id='folder' type='string' value='cachefs:/logs' />
|
<field id='folder' type='string' value='cachefs:/logs' />
|
||||||
<field id='filename' type='string' value='app_logs.txt' />
|
<field id='filename' type='string' value='app_logs.txt' />
|
||||||
<field id='filenamePrevious' type='string' value='app_logs_previous.txt' />
|
<field id='filenamePrevious' type='string' value='app_logs_previous.txt' />
|
||||||
<function name='logItem' />
|
|
||||||
</interface>
|
</interface>
|
||||||
<children />
|
|
||||||
</component>
|
</component>
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
|
||||||
|
|
||||||
function Init()
|
|
||||||
m.buffer = CreateObject("roByteArray")
|
|
||||||
|
|
||||||
previousLogs = m.top.folder + "/" + m.top.filenamePrevious
|
|
||||||
newLogs = m.top.folder + "/" + m.top.filename
|
|
||||||
|
|
||||||
CreateDirectory(m.top.folder)
|
|
||||||
DeleteFile(previousLogs)
|
|
||||||
MoveFile(newLogs, previousLogs)
|
|
||||||
|
|
||||||
m.logsPath = newLogs
|
|
||||||
end function
|
|
||||||
|
|
||||||
function logItem(name as string, levelNum as integer, text as string) as void
|
|
||||||
m.buffer.FromAsciiString(`[${name}] ${text}\n`)
|
|
||||||
m.buffer.AppendFile(m.logsPath)
|
|
||||||
end function
|
|
||||||
@@ -4,8 +4,8 @@ import "pkg:/source/utils/Logging.bs"
|
|||||||
import "pkg:/components/EcpArgs.bs"
|
import "pkg:/components/EcpArgs.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
InitializeLogging()
|
InitializeLogger()
|
||||||
m.log = new log.Logger("MainScene")
|
|
||||||
m.scene = m.top.getScene()
|
m.scene = m.top.getScene()
|
||||||
' At this point, the "MainScene" node is not yet added to the scene, and does not have a parent yet.
|
' At this point, the "MainScene" node is not yet added to the scene, and does not have a parent yet.
|
||||||
' Let's wait until it has one.
|
' Let's wait until it has one.
|
||||||
|
|||||||
@@ -5,9 +5,7 @@
|
|||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
InitializeBindings() ' auto-generated!
|
InitializeBindings() ' auto-generated!
|
||||||
InitializeLogging()
|
InitializeLogger()
|
||||||
m.log = log_Logger("MainScene")
|
|
||||||
m.__le = m.log.enabled
|
|
||||||
m.scene = m.top.getScene()
|
m.scene = m.top.getScene()
|
||||||
' At this point, the "MainScene" node is not yet added to the scene, and does not have a parent yet.
|
' At this point, the "MainScene" node is not yet added to the scene, and does not have a parent yet.
|
||||||
' Let's wait until it has one.
|
' Let's wait until it has one.
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
<script type="text/brightscript" uri="pkg:/components/MainScene_bindings.brs" />
|
<script type="text/brightscript" uri="pkg:/components/MainScene_bindings.brs" />
|
||||||
<script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
|
<script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
|
||||||
<script type="text/brightscript" uri="pkg:/source/utils/Logging.brs" />
|
<script type="text/brightscript" uri="pkg:/source/utils/Logging.brs" />
|
||||||
<script type="text/brightscript" uri="pkg:/source/roku_modules/log/LogMixin.brs" />
|
|
||||||
<script type="text/brightscript" uri="pkg:/source/utils/LoadingScreen.brs" />
|
<script type="text/brightscript" uri="pkg:/source/utils/LoadingScreen.brs" />
|
||||||
<script type="text/brightscript" uri="pkg:/components/EcpArgs.brs" />
|
<script type="text/brightscript" uri="pkg:/components/EcpArgs.brs" />
|
||||||
<script type="text/brightscript" uri="pkg:/source/utils/Types.brs" />
|
<script type="text/brightscript" uri="pkg:/source/utils/Types.brs" />
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
|||||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||||
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
||||||
import "pkg:/components/PlaylistView/PlaylistContentTask.bs"
|
import "pkg:/components/PlaylistView/PlaylistContentTask.bs"
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
import "pkg:/source/utils/ErrorUtils.bs"
|
import "pkg:/source/utils/ErrorUtils.bs"
|
||||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
import "pkg:/source/utils/ArrayUtils.bs"
|
import "pkg:/source/utils/ArrayUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.log = new log.Logger("PlayQueue")
|
|
||||||
m.pendingLoadTasks = {}
|
m.pendingLoadTasks = {}
|
||||||
' TODO:P1 prevent adding duplicates of the same video/playlist
|
' TODO:P1 prevent adding duplicates of the same video/playlist
|
||||||
m.queue = CreateObject("roArray", 0, true)
|
m.queue = CreateObject("roArray", 0, true)
|
||||||
@@ -163,7 +162,7 @@ function OnPlaylistContentTaskResult(output as object) as void
|
|||||||
error = output.result.error
|
error = output.result.error
|
||||||
end if
|
end if
|
||||||
error = ErrorUtils.Format(error)
|
error = ErrorUtils.Format(error)
|
||||||
m.log.error(error)
|
LogError(error)
|
||||||
playlistId = playlist.playlistId
|
playlistId = playlist.playlistId
|
||||||
message = `Failed to load playlist ${playlistId}\n${error}`
|
message = `Failed to load playlist ${playlistId}\n${error}`
|
||||||
' TODO:P1 play next upon closing the dialog
|
' TODO:P1 play next upon closing the dialog
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import "pkg:/source/utils/FocusManagement.bs"
|
|||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||||
import "pkg:/components/PlaylistView/PlaylistContentTask.bs"
|
import "pkg:/components/PlaylistView/PlaylistContentTask.bs"
|
||||||
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
||||||
@@ -10,8 +10,6 @@ import "pkg:/source/utils/ErrorUtils.bs"
|
|||||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.log = new log.Logger("PlaylistView")
|
|
||||||
|
|
||||||
m.background = m.top.findNode("background")
|
m.background = m.top.findNode("background")
|
||||||
m.backgroundSmall = m.top.findNode("backgroundSmall")
|
m.backgroundSmall = m.top.findNode("backgroundSmall")
|
||||||
m.titleLabel = m.top.findNode("titleLabel")
|
m.titleLabel = m.top.findNode("titleLabel")
|
||||||
@@ -90,7 +88,7 @@ function OnItemSelected(event as object)
|
|||||||
video = playlist.getChild(index)
|
video = playlist.getChild(index)
|
||||||
videoId = video.videoId
|
videoId = video.videoId
|
||||||
if not StringUtils.IsNullOrEmpty(videoId)
|
if not StringUtils.IsNullOrEmpty(videoId)
|
||||||
m.log.info("Play playlist: " + playlistId + " video: " + videoId)
|
LogInfo("Play playlist: " + playlistId + " video: " + videoId)
|
||||||
m.playQueue@.Play(playlist, index)
|
m.playQueue@.Play(playlist, index)
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
@@ -146,7 +144,7 @@ function OnPlaylistContentTaskResult(output as object) as void
|
|||||||
error = output.result.error
|
error = output.result.error
|
||||||
end if
|
end if
|
||||||
error = ErrorUtils.Format(error)
|
error = ErrorUtils.Format(error)
|
||||||
m.log.error(error)
|
LogError(error)
|
||||||
playlistId = output.task.input.content.playlistId
|
playlistId = output.task.input.content.playlistId
|
||||||
message = `Failed to load playlist ${playlistId}\n${error}`
|
message = `Failed to load playlist ${playlistId}\n${error}`
|
||||||
DialogUtils.ShowDialog(message, "Playlist load fail", true)
|
DialogUtils.ShowDialog(message, "Playlist load fail", true)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import "pkg:/components/Navigation/Navigation.bs"
|
import "pkg:/components/Navigation/Navigation.bs"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
|
||||||
import "pkg:/source/utils/ArrayUtils.bs"
|
import "pkg:/source/utils/ArrayUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
@@ -151,8 +150,6 @@ function PopulateLists(contentNodes as object, options as object)
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnNodeReady()
|
function OnNodeReady()
|
||||||
m.log = new log.Logger("SearchFilters")
|
|
||||||
|
|
||||||
RefreshUI()
|
RefreshUI()
|
||||||
|
|
||||||
m.controls.date.ObserveField("checkedItem", FuncName(OnListChecked))
|
m.controls.date.ObserveField("checkedItem", FuncName(OnListChecked))
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import "pkg:/source/asyncTask/asyncTask.bs"
|
|||||||
import "pkg:/source/services/SearchHistory.bs"
|
import "pkg:/source/services/SearchHistory.bs"
|
||||||
import "pkg:/source/utils/LoadingScreen.bs"
|
import "pkg:/source/utils/LoadingScreen.bs"
|
||||||
import "pkg:/source/utils/FocusManagement.bs"
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
import "pkg:/source/utils/ErrorUtils.bs"
|
import "pkg:/source/utils/ErrorUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
@@ -32,8 +32,6 @@ function Init()
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnNodeReady()
|
function OnNodeReady()
|
||||||
m.log = new log.Logger("SearchScreen")
|
|
||||||
|
|
||||||
m.rowlist@.BindNode(invalid)
|
m.rowlist@.BindNode(invalid)
|
||||||
m.keyboard.ObserveField("text", FuncName(OnTextChange))
|
m.keyboard.ObserveField("text", FuncName(OnTextChange))
|
||||||
m.suggestions.ObserveField("buttonFocused", FuncName(OnSearchButtonFocused))
|
m.suggestions.ObserveField("buttonFocused", FuncName(OnSearchButtonFocused))
|
||||||
@@ -112,7 +110,7 @@ function OnSearchSuggestionsTaskResults(output as object) as void
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
if not output.success
|
if not output.success
|
||||||
m.log.error(ErrorUtils.Format(output.error))
|
LogError(ErrorUtils.Format(output.error))
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
' In case this is an old request, discard suggestions
|
' In case this is an old request, discard suggestions
|
||||||
|
|||||||
+2
-4
@@ -1,13 +1,11 @@
|
|||||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||||
import "pkg:/components/Screens/SettingsScreen/InvidiousInstance/InvidiousPublicInstances/InvidiousPublicInstancesTask.bs"
|
import "pkg:/components/Screens/SettingsScreen/InvidiousInstance/InvidiousPublicInstances/InvidiousPublicInstancesTask.bs"
|
||||||
import "pkg:/source/utils/FocusManagement.bs"
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
import "pkg:/source/utils/ErrorUtils.bs"
|
import "pkg:/source/utils/ErrorUtils.bs"
|
||||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.log = new log.Logger("InvidiousPublicInstances")
|
|
||||||
|
|
||||||
m.failedLabel = m.top.findNode("failedLabel")
|
m.failedLabel = m.top.findNode("failedLabel")
|
||||||
m.refreshButton = m.top.findNode("refreshButton")
|
m.refreshButton = m.top.findNode("refreshButton")
|
||||||
m.instances = m.top.findNode("instances")
|
m.instances = m.top.findNode("instances")
|
||||||
@@ -71,7 +69,7 @@ function OnInvidiousPublicInstancesTaskResults(output as object) as void
|
|||||||
error = output.result.error
|
error = output.result.error
|
||||||
end if
|
end if
|
||||||
error = ErrorUtils.Format(error)
|
error = ErrorUtils.Format(error)
|
||||||
m.log.error(output.error)
|
LogError(output.error)
|
||||||
|
|
||||||
message = `Failed to load Invidious public instances\n${error}`
|
message = `Failed to load Invidious public instances\n${error}`
|
||||||
DialogUtils.ShowDialog(message, "Invidious public instances load error", true)
|
DialogUtils.ShowDialog(message, "Invidious public instances load error", true)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import "pkg:/source/utils/StringUtils.bs"
|
|||||||
import "pkg:/source/utils/TimeUtils.bs"
|
import "pkg:/source/utils/TimeUtils.bs"
|
||||||
import "pkg:/source/utils/CryptoUtils.bs"
|
import "pkg:/source/utils/CryptoUtils.bs"
|
||||||
import "pkg:/source/services/HttpClient.bs"
|
import "pkg:/source/services/HttpClient.bs"
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
|
|
||||||
namespace Invidious
|
namespace Invidious
|
||||||
const INSTANCES_API = "https://api.invidious.io/instances.json?sort_by=type,users"
|
const INSTANCES_API = "https://api.invidious.io/instances.json?sort_by=type,users"
|
||||||
@@ -34,8 +34,6 @@ namespace Invidious
|
|||||||
public node as object
|
public node as object
|
||||||
|
|
||||||
function new(node as object)
|
function new(node as object)
|
||||||
m.log = new log.Logger("InvidiousService")
|
|
||||||
|
|
||||||
m.node = node
|
m.node = node
|
||||||
' TODO:P2 api definitions are not needed everytime, move them to a separate function and lazy load
|
' TODO:P2 api definitions are not needed everytime, move them to a separate function and lazy load
|
||||||
apiDefinitions = node.apiDefinitions
|
apiDefinitions = node.apiDefinitions
|
||||||
@@ -290,8 +288,8 @@ namespace Invidious
|
|||||||
|
|
||||||
function DeleteExpiredToken(response as object)
|
function DeleteExpiredToken(response as object)
|
||||||
if response.StatusCode() = 403
|
if response.StatusCode() = 403
|
||||||
m.log.warn(`Invidious instance responded with 403: ${response.Text()}`)
|
LogWarn(`Invidious instance responded with 403: ${response.Text()}`)
|
||||||
m.log.warn("Deleting Invidious token...")
|
LogWarn("Deleting Invidious token...")
|
||||||
m.DeleteAuthToken()
|
m.DeleteAuthToken()
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||||
import "pkg:/components/VideoFeed/VideoRowListContentTask.bs"
|
import "pkg:/components/VideoFeed/VideoRowListContentTask.bs"
|
||||||
import "pkg:/components/VideoFeed/VideoRowListRowContentTask.bs"
|
import "pkg:/components/VideoFeed/VideoRowListRowContentTask.bs"
|
||||||
@@ -14,8 +14,6 @@ function Init()
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnNodeReady()
|
function OnNodeReady()
|
||||||
m.log = new log.Logger("VideoRowList")
|
|
||||||
|
|
||||||
m.top.ObserveField("itemFocused", FuncName(OnItemFocused))
|
m.top.ObserveField("itemFocused", FuncName(OnItemFocused))
|
||||||
m.top.ObserveField("rowItemFocused", FuncName(OnRowItemFocused))
|
m.top.ObserveField("rowItemFocused", FuncName(OnRowItemFocused))
|
||||||
m.top.ObserveField("rowItemSelected", FuncName(OnRowItemSelected))
|
m.top.ObserveField("rowItemSelected", FuncName(OnRowItemSelected))
|
||||||
@@ -70,15 +68,15 @@ function OnRowItemSelected(event as object)
|
|||||||
|
|
||||||
if rowItem.type = "video"
|
if rowItem.type = "video"
|
||||||
videoId = rowItem.videoId
|
videoId = rowItem.videoId
|
||||||
m.log.info("Play video: " + videoId)
|
LogInfo("Play video: " + videoId)
|
||||||
m.playQueue@.Play(rowItem, -1)
|
m.playQueue@.Play(rowItem, -1)
|
||||||
else if rowItem.type = "playlist"
|
else if rowItem.type = "playlist"
|
||||||
playlistId = rowItem.playlistId
|
playlistId = rowItem.playlistId
|
||||||
m.log.info("Open playlist: " + playlistId)
|
LogInfo("Open playlist: " + playlistId)
|
||||||
PlaylistUtils.Open(rowItem)
|
PlaylistUtils.Open(rowItem)
|
||||||
else if rowItem.type = "channel"
|
else if rowItem.type = "channel"
|
||||||
authorId = rowItem.authorId
|
authorId = rowItem.authorId
|
||||||
m.log.info("Open channel: " + authorId)
|
LogInfo("Open channel: " + authorId)
|
||||||
ChannelUtils.Open(rowItem)
|
ChannelUtils.Open(rowItem)
|
||||||
else if rowItem.type = "action"
|
else if rowItem.type = "action"
|
||||||
if rowItem.action = "LoginDialog"
|
if rowItem.action = "LoginDialog"
|
||||||
@@ -90,7 +88,7 @@ function OnRowItemSelected(event as object)
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnAuthTokenChange()
|
function OnAuthTokenChange()
|
||||||
' TODO:P1: Reload only content that is authenticated
|
' TODO:P2: Reload only content that is authenticated
|
||||||
' Should not reload if the page is not visible. Instead, capture state and reload when the page becomes visible
|
' Should not reload if the page is not visible. Instead, capture state and reload when the page becomes visible
|
||||||
InitContent()
|
InitContent()
|
||||||
end function
|
end function
|
||||||
@@ -197,7 +195,7 @@ function OnVideoRowListRowContentTaskResult(output as object) as void
|
|||||||
error = output.result.error
|
error = output.result.error
|
||||||
end if
|
end if
|
||||||
error = ErrorUtils.Format(error)
|
error = ErrorUtils.Format(error)
|
||||||
m.log.error(error)
|
LogError(error)
|
||||||
m.top.onError = error
|
m.top.onError = error
|
||||||
message = `Failed to load feed\n${error}`
|
message = `Failed to load feed\n${error}`
|
||||||
DialogUtils.ShowDialog(message, "Feed load fail", true)
|
DialogUtils.ShowDialog(message, "Feed load fail", true)
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ namespace SponsorBlock
|
|||||||
|
|
||||||
if not output.success
|
if not output.success
|
||||||
error = ErrorUtils.Format(output.error)
|
error = ErrorUtils.Format(output.error)
|
||||||
m.log.error(error)
|
LogError(error)
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ namespace SponsorBlock
|
|||||||
|
|
||||||
if action = "AutoSkip"
|
if action = "AutoSkip"
|
||||||
m.top.seek = segmentEnd
|
m.top.seek = segmentEnd
|
||||||
m.log.info("Skipping section:", segment["category"])
|
LogInfo("Skipping section:", segment["category"])
|
||||||
SendSkippedSectionEvent(segment.UUID)
|
SendSkippedSectionEvent(segment.UUID)
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import "pkg:/components/VideoPlayer/SponsorBlock.bs"
|
|||||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.log = new log.Logger("VideoPlayer")
|
|
||||||
SetPlayerStyle()
|
SetPlayerStyle()
|
||||||
SetupAnimation()
|
SetupAnimation()
|
||||||
|
|
||||||
@@ -90,7 +89,7 @@ function OnVideoContentTaskResults(output as object) as void
|
|||||||
error = output.result.error
|
error = output.result.error
|
||||||
end if
|
end if
|
||||||
error = ErrorUtils.Format(error)
|
error = ErrorUtils.Format(error)
|
||||||
m.log.error(error)
|
LogError(error)
|
||||||
videoId = output.task.input.content.videoId
|
videoId = output.task.input.content.videoId
|
||||||
message = `Failed to load video information for ${videoId}\n${error}`
|
message = `Failed to load video information for ${videoId}\n${error}`
|
||||||
DialogUtils.ShowDialog(message, "Video load fail", true)
|
DialogUtils.ShowDialog(message, "Video load fail", true)
|
||||||
@@ -145,13 +144,13 @@ function OnVideoPlayerStateChange() as void
|
|||||||
' If we successfully played the video, then any error that comes later is not due to a 403 (FORBIDDEN).
|
' If we successfully played the video, then any error that comes later is not due to a 403 (FORBIDDEN).
|
||||||
' This is to reduce false positives, as we do not want retry another link if the first link is working fine.
|
' This is to reduce false positives, as we do not want retry another link if the first link is working fine.
|
||||||
if state = "playing" and not m.videoPlayingSuccess
|
if state = "playing" and not m.videoPlayingSuccess
|
||||||
m.log.info(`Now playing video ${m.top.content.url}`)
|
LogInfo(`Now playing video ${m.top.content.url}`)
|
||||||
m.videoPlayingSuccess = true
|
m.videoPlayingSuccess = true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if state = "error"
|
if state = "error"
|
||||||
errorInfo = m.top.errorInfo
|
errorInfo = m.top.errorInfo
|
||||||
m.log.error(`Error playing video ${m.top.content.videoId}`, errorInfo)
|
LogError(`Error playing video ${m.top.content.videoId}`, errorInfo)
|
||||||
if m.videoPlayingSuccess <> true
|
if m.videoPlayingSuccess <> true
|
||||||
' http for stream format, mediaerror for DASH
|
' http for stream format, mediaerror for DASH
|
||||||
if errorInfo.category = "http" or errorInfo.category = "mediaerror"
|
if errorInfo.category = "http" or errorInfo.category = "mediaerror"
|
||||||
@@ -162,7 +161,7 @@ function OnVideoPlayerStateChange() as void
|
|||||||
m.top.content.playletStreamUrlIndex = playletStreamUrlIndex
|
m.top.content.playletStreamUrlIndex = playletStreamUrlIndex
|
||||||
if playletStreamUrlIndex < playletStreamUrls.Count()
|
if playletStreamUrlIndex < playletStreamUrls.Count()
|
||||||
nextUrl = playletStreamUrls[playletStreamUrlIndex]
|
nextUrl = playletStreamUrls[playletStreamUrlIndex]
|
||||||
m.log.error(`Stream ${currentUrl} failed to play. Trying next stream ${nextUrl}`)
|
LogError(`Stream ${currentUrl} failed to play. Trying next stream ${nextUrl}`)
|
||||||
|
|
||||||
m.top.content.url = nextUrl
|
m.top.content.url = nextUrl
|
||||||
' This video errored, and is about to finish, so don't close the video yet
|
' This video errored, and is about to finish, so don't close the video yet
|
||||||
@@ -231,7 +230,7 @@ function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
|
|||||||
continue for
|
continue for
|
||||||
end if
|
end if
|
||||||
if not m.container@.watchedVideosContain(videoId)
|
if not m.container@.watchedVideosContain(videoId)
|
||||||
m.log.info(`Playing next recommended video (${videoId})`)
|
LogInfo(`Playing next recommended video (${videoId})`)
|
||||||
node = InvidiousContent.ToVideoContentNode(invalid, metadata, invalid)
|
node = InvidiousContent.ToVideoContentNode(invalid, metadata, invalid)
|
||||||
VideoUtils.PlayVideo(node)
|
VideoUtils.PlayVideo(node)
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -3,14 +3,12 @@ import "HttpRequest.bs"
|
|||||||
import "HttpResponse.bs"
|
import "HttpResponse.bs"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
|
|
||||||
namespace Http
|
namespace Http
|
||||||
const BUFSIZE = 65536
|
const BUFSIZE = 65536
|
||||||
|
|
||||||
class HttpConnection
|
class HttpConnection
|
||||||
private log as log.Logger
|
|
||||||
|
|
||||||
private total_received = 0
|
private total_received = 0
|
||||||
private total_sent = 0
|
private total_sent = 0
|
||||||
private id = "<uninit>"
|
private id = "<uninit>"
|
||||||
@@ -22,7 +20,6 @@ namespace Http
|
|||||||
private settings as HttpSettings
|
private settings as HttpSettings
|
||||||
|
|
||||||
function new(server as HttpServer, settings as HttpSettings)
|
function new(server as HttpServer, settings as HttpSettings)
|
||||||
m.log = new log.Logger("HttpConnection")
|
|
||||||
m.server = server
|
m.server = server
|
||||||
m.settings = settings
|
m.settings = settings
|
||||||
m.Reset()
|
m.Reset()
|
||||||
@@ -42,14 +39,13 @@ namespace Http
|
|||||||
m.header = invalid
|
m.header = invalid
|
||||||
m.response = invalid
|
m.response = invalid
|
||||||
m.header_only = false
|
m.header_only = false
|
||||||
m.http_code = 0
|
|
||||||
m.close = true
|
m.close = true
|
||||||
m.ws_upgrade = false
|
m.ws_upgrade = false
|
||||||
m.SetState(Http.HttpConnectionState.INIT)
|
m.SetState(Http.HttpConnectionState.INIT)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function Recycle()
|
function Recycle()
|
||||||
m.log.info("recycle")
|
LogInfo("recycle")
|
||||||
m.Restart()
|
m.Restart()
|
||||||
m.SetState(Http.HttpConnectionState.RECV_REQUEST) ' ready for another
|
m.SetState(Http.HttpConnectionState.RECV_REQUEST) ' ready for another
|
||||||
end function
|
end function
|
||||||
@@ -60,7 +56,7 @@ namespace Http
|
|||||||
m.SetState(Http.HttpConnectionState.RECV_REQUEST)
|
m.SetState(Http.HttpConnectionState.RECV_REQUEST)
|
||||||
m.client = m.socket.getReceivedFromAddress().getAddress()
|
m.client = m.socket.getReceivedFromAddress().getAddress()
|
||||||
|
|
||||||
m.log.info("accepted connection @" + m.client)
|
LogInfo("accepted connection @" + m.client)
|
||||||
|
|
||||||
' try to read right away rather than going through another iteration
|
' try to read right away rather than going through another iteration
|
||||||
' of the poll loop.
|
' of the poll loop.
|
||||||
@@ -69,7 +65,7 @@ namespace Http
|
|||||||
|
|
||||||
function PollRequest(server as HttpServer)
|
function PollRequest(server as HttpServer)
|
||||||
if m.state <> Http.HttpConnectionState.RECV_REQUEST
|
if m.state <> Http.HttpConnectionState.RECV_REQUEST
|
||||||
m.log.error("illegal request state @" + m.client)
|
LogError("illegal request state @" + m.client)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
rcvStrByteLen = m.socket.GetCountRcvBuf()
|
rcvStrByteLen = m.socket.GetCountRcvBuf()
|
||||||
@@ -96,7 +92,7 @@ namespace Http
|
|||||||
else
|
else
|
||||||
m.setState(Http.HttpConnectionState.DONE)
|
m.setState(Http.HttpConnectionState.DONE)
|
||||||
m.close = true
|
m.close = true
|
||||||
m.log.error("couldn't process request or response, closing @" + m.client)
|
LogError("couldn't process request or response, closing @" + m.client)
|
||||||
end if
|
end if
|
||||||
else if m.request.buffer.len() > m.settings.MaxRequestLength ' die if it's too long
|
else if m.request.buffer.len() > m.settings.MaxRequestLength ' die if it's too long
|
||||||
m.response = new HttpResponse(m.request, m.server, m.settings)
|
m.response = new HttpResponse(m.request, m.server, m.settings)
|
||||||
@@ -114,7 +110,7 @@ namespace Http
|
|||||||
|
|
||||||
function PollHeader(server as HttpServer) as void
|
function PollHeader(server as HttpServer) as void
|
||||||
if m.state <> Http.HttpConnectionState.SEND_HEADER
|
if m.state <> Http.HttpConnectionState.SEND_HEADER
|
||||||
m.log.error("illegal header state @" + m.client)
|
LogError("illegal header state @" + m.client)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
sent = m.response.SendHeader(m.socket, Http.BUFSIZE)
|
sent = m.response.SendHeader(m.socket, Http.BUFSIZE)
|
||||||
@@ -136,7 +132,7 @@ namespace Http
|
|||||||
|
|
||||||
function PollResponse(server as HttpServer)
|
function PollResponse(server as HttpServer)
|
||||||
if m.state <> Http.HttpConnectionState.SEND_RESPONSE or m.response.header_only
|
if m.state <> Http.HttpConnectionState.SEND_RESPONSE or m.response.header_only
|
||||||
m.log.error("illegal response state @" + m.client)
|
LogError("illegal response state @" + m.client)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
sent = m.response.Send(m.socket, Http.BUFSIZE)
|
sent = m.response.Send(m.socket, Http.BUFSIZE)
|
||||||
@@ -166,9 +162,9 @@ namespace Http
|
|||||||
'info(m,op + " would have blocked @"+m.client)
|
'info(m,op + " would have blocked @"+m.client)
|
||||||
else
|
else
|
||||||
if m.socket.eSuccess()
|
if m.socket.eSuccess()
|
||||||
m.log.info(op + " peer closed @" + m.client)
|
LogInfo(op + " peer closed @" + m.client)
|
||||||
else
|
else
|
||||||
m.log.error(op + " transfer error @" + m.client, m.socket.status())
|
LogError(op + " transfer error @" + m.client, m.socket.status())
|
||||||
end if
|
end if
|
||||||
m.close = true
|
m.close = true
|
||||||
m.SetState(Http.HttpConnectionState.DONE)
|
m.SetState(Http.HttpConnectionState.DONE)
|
||||||
@@ -178,17 +174,11 @@ namespace Http
|
|||||||
|
|
||||||
function SetState(newState as Http.HttpConnectionState)
|
function SetState(newState as Http.HttpConnectionState)
|
||||||
if m.state <> newState
|
if m.state <> newState
|
||||||
' m.log.debug(m, "state change" + Stri(m.state) + " ->" + Stri(newState))
|
LogDebug(m, "state change" + Stri(m.state) + " ->" + Stri(newState))
|
||||||
m.state = newState
|
m.state = newState
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function LogInfo()
|
|
||||||
if m.http_code <> 0 and not StringUtils.IsNullOrEmpty(m.method)
|
|
||||||
m.log.info(m.last_active.totalSeconds(), " client:", m.client, " meth:", m.method, " uri:", m.uri, " code:", m.code, " sent:", m.total_sent, " referer:", m.referer, " user agent:", m.user_agent)
|
|
||||||
end if
|
|
||||||
end function
|
|
||||||
|
|
||||||
end class
|
end class
|
||||||
|
|
||||||
end namespace
|
end namespace
|
||||||
@@ -10,8 +10,6 @@ namespace Http
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
class HttpRequest
|
class HttpRequest
|
||||||
private log as log.Logger
|
|
||||||
|
|
||||||
' members
|
' members
|
||||||
private method = invalid
|
private method = invalid
|
||||||
private uri = invalid
|
private uri = invalid
|
||||||
@@ -33,7 +31,6 @@ namespace Http
|
|||||||
private ready_for_response = false
|
private ready_for_response = false
|
||||||
|
|
||||||
function new()
|
function new()
|
||||||
m.log = new log.Logger("HttpRequest")
|
|
||||||
m.id = Http.GetHttpRequestId()
|
m.id = Http.GetHttpRequestId()
|
||||||
m.headers = CreateObject("roAssociativeArray")
|
m.headers = CreateObject("roAssociativeArray")
|
||||||
end function
|
end function
|
||||||
@@ -81,7 +78,7 @@ namespace Http
|
|||||||
|
|
||||||
function ParseOperation() as boolean
|
function ParseOperation() as boolean
|
||||||
if m.buffer_index <> 0
|
if m.buffer_index <> 0
|
||||||
m.log.error(`invalid state: reading operation, but request is at index ${m.buffer_index}`)
|
LogError(`invalid state: reading operation, but request is at index ${m.buffer_index}`)
|
||||||
m.ready_for_response = true
|
m.ready_for_response = true
|
||||||
return false
|
return false
|
||||||
end if
|
end if
|
||||||
@@ -93,7 +90,7 @@ namespace Http
|
|||||||
operation = m.ReadHeaderLine()
|
operation = m.ReadHeaderLine()
|
||||||
|
|
||||||
if operation = invalid or operation = ""
|
if operation = invalid or operation = ""
|
||||||
m.log.error("empty request")
|
LogError("empty request")
|
||||||
m.ready_for_response = true
|
m.ready_for_response = true
|
||||||
return false
|
return false
|
||||||
end if
|
end if
|
||||||
@@ -103,9 +100,9 @@ namespace Http
|
|||||||
m.method = Ucase(parts[0])
|
m.method = Ucase(parts[0])
|
||||||
m.uri = parts[1]
|
m.uri = parts[1]
|
||||||
m.protocol = Ucase(parts[2])
|
m.protocol = Ucase(parts[2])
|
||||||
m.log.info(`${m.method} '${m.uri}'`)
|
LogInfo(`${m.method} '${m.uri}'`)
|
||||||
else
|
else
|
||||||
m.log.error("invalid request: " + operation)
|
LogError("invalid request: " + operation)
|
||||||
m.ready_for_response = true
|
m.ready_for_response = true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -148,7 +145,7 @@ namespace Http
|
|||||||
if m.headers["Content-Length"] = invalid
|
if m.headers["Content-Length"] = invalid
|
||||||
m.ready_for_response = true
|
m.ready_for_response = true
|
||||||
if m.body.len() > 0
|
if m.body.len() > 0
|
||||||
m.log.error("invalid request: request body found, but no Content-Length header")
|
LogError("invalid request: request body found, but no Content-Length header")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
@@ -160,7 +157,7 @@ namespace Http
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
if m.body.len() > contentLength
|
if m.body.len() > contentLength
|
||||||
m.log.error("invalid request: request body is larger than Content-Length")
|
LogError("invalid request: request body is larger than Content-Length")
|
||||||
m.ready_for_response = true
|
m.ready_for_response = true
|
||||||
return false
|
return false
|
||||||
end if
|
end if
|
||||||
@@ -233,7 +230,7 @@ namespace Http
|
|||||||
m.range_end_given = true
|
m.range_end_given = true
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
m.log.info("range request begin" + Stri(m.range_begin) + " end" + Stri(m.range_end))
|
LogInfo("range request begin" + Stri(m.range_begin) + " end" + Stri(m.range_end))
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ namespace Http
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
class HttpResponse
|
class HttpResponse
|
||||||
private log as log.Logger
|
|
||||||
|
|
||||||
private source = Http.HttpResponseSource.NONE
|
private source = Http.HttpResponseSource.NONE
|
||||||
|
|
||||||
' members
|
' members
|
||||||
@@ -32,7 +30,6 @@ namespace Http
|
|||||||
private settings
|
private settings
|
||||||
|
|
||||||
function new(request as HttpRequest, server as HttpServer, settings as HttpSettings)
|
function new(request as HttpRequest, server as HttpServer, settings as HttpSettings)
|
||||||
m.log = new log.Logger("HttpResponse")
|
|
||||||
m.id = Http.GetHttpResponseId()
|
m.id = Http.GetHttpResponseId()
|
||||||
m.request = request
|
m.request = request
|
||||||
m.server = server
|
m.server = server
|
||||||
@@ -111,20 +108,20 @@ namespace Http
|
|||||||
if m.start + m.sent >= m.buf_start + m.body_buffer.count()
|
if m.start + m.sent >= m.buf_start + m.body_buffer.count()
|
||||||
m.buf_start = m.start + m.sent
|
m.buf_start = m.start + m.sent
|
||||||
m.body_buffer.ReadFile(m.path, m.buf_start, bufsize)
|
m.body_buffer.ReadFile(m.path, m.buf_start, bufsize)
|
||||||
m.log.info(`Read ${m.body_buffer.count()} bytes from source file @${m.buf_start}`)
|
LogDebug(`Read ${m.body_buffer.count()} bytes from source file @${m.buf_start}`)
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
buf_pos = m.start + m.sent - m.buf_start
|
buf_pos = m.start + m.sent - m.buf_start
|
||||||
buf_remaining = m.body_buffer.count() - buf_pos
|
buf_remaining = m.body_buffer.count() - buf_pos
|
||||||
if buf_remaining = 0
|
if buf_remaining = 0
|
||||||
m.log.info("source buffer is empty")
|
LogInfo("source buffer is empty")
|
||||||
end if
|
end if
|
||||||
req_remaining = m.body_buffer_length - m.sent
|
req_remaining = m.body_buffer_length - m.sent
|
||||||
if buf_remaining > req_remaining
|
if buf_remaining > req_remaining
|
||||||
buf_remaining = req_remaining
|
buf_remaining = req_remaining
|
||||||
end if
|
end if
|
||||||
sent = sock.send(m.body_buffer, buf_pos, buf_remaining)
|
sent = sock.send(m.body_buffer, buf_pos, buf_remaining)
|
||||||
m.LogInfo(sent, m.buf_start + buf_pos, m.body_buffer_length)
|
m.LogSentRange(sent, m.buf_start + buf_pos, m.body_buffer_length)
|
||||||
if sent > 0
|
if sent > 0
|
||||||
m.sent = m.sent + sent
|
m.sent = m.sent + sent
|
||||||
end if
|
end if
|
||||||
@@ -141,7 +138,7 @@ namespace Http
|
|||||||
else
|
else
|
||||||
sent = sock.sendStr(m.header.mid(m.header_sent))
|
sent = sock.sendStr(m.header.mid(m.header_sent))
|
||||||
end if
|
end if
|
||||||
m.LogInfo(sent, m.header_sent, m.header_length)
|
m.LogSentRange(sent, m.header_sent, m.header_length)
|
||||||
if sent > 0
|
if sent > 0
|
||||||
m.header_sent = m.header_sent + sent
|
m.header_sent = m.header_sent + sent
|
||||||
end if
|
end if
|
||||||
@@ -176,8 +173,8 @@ namespace Http
|
|||||||
return m.header_sent = m.header_length
|
return m.header_sent = m.header_length
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function LogInfo(recent as integer, from as integer, total as integer)
|
function LogSentRange(recent as integer, from as integer, total as integer)
|
||||||
m.log.info(`Sent ${recent} [${m.MakeRange(from, recent, total)}]`)
|
LogDebug(`Sent ${recent} [${m.MakeRange(from, recent, total)}]`)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function KeepAlive(keepAlive as boolean)
|
function KeepAlive(keepAlive as boolean)
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import "HttpConnection.bs"
|
|||||||
namespace Http
|
namespace Http
|
||||||
|
|
||||||
class HttpServer
|
class HttpServer
|
||||||
private log as log.Logger
|
|
||||||
|
|
||||||
' members
|
' members
|
||||||
private connections = invalid
|
private connections = invalid
|
||||||
private sockin = invalid
|
private sockin = invalid
|
||||||
@@ -26,7 +24,6 @@ namespace Http
|
|||||||
public task as object
|
public task as object
|
||||||
|
|
||||||
function new(settings as HttpSettings, task as object)
|
function new(settings as HttpSettings, task as object)
|
||||||
m.log = new log.Logger("HttpServer")
|
|
||||||
m.settings = settings
|
m.settings = settings
|
||||||
m.task = task
|
m.task = task
|
||||||
m.routers = []
|
m.routers = []
|
||||||
@@ -44,13 +41,13 @@ namespace Http
|
|||||||
sockin = CreateObject("roStreamSocket")
|
sockin = CreateObject("roStreamSocket")
|
||||||
if sockin = invalid
|
if sockin = invalid
|
||||||
success = false
|
success = false
|
||||||
m.log.error("socket()")
|
LogError("socket()")
|
||||||
end if
|
end if
|
||||||
|
|
||||||
' reuse address
|
' reuse address
|
||||||
if not sockin.setReuseAddr(true)
|
if not sockin.setReuseAddr(true)
|
||||||
success = false
|
success = false
|
||||||
m.log.error("setsockopt(SO_REUSEADDR)", sockin.status())
|
LogError("setsockopt(SO_REUSEADDR)", sockin.status())
|
||||||
end if
|
end if
|
||||||
|
|
||||||
' bind socket
|
' bind socket
|
||||||
@@ -58,12 +55,12 @@ namespace Http
|
|||||||
addrin.setPort(m.settings.Port)
|
addrin.setPort(m.settings.Port)
|
||||||
if not sockin.setAddress(addrin)
|
if not sockin.setAddress(addrin)
|
||||||
success = false
|
success = false
|
||||||
m.log.error("bind(port" + Stri(m.settings.Port) + ")", sockin.status())
|
LogError("bind(port" + Stri(m.settings.Port) + ")", sockin.status())
|
||||||
end if
|
end if
|
||||||
' listen on socket
|
' listen on socket
|
||||||
if not sockin.listen(m.settings.MaxConnections)
|
if not sockin.listen(m.settings.MaxConnections)
|
||||||
success = false
|
success = false
|
||||||
m.log.error("listen()", sockin.status())
|
LogError("listen()", sockin.status())
|
||||||
end if
|
end if
|
||||||
' monitor socket
|
' monitor socket
|
||||||
sockin.setMessagePort(m.settings.MessagePort)
|
sockin.setMessagePort(m.settings.MessagePort)
|
||||||
@@ -71,7 +68,7 @@ namespace Http
|
|||||||
|
|
||||||
m.sockin = sockin
|
m.sockin = sockin
|
||||||
|
|
||||||
m.log.info("listening on " + addrin.getAddress())
|
LogInfo("listening on " + addrin.getAddress())
|
||||||
return success
|
return success
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -95,7 +92,7 @@ namespace Http
|
|||||||
conn.socket.notifyWritable(true)
|
conn.socket.notifyWritable(true)
|
||||||
conn.socket.notifyReadable(false)
|
conn.socket.notifyReadable(false)
|
||||||
else
|
else
|
||||||
m.log.error("invalid state")
|
LogError("invalid state")
|
||||||
end if
|
end if
|
||||||
end for
|
end for
|
||||||
end function
|
end function
|
||||||
@@ -126,7 +123,7 @@ namespace Http
|
|||||||
else if cs = Http.HttpConnectionState.DONE
|
else if cs = Http.HttpConnectionState.DONE
|
||||||
' handle with other connections that might transition to done
|
' handle with other connections that might transition to done
|
||||||
else
|
else
|
||||||
m.log.error("invalid state")
|
LogError("invalid state")
|
||||||
end if
|
end if
|
||||||
cs = conn.state
|
cs = conn.state
|
||||||
if cs = Http.HttpConnectionState.DONE
|
if cs = Http.HttpConnectionState.DONE
|
||||||
@@ -134,7 +131,7 @@ namespace Http
|
|||||||
conn.socket.close()
|
conn.socket.close()
|
||||||
connections.delete(id)
|
connections.delete(id)
|
||||||
else if conn.ws_upgrade and m.websocket <> invalid
|
else if conn.ws_upgrade and m.websocket <> invalid
|
||||||
m.log.info("upgrading connection to web socket")
|
LogInfo("upgrading connection to web socket")
|
||||||
m.websocket.AddConnection(conn.socket)
|
m.websocket.AddConnection(conn.socket)
|
||||||
connections.delete(id)
|
connections.delete(id)
|
||||||
else
|
else
|
||||||
@@ -149,7 +146,7 @@ namespace Http
|
|||||||
sockin = m.sockin
|
sockin = m.sockin
|
||||||
socket = sockin.accept()
|
socket = sockin.accept()
|
||||||
if not sockin.eOK()
|
if not sockin.eOK()
|
||||||
m.log.error("accept()", sockin.status())
|
LogError("accept()", sockin.status())
|
||||||
end if
|
end if
|
||||||
if socket = invalid
|
if socket = invalid
|
||||||
return invalid
|
return invalid
|
||||||
@@ -171,7 +168,7 @@ namespace Http
|
|||||||
m.websocket.Close()
|
m.websocket.Close()
|
||||||
end if
|
end if
|
||||||
' final stats
|
' final stats
|
||||||
m.log.info(`\n` + m.stats())
|
LogInfo(`\n` + m.stats())
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function Stats() as string
|
function Stats() as string
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import "pkg:/source/utils/StringUtils.bs"
|
|||||||
namespace Http
|
namespace Http
|
||||||
|
|
||||||
class HttpStaticFilesRouter extends HttpRouter
|
class HttpStaticFilesRouter extends HttpRouter
|
||||||
private log as log.Logger
|
|
||||||
|
|
||||||
private root
|
private root
|
||||||
private route
|
private route
|
||||||
private showDirectories
|
private showDirectories
|
||||||
@@ -13,7 +11,6 @@ namespace Http
|
|||||||
|
|
||||||
function new(route as string, root as string, showDirectories = false as boolean, showHidden = false as boolean, fsCheck = true as boolean)
|
function new(route as string, root as string, showDirectories = false as boolean, showHidden = false as boolean, fsCheck = true as boolean)
|
||||||
super()
|
super()
|
||||||
m.log = new log.Logger("HttpStaticFilesRouter")
|
|
||||||
|
|
||||||
m.root = root
|
m.root = root
|
||||||
m.route = route
|
m.route = route
|
||||||
@@ -78,7 +75,7 @@ namespace Http
|
|||||||
mimetype = server.utils.MimeType(decoded_path)
|
mimetype = server.utils.MimeType(decoded_path)
|
||||||
response.ContentType(mimetype)
|
response.ContentType(mimetype)
|
||||||
response.fileLength = stat.size
|
response.fileLength = stat.size
|
||||||
router.log.info(`uri=${request.uri}, target=${path}, content-type=${mimetype}, content-length=${response.fileLength}`)
|
LogInfo(`uri=${request.uri}, target=${path}, content-type=${mimetype}, content-length=${response.fileLength}`)
|
||||||
router.GenerateFile(path, router, request, response)
|
router.GenerateFile(path, router, request, response)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
@@ -117,7 +114,7 @@ namespace Http
|
|||||||
start = 0
|
start = 0
|
||||||
end if
|
end if
|
||||||
else
|
else
|
||||||
router.log.error(1, "internal error - range start/finish logic inconsistency")
|
LogError(1, "internal error - range start/finish logic inconsistency")
|
||||||
end if
|
end if
|
||||||
|
|
||||||
response.start = start
|
response.start = start
|
||||||
@@ -126,7 +123,7 @@ namespace Http
|
|||||||
response.headers["Content-Range"] = "bytes " + response.MakeRange(response.start, response.body_buffer_length, response.filelength)
|
response.headers["Content-Range"] = "bytes " + response.MakeRange(response.start, response.body_buffer_length, response.filelength)
|
||||||
response.http_code = 206
|
response.http_code = 206
|
||||||
|
|
||||||
router.log.info("sending range " + response.MakeRange(start, response.body_buffer_length, response.fileLength))
|
LogInfo("sending range " + response.MakeRange(start, response.body_buffer_length, response.fileLength))
|
||||||
else ' no range stuff
|
else ' no range stuff
|
||||||
response.body_buffer_length = response.fileLength
|
response.body_buffer_length = response.fileLength
|
||||||
response.ContentLength(response.body_buffer_length)
|
response.ContentLength(response.body_buffer_length)
|
||||||
@@ -198,7 +195,7 @@ namespace Http
|
|||||||
safe_url = uri ' UrlEncode(uri) ' too much encoding
|
safe_url = uri ' UrlEncode(uri) ' too much encoding
|
||||||
listing += `<a href="${safe_url}">${item}${indicator}</a>\n`
|
listing += `<a href="${safe_url}">${item}${indicator}</a>\n`
|
||||||
else
|
else
|
||||||
router.log.warn("insufficient stat info to include '" + dir + item + "'")
|
LogWarn("insufficient stat info to include '" + dir + item + "'")
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
end for
|
end for
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ import "pkg:/components/Web/WebServer/Middleware/HttpDefaultRouter.bs"
|
|||||||
import "pkg:/source/utils/Logging.bs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
InitializeLogging()
|
|
||||||
m.log = new log.Logger("WebServer")
|
|
||||||
|
|
||||||
m.top.functionName = "WebServerLoop"
|
m.top.functionName = "WebServerLoop"
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -40,7 +37,7 @@ function WebServerLoop() as void
|
|||||||
server = new Http.HttpServer(settings, m.top)
|
server = new Http.HttpServer(settings, m.top)
|
||||||
if not server.success
|
if not server.success
|
||||||
m.top.isRunning = false
|
m.top.isRunning = false
|
||||||
m.log.error("Failed to start server")
|
LogError("Failed to start server")
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -73,12 +70,12 @@ function WebServerLoop() as void
|
|||||||
end if
|
end if
|
||||||
end while
|
end while
|
||||||
|
|
||||||
m.log.info("closing server")
|
LogInfo("closing server")
|
||||||
server.Close()
|
server.Close()
|
||||||
m.top.isRunning = false
|
m.top.isRunning = false
|
||||||
m.top.unobserveField("shouldQuit")
|
m.top.unobserveField("shouldQuit")
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function SetupRoutes(server as object)
|
function SetupRoutes(server as object)
|
||||||
m.log.warn("No routes configured")
|
LogWarn("No routes configured")
|
||||||
end function
|
end function
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#const DISABLE_CACHE = false
|
#const DISABLE_CACHE = false
|
||||||
|
|
||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
import "pkg:/source/utils/CryptoUtils.bs"
|
import "pkg:/source/utils/CryptoUtils.bs"
|
||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
@@ -45,7 +45,6 @@ namespace HttpClient
|
|||||||
public urlTransfer as object
|
public urlTransfer as object
|
||||||
|
|
||||||
function new()
|
function new()
|
||||||
m.log = new log.Logger("HttpRequest")
|
|
||||||
m._timeoutSeconds = 30
|
m._timeoutSeconds = 30
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -198,7 +197,7 @@ namespace HttpClient
|
|||||||
if m._noCache <> true
|
if m._noCache <> true
|
||||||
cache = HttpClientCache.Get(m)
|
cache = HttpClientCache.Get(m)
|
||||||
if cache <> invalid
|
if cache <> invalid
|
||||||
m.log.info("Cache hit", m._method, m.BuildUrl())
|
LogInfo("Cache hit", m._method, m.BuildUrl())
|
||||||
m._cache = cache
|
m._cache = cache
|
||||||
return m
|
return m
|
||||||
end if
|
end if
|
||||||
@@ -206,7 +205,7 @@ namespace HttpClient
|
|||||||
|
|
||||||
m.urlTransfer = m.CreateRoUrlTransfer()
|
m.urlTransfer = m.CreateRoUrlTransfer()
|
||||||
if m.urlTransfer = invalid
|
if m.urlTransfer = invalid
|
||||||
m.log.error("Failed to create roUrlTransfer. We're probably not in a background thread.")
|
LogError("Failed to create roUrlTransfer. We're probably not in a background thread.")
|
||||||
return m
|
return m
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -219,7 +218,7 @@ namespace HttpClient
|
|||||||
m.urlTransfer.SetMessagePort(CreateObject("roMessagePort"))
|
m.urlTransfer.SetMessagePort(CreateObject("roMessagePort"))
|
||||||
end if
|
end if
|
||||||
|
|
||||||
m.log.info("Sending", m._method, m.urlTransfer.GetURL(), "ID:", m.urlTransfer.GetIdentity())
|
LogInfo("Sending", m._method, m.urlTransfer.GetURL(), "ID:", m.urlTransfer.GetIdentity())
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
? `════════ curl command ════════\n${m.ToCurlCommand()}\n══════════════════════════════`
|
? `════════ curl command ════════\n${m.ToCurlCommand()}\n══════════════════════════════`
|
||||||
@@ -237,7 +236,7 @@ namespace HttpClient
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
if m._sent <> true
|
if m._sent <> true
|
||||||
m.log.error("Failed to send request")
|
LogError("Failed to send request")
|
||||||
end if
|
end if
|
||||||
|
|
||||||
return m
|
return m
|
||||||
@@ -295,19 +294,19 @@ namespace HttpClient
|
|||||||
|
|
||||||
if msg = invalid
|
if msg = invalid
|
||||||
' timeout
|
' timeout
|
||||||
m.log.info("Timeout", "ID:", m.urlTransfer.GetIdentity())
|
LogInfo("Timeout", "ID:", m.urlTransfer.GetIdentity())
|
||||||
m.urlTransfer.AsyncCancel()
|
m.urlTransfer.AsyncCancel()
|
||||||
else
|
else
|
||||||
eventType = type(msg)
|
eventType = type(msg)
|
||||||
if eventType = "roUrlEvent"
|
if eventType = "roUrlEvent"
|
||||||
m.log.info("Finished", "ID:", m.urlTransfer.GetIdentity())
|
LogInfo("Finished", "ID:", m.urlTransfer.GetIdentity())
|
||||||
else if eventType = "roSGNodeEvent"
|
else if eventType = "roSGNodeEvent"
|
||||||
node = msg.getRoSGNode()
|
node = msg.getRoSGNode()
|
||||||
field = msg.getField()
|
field = msg.getField()
|
||||||
value = msg.getData()
|
value = msg.getData()
|
||||||
' cancellation
|
' cancellation
|
||||||
if node.isSameNode(m._cancellation.node) and field = m._cancellation.field and value = m._cancellation.value
|
if node.isSameNode(m._cancellation.node) and field = m._cancellation.field and value = m._cancellation.value
|
||||||
m.log.info("Cancelled", "ID:", m.urlTransfer.GetIdentity())
|
LogInfo("Cancelled", "ID:", m.urlTransfer.GetIdentity())
|
||||||
m._cancelled = true
|
m._cancelled = true
|
||||||
m.urlTransfer.AsyncCancel()
|
m.urlTransfer.AsyncCancel()
|
||||||
end if
|
end if
|
||||||
@@ -544,9 +543,6 @@ namespace HttpClient
|
|||||||
|
|
||||||
end namespace
|
end namespace
|
||||||
|
|
||||||
' TODO:P2 introduce the concept of "loose" cache
|
|
||||||
' For playlists that show in a feed or in a search, we don't want to make a request to get the playlist details
|
|
||||||
' But if we have that information in the cache already, it can be used
|
|
||||||
namespace HttpClientCache
|
namespace HttpClientCache
|
||||||
function GetLocation(request as HttpClient.HttpRequest) as dynamic
|
function GetLocation(request as HttpClient.HttpRequest) as dynamic
|
||||||
if request._cacheLocation <> invalid
|
if request._cacheLocation <> invalid
|
||||||
|
|||||||
@@ -1,17 +1,66 @@
|
|||||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
|
||||||
|
|
||||||
enum LogLevel
|
enum LogLevel
|
||||||
ERROR = 0
|
ERROR = 0
|
||||||
WARN = 1
|
WARN = 1
|
||||||
INFO = 2
|
INFO = 2
|
||||||
VERBOSE = 3
|
|
||||||
DEBUG = 3
|
DEBUG = 3
|
||||||
end enum
|
end enum
|
||||||
|
|
||||||
function InitializeLogging() as void
|
function InitializeLogger(logLevel = LogLevel.Info as LogLevel) as void
|
||||||
instance = log.getLogInstance()
|
logger = CreateObject("roSGNode", "Logger")
|
||||||
if instance <> invalid
|
logger.logLevel = logLevel
|
||||||
return
|
m.global.addFields({ logger: logger })
|
||||||
|
logger.control = "run"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LogError(arg1 = invalid as dynamic, arg2 = invalid as dynamic, arg3 = invalid as dynamic, arg4 = invalid as dynamic, arg5 = invalid as dynamic, arg6 = invalid as dynamic, arg7 = invalid as dynamic, arg8 = invalid as dynamic, arg9 = invalid as dynamic, arg10 = invalid as dynamic, arg11 = invalid as dynamic, arg12 = invalid as dynamic, arg13 = invalid as dynamic, arg14 = invalid as dynamic, arg15 = invalid as dynamic, arg16 = invalid as dynamic) as void
|
||||||
|
throw "FATAL: Calling LogError() which is a stub function"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LogWarn(arg1 = invalid as dynamic, arg2 = invalid as dynamic, arg3 = invalid as dynamic, arg4 = invalid as dynamic, arg5 = invalid as dynamic, arg6 = invalid as dynamic, arg7 = invalid as dynamic, arg8 = invalid as dynamic, arg9 = invalid as dynamic, arg10 = invalid as dynamic, arg11 = invalid as dynamic, arg12 = invalid as dynamic, arg13 = invalid as dynamic, arg14 = invalid as dynamic, arg15 = invalid as dynamic, arg16 = invalid as dynamic) as void
|
||||||
|
throw "FATAL: Calling LogWarn() which is a stub function"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LogInfo(arg1 = invalid as dynamic, arg2 = invalid as dynamic, arg3 = invalid as dynamic, arg4 = invalid as dynamic, arg5 = invalid as dynamic, arg6 = invalid as dynamic, arg7 = invalid as dynamic, arg8 = invalid as dynamic, arg9 = invalid as dynamic, arg10 = invalid as dynamic, arg11 = invalid as dynamic, arg12 = invalid as dynamic, arg13 = invalid as dynamic, arg14 = invalid as dynamic, arg15 = invalid as dynamic, arg16 = invalid as dynamic) as void
|
||||||
|
throw "FATAL: Calling LogInfo() which is a stub function"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function LogDebug(arg1 = invalid as dynamic, arg2 = invalid as dynamic, arg3 = invalid as dynamic, arg4 = invalid as dynamic, arg5 = invalid as dynamic, arg6 = invalid as dynamic, arg7 = invalid as dynamic, arg8 = invalid as dynamic, arg9 = invalid as dynamic, arg10 = invalid as dynamic, arg11 = invalid as dynamic, arg12 = invalid as dynamic, arg13 = invalid as dynamic, arg14 = invalid as dynamic, arg15 = invalid as dynamic, arg16 = invalid as dynamic) as void
|
||||||
|
throw "FATAL: Calling LogDebug() which is a stub function"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ToString(value as dynamic) as string
|
||||||
|
if getInterface(value, "ifString") <> invalid
|
||||||
|
return value
|
||||||
end if
|
end if
|
||||||
log.initializeLogManager(["log_PrintTransport", "log_FileTransport"], LogLevel.INFO)
|
|
||||||
|
valueType = type(value)
|
||||||
|
|
||||||
|
if valueType = "<uninitialized>"
|
||||||
|
return valueType
|
||||||
|
else if value = invalid
|
||||||
|
return "<invalid>"
|
||||||
|
else if GetInterface(value, "ifToStr") <> invalid
|
||||||
|
return value.toStr()
|
||||||
|
else if valueType = "roSGNode"
|
||||||
|
return "Node(" + value.subType() + ":" + value.id + ")"
|
||||||
|
else if valueType = "roAssociativeArray"
|
||||||
|
return AssocArrayToString(value)
|
||||||
|
end if
|
||||||
|
|
||||||
|
return "<" + valueType + ">"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function AssocArrayToString(dict as object) as string
|
||||||
|
result = "{"
|
||||||
|
count = dict.count()
|
||||||
|
i = 0
|
||||||
|
for each key in dict
|
||||||
|
result += key + ": " + ToString(dict[key])
|
||||||
|
if i < count - 1
|
||||||
|
result += ", "
|
||||||
|
end if
|
||||||
|
i++
|
||||||
|
end for
|
||||||
|
result += "}"
|
||||||
|
return result
|
||||||
end function
|
end function
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
// This plugin generates logging functions based on the usage of the LogError, LogWarn, LogInfo, and LogDebug functions.
|
||||||
|
|
||||||
|
import {
|
||||||
|
AstEditor,
|
||||||
|
BeforeFileTranspileEvent,
|
||||||
|
BscFile,
|
||||||
|
CompilerPlugin,
|
||||||
|
Program,
|
||||||
|
SourceLiteralExpression,
|
||||||
|
TokenKind,
|
||||||
|
TranspileObj,
|
||||||
|
WalkMode,
|
||||||
|
createToken,
|
||||||
|
createVisitor,
|
||||||
|
isBrsFile,
|
||||||
|
} from 'brighterscript';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
const loggingFilePath = 'source/utils/Logging.bs';
|
||||||
|
const logFunctions = {
|
||||||
|
LogError: {
|
||||||
|
stringLevel: 'ERROR',
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
LogWarn: {
|
||||||
|
stringLevel: 'WARN',
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
LogInfo: {
|
||||||
|
stringLevel: 'INFO',
|
||||||
|
level: 2,
|
||||||
|
},
|
||||||
|
LogDebug: {
|
||||||
|
stringLevel: 'DEBUG',
|
||||||
|
level: 3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const logFunctionKeys = Object.keys(logFunctions);
|
||||||
|
|
||||||
|
type LogFunction = {
|
||||||
|
name: string;
|
||||||
|
argCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LoggerPlugin implements CompilerPlugin {
|
||||||
|
public name = 'LoggerPlugin';
|
||||||
|
|
||||||
|
private hasLogger = false;
|
||||||
|
|
||||||
|
beforeProgramTranspile(program: Program, entries: TranspileObj[], editor: AstEditor) {
|
||||||
|
this.hasLogger = program.hasFile(loggingFilePath);
|
||||||
|
if (!this.hasLogger) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const usedLogFunctions = new Map<string, LogFunction>();
|
||||||
|
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (!isBrsFile(entry.file)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const visitor = createVisitor({
|
||||||
|
ExpressionStatement: (statement) => {
|
||||||
|
// @ts-ignore
|
||||||
|
const funcName = statement.expression.callee?.name?.text;
|
||||||
|
if (funcName && logFunctionKeys.includes(funcName)) {
|
||||||
|
// @ts-ignore
|
||||||
|
const argCount = statement.expression.args.length + 1; // +1 for the file path
|
||||||
|
const newFuncName = `${funcName}${argCount}`;
|
||||||
|
usedLogFunctions.set(newFuncName, {
|
||||||
|
name: funcName,
|
||||||
|
argCount: argCount,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const func of entry.file.parser.references.functionExpressions) {
|
||||||
|
func.body.walk(visitor, {
|
||||||
|
walkMode: WalkMode.visitStatements
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.generateLoggingFile(program, usedLogFunctions);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeFileTranspile(event: BeforeFileTranspileEvent<BscFile>) {
|
||||||
|
if (!this.hasLogger) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isBrsFile(event.file)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
const isDebug = !!event.program.options.debug;
|
||||||
|
|
||||||
|
const visitor = createVisitor({
|
||||||
|
ExpressionStatement: (statement) => {
|
||||||
|
// @ts-ignore
|
||||||
|
const funcName = statement.expression.callee?.name?.text;
|
||||||
|
if (funcName && logFunctionKeys.includes(funcName)) {
|
||||||
|
// @ts-ignore
|
||||||
|
const args = statement.expression.args;
|
||||||
|
if (isDebug) {
|
||||||
|
const t = createToken(TokenKind.SourceLocationLiteral, '', statement.expression.range);
|
||||||
|
let sourceExpression = new SourceLiteralExpression(t);
|
||||||
|
event.editor.addToArray(args, 0, sourceExpression);
|
||||||
|
} else {
|
||||||
|
const fileName = path.basename(event.file.pkgPath);
|
||||||
|
const line = statement.range.start.line;
|
||||||
|
const t = createToken(TokenKind.StringLiteral, `\"[${fileName}:${line}]\"`, statement.expression.range);
|
||||||
|
let sourceExpression = new SourceLiteralExpression(t);
|
||||||
|
event.editor.addToArray(args, 0, sourceExpression);
|
||||||
|
}
|
||||||
|
|
||||||
|
const newFuncName = `${funcName}${args.length}`;
|
||||||
|
event.program.logger.info(this.name, `Replacing ${funcName} with ${newFuncName}`);
|
||||||
|
// @ts-ignore
|
||||||
|
event.editor.setProperty(statement.expression.callee?.name, 'text', `${newFuncName}`)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const func of event.file.parser.references.functionExpressions) {
|
||||||
|
func.body.walk(visitor, {
|
||||||
|
walkMode: WalkMode.visitStatements
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generateLoggingFile(program: Program, usedLogFunctions: Map<string, LogFunction>) {
|
||||||
|
const file = program.getFile(loggingFilePath);
|
||||||
|
let content = file.fileContents;
|
||||||
|
|
||||||
|
content += '\n\' Start of auto-generated functions\n'
|
||||||
|
usedLogFunctions.forEach((logFunction, newFunctionName) => {
|
||||||
|
content += this.generateLoggingFunction(newFunctionName, logFunction.name, logFunction.argCount);
|
||||||
|
});
|
||||||
|
content += '\n\' End of auto-generated functions\n'
|
||||||
|
|
||||||
|
program.setFile(loggingFilePath, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
generateLoggingFunction(newFunctionName: string, level: string, argCount: number) {
|
||||||
|
const args: string[] = [];
|
||||||
|
const argsParams: string[] = [];
|
||||||
|
for (let i = 0; i < argCount; i++) {
|
||||||
|
args.push(`arg${i}`);
|
||||||
|
argsParams.push(`arg${i} as object`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const msg = args.map((arg) => {
|
||||||
|
return `ToString(${arg})`;
|
||||||
|
}).join(` + " " + `);
|
||||||
|
|
||||||
|
const func = logFunctions[level as 'LogError' | 'LogWarn' | 'LogInfo' | 'LogDebug'];
|
||||||
|
|
||||||
|
return `
|
||||||
|
function ${newFunctionName}(${args.join(', ')}) as void
|
||||||
|
logger = m.global.logger
|
||||||
|
if logger.logLevel < ${func.level}
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
m.global.logger.logLine = "[${func.stringLevel}]" + ${msg}
|
||||||
|
end function
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
return new LoggerPlugin();
|
||||||
|
};
|
||||||
Reference in new issue
Block a user