286 lines
145 KiB
HTML
286 lines
145 KiB
HTML
|
|
||
|
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
|
||
|
<meta charset="utf-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
||
|
<title>
|
||
|
components/config/ServerDiscoveryTask.brs - Documentation
|
||
|
</title>
|
||
|
|
||
|
<link href="https://www.braintreepayments.com/images/favicon-ccda0b14.png" rel="icon" type="image/png">
|
||
|
|
||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
|
||
|
<script>hljs.initHighlightingOnLoad();</script>
|
||
|
|
||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
||
|
|
||
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<!-- start Mixpanel -->
|
||
|
<script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
|
||
|
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
||
|
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
|
||
|
mixpanel.init("1919205b2da72e4da3b9b6639b444d59");</script>
|
||
|
<!-- end Mixpanel -->
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
<svg style="display: none;">
|
||
|
<defs>
|
||
|
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
||
|
<path d="M0 0h24v24H0z" fill="none"/>
|
||
|
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
|
||
|
</symbol>
|
||
|
</defs>
|
||
|
</svg>
|
||
|
|
||
|
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
||
|
<label for="nav-trigger" class="navicon-button x">
|
||
|
<div class="navicon"></div>
|
||
|
</label>
|
||
|
|
||
|
<label for="nav-trigger" class="overlay"></label>
|
||
|
|
||
|
<div class="top-nav-wrapper">
|
||
|
<ul>
|
||
|
<li >
|
||
|
<a href="index.html">
|
||
|
|
||
|
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
||
|
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
|
||
|
<path d="M0 0h24v24H0z" fill="none"/>
|
||
|
</svg>
|
||
|
|
||
|
|
||
|
</a>
|
||
|
</li>
|
||
|
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
</div>
|
||
|
|
||
|
<nav>
|
||
|
<h3 class="reference-title">
|
||
|
Braintree SDK Client Reference
|
||
|
</h3>
|
||
|
|
||
|
|
||
|
|
||
|
<h3>Classes</h3><ul><li id="Logger-nav"><a href="module-log.Logger.html">Logger</a><ul class='methods'><li data-type="method" id="Logger-debug-nav"><a href="module-log.Logger.html#debug">debug</a></li><li data-type="method" id="Logger-decreaseIndent-nav"><a href="module-log.Logger.html#decreaseIndent">decreaseIndent</a></li><li data-type="method" id="Logger-error-nav"><a href="module-log.Logger.html#error">error</a></li><li data-type="method" id="Logger-increaseIndent-nav"><a href="module-log.Logger.html#increaseIndent">increaseIndent</a></li><li data-type="method" id="Logger-info-nav"><a href="module-log.Logger.html#info">info</a></li><li data-type="method" id="Logger-log-nav"><a href="module-log.Logger.html#log">log</a></li><li data-type="method" id="Logger-method-nav"><a href="module-log.Logger.html#method">method</a></li><li data-type="method" id="Logger-resetIndent-nav"><a href="module-log.Logger.html#resetIndent">resetIndent</a></li><li data-type="method" id="Logger-toString-nav"><a href="module-log.Logger.html#toString">toString</a></li><li data-type="method" id="Logger-verbose-nav"><a href="module-log.Logger.html#verbose">verbose</a></li><li data-type="method" id="Logger-warn-nav"><a href="module-log.Logger.html#warn">warn</a></li></ul></li></ul><h3>Modules</h3><ul><li id="AlbumData-nav"><a href="module-AlbumData.html">AlbumData</a><ul class='methods'><li data-type="method" id="AlbumData-setFields-nav"><a href="module-AlbumData.html#.setFields">setFields</a></li></ul></li><li id="AlbumGrid-nav"><a href="module-AlbumGrid.html">AlbumGrid</a><ul class='methods'><li data-type="method" id="AlbumGrid-getData-nav"><a href="module-AlbumGrid.html#.getData">getData</a></li><li data-type="method" id="AlbumGrid-init-nav"><a href="module-AlbumGrid.html#.init">init</a></li><li data-type="method" id="AlbumGrid-onKeyEvent-nav"><a href="module-AlbumGrid.html#.onKeyEvent">onKeyEvent</a></li></ul></li><li id="AlbumTrackList-nav"><a href="module-AlbumTrackList.html">AlbumTrackList</a><ul class='methods'><li data-type="method" id="AlbumTrackList-getData-nav"><a href="module-AlbumTrackList.html#.getData">getData</a></li><li data-type="method" id="AlbumTrackList-init-nav"><a href="module-AlbumTrackList.html#.init">init</a></li></ul></li><li id="AlbumView-nav"><a href="module-AlbumView.html">AlbumView</a><ul class='methods'><li data-type="method" id="AlbumView-OnScreenHidden-nav"><a href="module-AlbumView.html#.OnScreenHidden">OnScreenHidden</a></li><li data-type="method" id="AlbumView-adjustScreenForNoOverview-nav"><a href="module-AlbumView.html#.adjustScreenForNoOverview">adjustScreenForNoOverview</a></li><li data-type="method" id="AlbumView-createDialogPallete-nav"><a href="module-AlbumView.html#.createDialogPallete">createDialogPallete</a></li><li data-type="method" id="AlbumView-createFullDscrDlg-nav"><a href="module-AlbumView.html#.createFullDscrDlg">createFullDscrDlg</a></li><li data-type="method" id="AlbumView-init-nav"><a href="module-AlbumView.html#.init">init</a></li><li data-type="method" id="AlbumView-onDoneLoading-nav"><a href="module-AlbumView.html#.onDoneLoading">onDoneLoading</a></li><li data-type="method" id="AlbumView-onKeyEvent-nav"><a href="module-AlbumView.html#.onKeyEvent">onKeyEvent</a></li><li data-type="method" id="AlbumView-pageContentChanged-nav"><a href="module-AlbumView.html#.pageContentChanged">pageContentChanged</a></li><li data-type="method" id="AlbumView-setOnScreenTextValues-nav"><a href="module-AlbumView.html#.setOnScreenTextValues">setOnScreenTextValues</a></li><li data-type="method" id="AlbumView-setPosterImage-nav"><a href="module-AlbumView.html#.setPosterImage">setPosterImage</a></li><li data-type="method" id="AlbumView-setScreenTitle-nav"><a href="module-AlbumView.html#.setScreenTitle">setScreenTitle</a></li><li data-type="method" id="AlbumView-setupMainNode-nav"><a href="module-AlbumView.html#.setupMainNode">setupMainNode</a></li></ul></li><li id="Alpha-nav"><a href="module-Alpha.html">Alpha</a><ul class='methods'><li data-type="method" id="Alpha-init-nav"><a href="module-Alpha.html#.init">
|
||
|
</nav>
|
||
|
|
||
|
<div id="main">
|
||
|
|
||
|
<h1 class="page-title">
|
||
|
components/config/ServerDiscoveryTask.brs
|
||
|
</h1>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<section>
|
||
|
<article>
|
||
|
<pre class="prettyprint source linenums"><code>import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||
|
|
||
|
'
|
||
|
' Task used to discover jellyfin servers on the local network
|
||
|
'
|
||
|
sub init()
|
||
|
m.log = log.Logger("ServerDiscoveryTask")
|
||
|
m.top.functionName = "execute"
|
||
|
end sub
|
||
|
|
||
|
sub execute()
|
||
|
m.servers = []
|
||
|
m.serverUrlMap = {}
|
||
|
m.locationUrlMap = {}
|
||
|
'send both requests at the same time
|
||
|
SendSSDPBroadcast()
|
||
|
SendClientDiscoveryBroadcast()
|
||
|
|
||
|
ts = CreateObject("roTimespan")
|
||
|
maxTimeMs = 2200
|
||
|
|
||
|
'monitor each port and collect messages
|
||
|
while True
|
||
|
elapsed = ts.TotalMilliseconds()
|
||
|
if elapsed >= maxTimeMs
|
||
|
exit while
|
||
|
end if
|
||
|
|
||
|
msg = Wait(100, m.ssdp.port)
|
||
|
if msg <> invalid
|
||
|
ProcessSSDPResponse(msg)
|
||
|
end if
|
||
|
|
||
|
msg = Wait(100, m.clientDiscovery.port)
|
||
|
if msg <> invalid
|
||
|
ProcessClientDiscoveryResponse(msg)
|
||
|
end if
|
||
|
|
||
|
end while
|
||
|
|
||
|
m.top.content = m.servers
|
||
|
m.log.debug("Jellyfin servers found", m.servers[0], m.servers[1], m.servers[2])
|
||
|
end sub
|
||
|
|
||
|
sub AddServer(server)
|
||
|
if m.serverUrlMap[server.baseUrl] = invalid
|
||
|
m.serverUrlMap[server.baseUrl] = true
|
||
|
m.servers.push(server)
|
||
|
end if
|
||
|
end sub
|
||
|
|
||
|
sub SendClientDiscoveryBroadcast()
|
||
|
m.clientDiscovery = {
|
||
|
port: CreateObject("roMessagePort"),
|
||
|
address: CreateObject("roSocketAddress"),
|
||
|
socket: CreateObject("roDatagramSocket"),
|
||
|
urlTransfer: CreateObject("roUrlTransfer")
|
||
|
}
|
||
|
m.clientDiscovery.address.SetAddress("255.255.255.255:7359")
|
||
|
m.clientDiscovery.urlTransfer.SetPort(m.clientDiscoveryPort)
|
||
|
m.clientDiscovery.socket.SetMessagePort(m.clientDiscovery.port)
|
||
|
m.clientDiscovery.socket.SetSendToAddress(m.clientDiscovery.address)
|
||
|
m.clientDiscovery.socket.NotifyReadable(true)
|
||
|
m.clientDiscovery.socket.SetBroadcast(true)
|
||
|
m.clientDiscovery.socket.SendStr("Who is JellyfinServer?")
|
||
|
end sub
|
||
|
|
||
|
sub ProcessClientDiscoveryResponse(message)
|
||
|
if Type(message) = "roSocketEvent" and message.GetSocketId() = m.clientDiscovery.socket.GetId() and m.clientDiscovery.socket.IsReadable()
|
||
|
try
|
||
|
responseJson = m.clientDiscovery.socket.ReceiveStr(4096)
|
||
|
server = ParseJson(responseJson)
|
||
|
AddServer({
|
||
|
name: server.Name,
|
||
|
baseUrl: server.Address,
|
||
|
'hardcoded icon since this service doesn't include them
|
||
|
iconUrl: "pkg:/images/logo-icon120.jpg",
|
||
|
iconWidth: 120,
|
||
|
iconHeight: 120
|
||
|
})
|
||
|
m.log.info("Found Jellyfin server using client discovery", server.Address)
|
||
|
catch e
|
||
|
m.log.error("Error scanning for jellyfin server", message)
|
||
|
end try
|
||
|
end if
|
||
|
end sub
|
||
|
|
||
|
sub SendSSDPBroadcast()
|
||
|
m.ssdp = {
|
||
|
port: CreateObject("roMessagePort"),
|
||
|
address: CreateObject("roSocketAddress"),
|
||
|
socket: CreateObject("roDatagramSocket"),
|
||
|
urlTransfer: CreateObject("roUrlTransfer")
|
||
|
}
|
||
|
m.ssdp.address.SetAddress("239.255.255.250:1900")
|
||
|
m.ssdp.socket.SetMessagePort(m.ssdp.port)
|
||
|
m.ssdp.socket.SetSendToAddress(m.ssdp.address)
|
||
|
m.ssdp.socket.NotifyReadable(true)
|
||
|
m.ssdp.urlTransfer.SetPort(m.ssdp.port)
|
||
|
|
||
|
'brightscript can't escape characters in strings, so create a few vars here so we can use them in the strings below
|
||
|
Q = Chr(34)
|
||
|
CRLF = Chr(13) + Chr(10)
|
||
|
|
||
|
ssdpStr = "M-SEARCH * HTTP/1.1" + CRLF
|
||
|
ssdpStr += "HOST: 239.255.255.250:1900" + CRLF
|
||
|
ssdpStr += "MAN: " + Q + "ssdp:discover" + Q + CRLF
|
||
|
ssdpStr += "ST:urn:schemas-upnp-org:device:MediaServer:1" + CRLF
|
||
|
ssdpStr += "MX: 2" + CRLF
|
||
|
ssdpStr += CRLF
|
||
|
|
||
|
m.ssdp.socket.SendStr(ssdpStr)
|
||
|
end sub
|
||
|
|
||
|
sub ProcessSSDPResponse(message)
|
||
|
locationUrl = invalid
|
||
|
if Type (message) = "roSocketEvent" and message.GetSocketId() = m.ssdp.socket.GetId() and m.ssdp.socket.IsReadable()
|
||
|
recvStr = m.ssdp.socket.ReceiveStr(4096)
|
||
|
match = CreateObject("roRegex", "\r\nLocation:\s*(.*?)\s*\r\n", "i").Match(recvStr)
|
||
|
if match.Count() = 2
|
||
|
locationUrl = match[1]
|
||
|
end if
|
||
|
end if
|
||
|
|
||
|
if locationUrl = invalid
|
||
|
return
|
||
|
else if m.locationUrlMap[locationUrl] <> invalid
|
||
|
m.log.warn("Already discovered this location", locationUrl)
|
||
|
return
|
||
|
end if
|
||
|
|
||
|
m.locationUrlMap[locationUrl] = true
|
||
|
|
||
|
http = CreateObject("roUrlTransfer")
|
||
|
http.SetUrl(locationUrl)
|
||
|
responseText = http.GetToString()
|
||
|
xml = CreateObject("roXMLElement")
|
||
|
'if we successfully parsed the response, process it
|
||
|
if xml.Parse(responseText)
|
||
|
deviceNode = xml.GetNamedElementsCi("device")[0]
|
||
|
manufacturer = deviceNode.GetNamedElementsCi("manufacturer").GetText()
|
||
|
'only process jellyfin servers
|
||
|
if lcase(manufacturer) = "jellyfin"
|
||
|
'find the largest icon
|
||
|
width = 0
|
||
|
server = invalid
|
||
|
icons = deviceNode.GetNamedElementsCi("iconList")[0].GetNamedElementsCi("icon")
|
||
|
for each iconNode in icons
|
||
|
iconUrl = iconNode.GetNamedElementsCi("url").GetText()
|
||
|
baseUrl = invalid
|
||
|
match = CreateObject("roRegex", "(.*?)\/dlna\/", "i").Match(iconUrl)
|
||
|
if match.Count() = 2
|
||
|
baseUrl = match[1]
|
||
|
end if
|
||
|
loopResult = {
|
||
|
name: deviceNode.GetNamedElementsCi("friendlyName").GetText(),
|
||
|
baseUrl: baseUrl,
|
||
|
iconUrl: iconUrl,
|
||
|
iconWidth: iconNode.GetNamedElementsCi("width")[0].GetText().ToInt(),
|
||
|
iconHeight: iconNode.GetNamedElementsCi("height")[0].GetText().ToInt()
|
||
|
}
|
||
|
if baseUrl <> invalid and loopResult.iconWidth > width
|
||
|
width = loopResult.iconWidth
|
||
|
server = loopResult
|
||
|
end if
|
||
|
end for
|
||
|
AddServer(server)
|
||
|
m.log.info("Found jellyfin server using SSDP and DLNA", server.baseUrl)
|
||
|
end if
|
||
|
end if
|
||
|
end sub
|
||
|
</code></pre>
|
||
|
</article>
|
||
|
</section>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<br class="clear">
|
||
|
|
||
|
<footer>
|
||
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a>
|
||
|
</footer>
|
||
|
|
||
|
<script src="scripts/linenumber.js"></script>
|
||
|
<script src="scripts/pagelocation.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|