Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
msbsankar2u
Visitor

How to implement rendezvous style registration?

Hi to all,

I am new to ROKU development and i would like to know how to implement Rendezvous style registration. Can anyone please explain me in detail step by step process to implement rendezvous registration.

I went through the documentation and examples provided by ROKU. And i have developed a sample channel that make use of rendezvous registration.I would like to share what i have done and please give me suggestions weather i am correct or not.

ROKU code logic,
1. When the user enters into channel, the home screen will be displayed with a list of programs. when the user clicks/selects any of the programs on the home screen, Registration method gets called and checks weather user is registered or not. If user is not registered, Registration screen will be displayed prompting user, go to the website and enter activation code shown on the TV screen connected to your Roku box.

2. In Registration method what i have done is, (Subscription period of the user is 1 month)

a) First of all i am checking weather the device token for my channel is stored or not. If device token already exists (i.e user is registered) then i am checking the subscription period (i.e for one month, for subscription period checking i am calling a web service that checks expire status, weather user subscription period is over or not). If the user subscription period is not finished then the user is allowed to next screen else device registration token will be deleted from registry of my channel.
And if the token is not stored in registry (i.e user is not registered) then registration screen will be displayed with activation code (i.e the activation code is generated by web service), the user should go to the website and enter the activation code displayed on TV Screen, if user enters the activation code correctly, then in response the token will be sent to ROKU box and stored in registry.

Is the above mentioned process correct or not?
Please explain in detail about the Rendezvous style registration step by step.

Below i am enclosing the code, Please check;

'******************************************************
'** Display the home screen and wait for events from
'** the screen. The screen will show retreiving while
'** we fetch and parse the feeds for the game posters
'******************************************************
Function showHomeScreen(screen) As Integer

if validateParam(screen, "roPosterScreen", "showHomeScreen") = false return -1

initCategoryList()
screen.SetContentList(m.Categories.Kids)
screen.SetFocusedListItem(3)
screen.Show()

while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roPosterScreenEvent" then
if msg.isListFocused() then
print "list focused | index = "; msg.GetIndex(); " | category = "; m.curCategory
else if msg.isListItemSelected() then
registrationstatus = doRegistration()
if registrationstatus = 0 then
kid = m.Categories.Kids[msg.GetIndex()]
if kid.type = "special_category" then
displaySpecialCategoryScreen()
else
displayCategoryPosterScreen(kid)
end if
end if
else if msg.isScreenClosed() then
return -1
end if
end If
end while

return 0
End Function

Function doRegistration() As Integer
m.UrlBase = "http://example.com/restserviceimpl"
m.UrlGetRegCode = m.UrlBase + "/getCode"
m.UrlGetRegResult = m.UrlBase + "/getRegToken"
m.UrlGetExpireStatus = m.UrlBase + "/AccountExpireStatus"
m.UrlWebSite = "http://example.com/roku"

m.RegToken = loadRegistrationToken()
expStatus = getAccountExpireStatus(m.RegToken)
if isLinked() then
if expStatus = "continue" then
return 0
else if expStatus = "terminate" then
deleteRegistrationToken()
end if
endif

regscreen = displayRegistrationScreen()
while true
duration = 0
sn = GetDeviceESN()
regCode = getRegistrationCode(sn)
if regCode = "" then return 2
regscreen.SetRegistrationCode(regCode)
while true
status = checkRegistrationStatus(sn, regCode)
if status < 3 return status
getNewCode = false
retryInterval = getRetryInterval()
retryDuration = getRetryDuration()
while true
msg = wait(retryInterval * 1000, regscreen.GetMessagePort())
duration = duration + retryInterval
if msg = invalid exit while

if type(msg) = "roCodeRegistrationScreenEvent"
if msg.isScreenClosed()
'print "Screen closed"
return 1
elseif msg.isButtonPressed()
if msg.GetIndex() = 0
regscreen.SetRegistrationCode("retrieving code...")
getNewCode = true
exit while
endif
if msg.GetIndex() = 1 return 1
endif
endif
end while

if duration > retryDuration exit while
if getNewCode exit while
end while
end while

End Function


'********************************************************************
'** display the registration screen in its initial state with the
'** text "retreiving..." shown. We'll get the code and replace it
'** in the next step after we have something onscreen for teh user
'********************************************************************
Function displayRegistrationScreen() As Object

regsite = "go to " + m.UrlWebsite
regscreen = CreateObject("roCodeRegistrationScreen")
regscreen.SetMessagePort(CreateObject("roMessagePort"))

regscreen.SetTitle("")
regscreen.AddParagraph("movies contains premium movies. For instance access")
regscreen.AddFocalText(" ", "spacing-dense")
regscreen.AddFocalText("Visit www.example.com/roku and Click on ROKU movies Activation to", "spacing-dense")
regscreen.AddFocalText("enter this code :", "spacing-dense")
regscreen.SetRegistrationCode("retrieving code...")
regscreen.AddParagraph("This screen will automatically update as soon as your activation completes")
regscreen.AddButton(0, "Get a new code")
regscreen.AddButton(1, "Back")
regscreen.Show()

return regscreen

End Function


'********************************************************************
'** Fetch the prelink code from the registration service. return
'** valid registration code on success or an empty string on failure
'********************************************************************
Function getRegistrationCode(sn As String) As String

if sn = "" then return ""

http = NewHttp(m.UrlGetRegCode)
http.AddParam("partner", "roku")
http.AddParam("deviceID", sn)
http.AddParam("deviceTypeName", "roku")

rsp = http.Http.GetToString()
xml = CreateObject("roXMLElement")
if not xml.Parse(rsp) then
ShowConnectionFailed()
return ""
endif

if xml.GetName() <> "result"
ShowConnectionFailed()
return ""
endif

if islist(xml.GetBody()) = false then
ShowConnectionFailed()
return ""
endif
retryInterval = 30 'seconds
retryDuration = 900 'seconds (aka 15 minutes)
regCode = ""
for each e in xml.GetBody()
if e.GetName() = "regCode" then
regCode = e.GetBody() 'enter this code at website
elseif e.GetName() = "retryInterval" then
retryInterval = strtoi(e.GetBody())
elseif e.GetName() = "retryDuration" then
retryDuration = strtoi(e.GetBody())
endif
next

if regCode = "" then
'Dbg("Parse yields empty registration code")
ShowConnectionFailed()
endif

m.retryDuration = retryDuration
m.retryInterval = retryInterval
m.regCode = regCode

return regCode

End Function


'******************************************************************
'** Check the status of the registration to see if we've linked
'** Returns:
'** 0 - We're registered. Proceed.
'** 1 - Reserved. Used by calling function.
'** 2 - We're not registered. There was an error, abort.
'** 3 - We're not registered. Keep trying.
'******************************************************************
Function checkRegistrationStatus(sn As String, regCode As String) As Integer

http = NewHttp(m.UrlGetRegResult)
http.AddParam("partner", "roku")
http.AddParam("deviceID", sn)
http.AddParam("regCode", regCode)

print "checking registration status"

while true
rsp = http.Http.GetToString()
xml = CreateObject("roXMLElement")
if not xml.Parse(rsp) then
print "Can't parse check registration status response"
ShowConnectionFailed()
return 2
endif

if xml.GetName() <> "result" then
print "unexpected check registration status response: ", xml.GetName()
ShowConnectionFailed()
return 2
endif

if islist(xml.GetBody()) = true then
for each e in xml.GetBody()
if e.GetName() = "regToken" then
token = e.GetBody()

if token <> "" and token <> invalid then
print "obtained registration token: " + validstr(token)
saveRegistrationToken(token) 'commit it
m.RegistrationToken = token
showCongratulationsScreen()
return 0
else
return 3
endif
elseif e.GetName() = "customerId" then
customerId = strtoi(e.GetBody())
elseif e.GetName() = "creationTime" then
creationTime = strtoi(e.GetBody())
endif
next
endif
end while

print "result: " + validstr(regToken) + " for " + validstr(customerId) + " at " + validstr(creationTime)

return 3

End Function

'***************************************************************
' The retryInterval is used to control how often we retry and
' check for registration success. its generally sent by the
' service and if this hasn't been done, we just return defaults
'***************************************************************
Function getRetryInterval() As Integer
if m.retryInterval < 1 then m.retryInterval = 30
return m.retryInterval
End Function


'**************************************************************
' The retryDuration is used to control how long we attempt to
' retry. this value is generally obtained from the service
' if this hasn't yet been done, we just return the defaults
'**************************************************************
Function getRetryDuration() As Integer
if m.retryDuration < 1 then m.retryDuration = 900
return m.retryDuration
End Function


'******************************************************
'Load/Save RegistrationToken to registry
'******************************************************

Function loadRegistrationToken() As dynamic
m.RegToken = RegRead("RegToken", "Authentication")
if m.RegToken = invalid then m.RegToken = ""
return m.RegToken
End Function

Sub saveRegistrationToken(token As String)
RegWrite("RegToken", token, "Authentication")
End Sub

Sub deleteRegistrationToken()
RegDelete("RegToken", "Authentication")
m.RegToken = ""
End Sub

Function isLinked() As Dynamic
if Len(m.RegToken) > 0 then return true
return false
End Function

'******************************************************
'Show congratulations screen
'******************************************************
Sub showCongratulationsScreen()
port = CreateObject("roMessagePort")
screen = CreateObject("roParagraphScreen")
screen.SetMessagePort(port)

screen.AddHeaderText("Congratulations!")
screen.AddParagraph("You have successfully linked your Roku player to your account")
screen.AddParagraph("Select 'start' to begin.")
screen.AddButton(1, "start")
screen.Show()

while true
msg = wait(0, screen.GetMessagePort())

if type(msg) = "roParagraphScreenEvent"
if msg.isScreenClosed()
'print "Screen closed"
exit while
else if msg.isButtonPressed()
'print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
exit while
else
'print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
exit while
endif
endif
end while
End Sub

'********************************************************************
'** Fetch the status of the account validity
'********************************************************************
Function getAccountExpireStatus(sn As String) As String

if sn = "" then return ""

http = NewHttp(m.UrlGetExpireStatus)
http.AddParam("regtoken", sn)

rsp = http.Http.GetToString()
xml = CreateObject("roXMLElement")
'print "GOT: " + rsp
'print "Reason: " + http.Http.GetFailureReason()

if not xml.Parse(rsp) then
'print "Can't parse getAccountExpireStatus response"
ShowConnectionFailed()
return ""
endif

if xml.GetName() <> "result"
'Dbg("Bad expire response: ", xml.GetName())
ShowConnectionFailed()
return ""
endif

if islist(xml.GetBody()) = false then
'Dbg("No expire information available")
ShowConnectionFailed()
return ""
endif

'handle validation of response fields
for each e in xml.GetBody()
if e.GetName() = "Expirestatus" then
expireStatus = e.GetBody()
endif
next

if expireStatus = "" then
'Dbg("Parse yields empty registration code")
ShowConnectionFailed()
endif

return expireStatus

End Function

'******************************************************
'Registry Helper Functions
'******************************************************
Function RegRead(key, section=invalid)
if section = invalid then section = "Default"
sec = CreateObject("roRegistrySection", section)
if sec.Exists(key) then return sec.Read(key)
return invalid
End Function

Function RegWrite(key, val, section=invalid)
if section = invalid then section = "Default"
sec = CreateObject("roRegistrySection", section)
sec.Write(key, val)
sec.Flush() 'commit it
End Function

Function RegDelete(key, section=invalid)
if section = invalid then section = "Default"
sec = CreateObject("roRegistrySection", section)
sec.Delete(key)
sec.Flush()
End Function
1 REPLY 1
RokuKevin
Visitor

Re: How to implement rendezvous style registration?

That sounds right to me.... Have you looked at the 'register' example in the SDK. Open the source and read the comments about how to replace hard coded methods with queries to your server. You will have to implement the server side of the solution yourself by integrating with your user database.

--Kevin
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.