Forum Discussion

EnTerr's avatar
EnTerr
Roku Guru
10 years ago

Getting channel's ID, how? [answer: roAppInfo.getID()]

I wonder how a program running on Roku can figure out its channel ID? The (mostly) numeric ID that's used to /launch or /input to.

There are situations that can be useful, one is for a shared/library code between different channels. Another one i have at hand is, say i have two of the same channels - one with ID "12345", the other one "23456". 12345 is a beta, 23456 is a release - they are exactly the same as code base and even use the same registry but need to act a hair differently - say one shows a "beta" placard. So if when started, the code can check "who am i?" - then it can implement that local difference based on hearing back the ID.

Seems to me appropriate place for this is a method (getSelfID? getAppID?) in roDeviceInfo but nothing related i can find so far.

9 Replies

  • is roAppInfo's GetID() not what your looking for?
  • Why yes - yes, it is!

    It's a... it's a <cough> new API :oops:

    thank you
  • Even though I answered that question I never actually thought of doing that till you asked, now my statistics dashboard can distinguish between dev (sideloaded), testing, and production. Realized that once we got published knowing if I'm seeing a pattern or issue in test or in production was a huge need. A case where I really am glad you asked.
  • "sjb64" wrote:
    Even though I answered that question I never actually thought of doing that till you asked, now my statistics dashboard can distinguish between dev (sideloaded), testing, and production. Realized that once we got published knowing if I'm seeing a pattern or issue in test or in production was a huge need. A case where I really am glad you asked.

    "You are welcome!" :mrgreen:
    Watch out for my new book "How to Ask the Right Questions (or On Strategic Ignorance)" Smiley LOL

    A bit more serious, i call this the Docendo discimus (Latin "by teaching, we learn") effect. At least I find myself understanding things better by answering questions here, StackOverflow etc

    Congrats on getting published (8/11), btw!
    Ha! 51 channels published on 8/13. FIFTY ONE. In one day. Really?!
    I wonder if there is a day (once a month? once a quarter?) when the Co says "oh, f**k it - open the gate, flush the queue, everybody gets a pass"?
  • Just for fun, here's how I did it before getID() was implemented. Anyone writing private channels they want to run on Legacy will still need something like this to get the Channel ID (mIght be some bugs in this code, esp. with regards to handling side-loadedness):


    'exerpted from a set of private functions in an AA

    ChannelID: function () as string
    'get ip from deviceIP function
    ip=m.deviceIP()
    m.ipAddress=ip
    'read manifest file from local storage
    manifest=readAsciiFile("pkg:/manifest")

    'convert manifest file into array delimited by carriage returns
    phase1=manifest.tokenize(chr(10))

    'iterate through result and find app title
    for each line in phase1
    if lcase(line.left(line.instr("=") ) )="title" then
    apptitle=line.mid(line.instr("=")+1)
    end if
    end for

    'to do: handle case if no title field in manifest

    'get list of apps from device ECP

    xfer=createobject("roURLTransfer")
    xfer.seturl("http://"+ip+":8060/query/apps")
    data=xfer.gettostring()
    xml=createobject("roXMLElement")
    Identity=""
    if xml.parse(data) then
    ?"iterate through all apps in list and find one where the title matches manifest title"

    for each entry in xml.app
    if entry.getText() = apptitle.trim()
    Identity=entry@id
    if instr(identity,"_") > 0 then
    Identity=left(Identity,instr(Identity,"_")-1)
    end if
    end if
    end for

    if identity="dev" then
    ?"ID=DEV"
    return "00000"
    else
    if identity=invalid then
    print "identity is invalid, replacing with 00000"
    identity="00000"
    end if
    if identity="" then
    print "identity is null string, replacing with 00000"
    identity="00000"
    end if
    end if
    else
    ?"got bad xml from device, return null channel id:"
    return identity
    end if
    return identity
    end function

    DeviceIP: function () as string
    di=createobject("rodeviceinfo")
    temp=di.getipaddrs()
    temp.reset()
    while true
    aakey=temp.next()
    if not temp=invalid then
    return temp[aakey]
    end if
    end while
    end function
  • "EnTerr" wrote:
    Congrats on getting published (8/11), btw!
    Ha! 51 channels published on 8/13. FIFTY ONE. In one day. Really?!

    Thanks, we got to spend like a day and a half visible on the new list. Watching historically I told them it would be a week visible, then 2 to 3 on the list, but seems that changed suddenly just in time for us.

    Such is life...

    Watching our install counts with no idea what is a good successful number or a rough start, but still fun to watch.
  • "RokuJoel" wrote:
    Just for fun, here's how I did it before getID() was implemented. ...

    I like how you parse the manifest for the channel name, so it does not have to be supplied (so potentially can be part of shared library).

    I thought about peeking in /query/apps but that wouldn't have helped in my case (or sjb64's), since i could have all 3 installed together - dev, beta and public - all with the same name but different ID. So a search can return the first (or last, or all) ID but not help me know "who am i".
  • "RokuJoel" wrote:
    Just for fun, here's how I did it before getID() was implemented. ...

    Makes me realize how easy I've had it having joined the rokudev world well after 3.1 (actually right at 6.1).
  • "sjb64" wrote:
    Thanks, we got to spend like a day and a half visible on the new list. Watching historically I told them it would be a week visible, then 2 to 3 on the list, but seems that changed suddenly just in time for us.

    Such is life...

    Agreed - does not seem fair getting buried under a 6 screens avalanche just a day or two after debut. Heck, it is unfair even to the bottom half of that truckload of 51. They should spread such "goodness" over longer period, say drip 3 per day for a month.

    Watching our install counts with no idea what is a good successful number or a rough start, but still fun to watch.

    You got thousands of downloads already - that is (was?) good! I see also floated up a little in "Movies and TV" category, being more fortunate than DirecTV's "Yaveo". Though, i presume the release of Yaveo for Roku will be drummed up soon and shoot way up.