Page 1 of 1

How to enable remote access for Twonky Server 7.2.x

Posted: Thu May 15, 2014 1:09 am
by phibertron
Twonky Server might not officially support remote access in the Web Interface, but it is possible to get working.

If you have ever done a port forward on your router to the twonky server
and wondered why when you click on items or links, they wont display or play correctly...

For Example

the following shows one scenario that it is putting a local ip address in the url

Code: Select all

http://twonkyserver:9000/webbrowse#http://192.168.208.148:9000/nmc/rss/server/...
here is another where the link for a video is pointing to a local ip

Code: Select all

http://192.168.208.148:9000/disk/DLNA/O0$3$27I268.mp4
This isn't an issue when you are connected to your network locally,
but it is a problem if you are connecting remotely as those local ip links wont work as intended

The next few posts will show you what to change to make things work as you might have expected them to
such that when going to your server url for example twonkyserver:9000
you would see things like this

a url link use in navigation for example

Code: Select all

http://twonkyserver:9000/webbrowse#http://twonkyserver:9000/nmc/rss/server/...
a link to a video for example

Code: Select all

http://twonkyserver:9000/disk/DLNA/O0$3$27I268.mp4
NOTE:
even with all of these changes, this solution does not solve beaming from web interface
I need to work on code changes to a the beam.js and main.js to make that work
.

1. Open the file "browse.js" file for editing

Posted: Thu May 15, 2014 1:13 am
by phibertron
1. Open the file "browse.js" file for editing

C:\Program Files\Twonky\TwonkyServer\resources\webbrowse

2. Add var hosturl code

Posted: Thu May 15, 2014 1:17 am
by phibertron
2. Add var hosturl code

Code: Select all

//phibertron
//this will get the base url and port used to connect to the server
//this will be use to prepend to any links that are not relative to it
//
var hosturl = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
Place the above code in between this section

Code: Select all

// number of calls needed to find the container thumbnail
var getThumbnailCalls;

// ---- Initialize the Browse application
function initPage() {
So that it looks like this

Code: Select all

// number of calls needed to find the container thumbnail
var getThumbnailCalls;

//phibertron
//this will get the base url and port used to connect to the server
//this will be use to prepend to any links that are not relative to it
//
var hosturl = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');

// ---- Initialize the Browse application
function initPage() {

3 Edit the function isServer

Posted: Thu May 15, 2014 1:20 am
by phibertron
3 Edit the function isServer

So that it looks like this

Code: Select all

function isServer(elem, index, port1) {
    var isLocalDevice = (getNMCPropertyText(elem, "item.server.isLocalDevice", index) == "true");
    //var port2 = getPort(getNMCPropertyText(elem, "item.server.baseURL", index));
    // server found if running on local device and server port is current port

    //phibertron
    //if (isLocalDevice && (port1 == port2)) return true;
    //the port check is not done to allow for router port forwards that are different than the server port
    //
    if (isLocalDevice) return true;
    return false;
}

4 Edit the function getThumbnail

Posted: Thu May 15, 2014 1:24 am
by phibertron
4 Edit the function getThumbnail

So that it looks like this

Code: Select all

function getThumbnail(elem) {
    try {
        var albumArtURI = true;
        var resValue = true;
        if (!itemHasProperty(elem, "meta")) return "";
        if (!itemHasProperty(elem, "meta.upnp:albumArtURI")) albumArtURI = false;
        if (!itemHasProperty(elem, "meta.res")) resValue = false;
        if (resValue) if (!(elem.meta.res.length > 0)) resValue = false;
        if (!albumArtURI && !resValue) return "";

        //phibertron
        //if (albumArtURI) return elem.meta["upnp:albumArtURI"];
        //this will return container thumbnail image links relative to the hosturl
        //
        if (albumArtURI) { //return elem.meta["upnp:albumArtURI"];
           var metaitemurl = elem.meta["upnp:albumArtURI"];
           metaitemurl = "/" + metaitemurl.split("/").slice(3).join("/");
           return hosturl + metaitemurl;
        }

        if (resValue) {
           var resIndex = 0;
           if (elem.meta.res.length > 1) resIndex = 1;

           //phibertron 
           //return elem.meta.res[resIndex].value;
           //this will return item thumbnail image links relative to the hosturl
           //
           var resitemurl = elem.meta.res[resIndex].value;
           resitemurl = "/" + resitemurl.split("/").slice(3).join("/");
           return hosturl + resitemurl;
        }
        return "";
    } catch (e) {
        return "";
    }
}

5 Edit the function getNMCPropertyText

Posted: Thu May 15, 2014 1:27 am
by phibertron
5 Edit the function getNMCPropertyText

So that it looks like this

Code: Select all

function getNMCPropertyText(elem, property, index) {
    try {
        switch (property) {
            case "parentList.id":
                return elem.parentList[index].id

            case "parentList.url":
                //phibertron
                //return elem.parentList[index].url;
                //this will return breadcrumb links relative to the hosturl
                //
                var itemurl = elem.parentList[index].url;
                itemurl = "/" + itemurl.split("/").slice(3).join("/");
                return hosturl + itemurl;

            case "parentList.title":
                return elem.parentList[index].title;
            case "parentList.childCount":
                return elem.parentList[index].childCount;
            case "id":
                return elem.id;
            case "title":
                return elem.title;

            case "url":
                //phibertron
                //return elem.enclosure.url;
                //this will return url links relative to the hosturl
                //
                var itemurl = elem.enclosure.url;
                itemurl = "/" + itemurl.split("/").slice(3).join("/");
                return hosturl + itemurl;

            case "item.url":
                //phibertron
                //return elem.item[index].enclosure.url;
                //this will return url links relative to the hosturl
                //
                var itemurl = elem.item[index].enclosure.url;
                itemurl = "/" + itemurl.split("/").slice(3).join("/");
                return hosturl + itemurl;

            case "item.id":
                return elem.item[index].id;
            case "meta.id":
                return elem.meta.id;
            case "meta.title":
                return elem.meta['dc:title'];
            case "meta.album":
                return elem.meta['upnp:album'];
            case "meta.artist":
                return elem.meta['upnp:artist'];
            case "meta.genre":
                return elem.meta['upnp:genre'];
            case "res.size":
                return elem.meta.res[0].size;
            case "meta.format":
                return elem.meta['pv:extension'];
            case "meta.date":
                return elem.meta['dc:date'];
            case "item.meta.id":
                return elem.item[index].meta.id;
            case "item.server.isLocalDevice":
                return elem.item[index].server.isLocalDevice;
            case "item.server.baseURL":
                return elem.item[index].server.baseURL;
            case "meta.pv:persistentID":
                return elem.item[index].meta['pv:persistentID'];

            case "meta.res.value":
                //phibertron
                //return elem.meta.res[index].value;
                //this will return res links relative to the hosturl
                //
                var itemurl = elem.meta.res[index].value;
                itemurl = "/" + itemurl.split("/").slice(3).join("/");
                return hosturl + itemurl;

            case "bookmark":
                return elem.bookmark;
            case "childCountContainer":
                return elem.meta['pv:childCountContainer'];
            default:
                return "";
        }
    } catch (e) {
        return "";
    }
}

Re: How to enable remote access for Twonky Server 7.2.x

Posted: Thu May 15, 2014 2:33 am
by phibertron
For Reference, I have put the changes from above in a text file

How to enable remote access for Twonky Server 7.2.x.txt

https://onedrive.live.com/?cid=FE1D7E98 ... MlDUzNtCqg

.