Premise Automatic navigation after unused time

Motorola Premise

franky

Member
After a browser client has gone unused for some amount of time, I'd like it to automatically navigate back to some specified node in the Home; I'll probably just the Custom Root property of a ClientSetting to specify this.

Changes on the WebSession LastUsed property seems to be a convenient way to start a timer. When the timer expires, I was hoping to simply set the WebSessionEx CurrentLocation, but this doesn't seem to be enough to cause the client to redraw. Can anyone give me any ideas on this?

For the next feature after this, I'd like to have a MediaShortcut automatically navigate to the currently playing item (if any) when a user navigates to a MediaZone that happens to have a MedaiShortcut. So any pointers in that area would be much appreciated.
 
I ran the following code from a ScriptMacro and it forces all (AutomationBrowser) Web Sessions to display the Home page.
Code:
for each oSession in Sys.Services.WebServer.Sites.Default_Web_Site.Sessions
	if not oSession.CurrentLocation is nothing then
		set sysevent.ClientSession = oSession
		set oSession.CurrentLocation = sys.GetObject("sys://Home")
	end if
next
  • It iterates through all Web Sessions of the Default Web Site
  • It skips Sessions without a CurrentLocation (like a MiniBrowser web session)
  • It sets the sysevent object to the selected Session (this is crucial)
  • It sets the Session's CurrentLocation to the desired location (i.e. to Home in this example)
In this example, it only acts on Joe's Session.
Code:
for each oSession in Sys.Services.WebServer.Sites.Default_Web_Site.Sessions
	if not oSession.WebUser is nothing then
		if oSession.WebUser.Name = "Joe" then
			if not oSession.CurrentLocation is nothing then
				set sysevent.ClientSession = oSession
				set oSession.CurrentLocation = sys.GetObject("sys://Home")
			end if
		end if
	end if
next

Let us know when you complete the "Inactivity" Module; I'm interested in this feature.
 
Thanks 123, this definitely got me moving along. I have everything basically working but have some follow up questions and curiosities.

First, can you explain the reason for having to use the sysevent object? This does seem essential for this to work, but I don't understand why. At first glance one would think the script could simply set the CurrentLocation on the WebSession object.

Second, I have a new class SessionIdle that extends WebSession. I have a property change script on this class that sets sysevent.ClientSession in order to update the CurrentLocation. If this script assigns "this" to sysevent.ClientSession it encounters a type mismatch runtime error. I found that if I instead assign "sys.GetObject(this.ObjectID)" to sysevent.ClientSession then no error occurs. I speculate this happens because "this" is actually a reference to my SessionIdle extension class rather than a WebSession class, and that "sys.GetObject(this.GetObjectID)" will return a reference to the object's class (the WebSession).

Lastly, using the WebSession.LastUsed property does seem to work, however this property is updated not only in response to actual user actitivity on the session; it also ends up being updated when my script changes the location of the session. In practice this might not be an issue, but I wonder if there is a better way to determine actual user activity on the client session.

Once I have this working well and have selfhosted it for a few days with no problems, I'll post the module.
 
... can you explain the reason for having to use the sysevent object?
I'm not certain but I suspect that assigning a Session object to sysevent.ClientSession triggers some screen-refresh code within AutomationBrowser. On the surface, simply assigning a new location object to sysevent.ClientLocation seems sufficient but, as we've seen, fails to make AutomationBrowser happy.

... If this script assigns "this" to sysevent.ClientSession it encounters a type mismatch runtime error ... if I ... assign "sys.GetObject(this.ObjectID)" to sysevent.ClientSession then no error occurs.
"this" is a pointer to the current object (not a pointer to a class but to an object, as in an instantiation of a class). However, I must admit that 'get the object whose ID is the current one' sure sounds like the object represented by "this"! FWIW, the following are legal (gleaned from MiniBrowser and AutomationBrowser):
set sysevent.ClientSession.mbCurrentObject = this
set sysevent.ClientSession.CurrentLocation = this.TargetLocation

I'd have to see more of your code to understand why "this" is rejected.

BTW, "sys.GetObject(this.ObjectID)" looks and feels krufty ... like a Premise entry into one of those 'obfuscated code' contests!

... I wonder if there is a better way to determine actual user activity on the client session.
Off the top of my head I'd say you'd need to extend some (fundamental) class with a method that gets called by all UI activity. Ugh. Using "LastUsed" is less work.
 
"this" is a pointer to the current object (not a pointer to a class but to an object, as in an instantiation of a class). However, I must admit that 'get the object whose ID is the current one' sure sounds like the object represented by "this"!
Yes, what I was trying to say is that, since the script is on my extension class (i.e. a base class for the WebSession class), the "this" pointer might have type SessionIdle (the base class) rather than type WebSession (the derived class). The krufty (which I guess means "hacky" :( ) line of code perhaps ends up returning a pointer to the full object which would have type WebSession.

I'm speaking from a C++ point of view (which is where my experience is). I really don't know VB very well. In C++, you generally can't automatically cast from a base class to a derived class. I guess though that my theory wouldn't explain why "this" could still be used to reference the ClientSetting property, which is defined by the WebSession class. Perhaps VB does this dynamically for properties but not for assignments.

Here is the property change script on my SessionIdle class for your review.
Code:
' OnChangeIdle

if sysevent.newVal = true then

	' Seems the following line could just be oSession = this but that causes a type mismatch when assigning to sysevent.ClientSession
	' set oSession = this
	set oSession = sys.GetObject(this.ObjectID)

	' If the session has a client setting...
	if not oSession.ClientSetting is nothing then
		set oSetting = oSession.ClientSetting

		' ...and it has a custom root...
		if not oSetting.CustomRoot is nothing then
			set oRoot = oSetting.CustomRoot
		
			' ...and there is a current location...
			if not oSession.CurrentLocation is nothing then
				set oLocation = oSession.CurrentLocation
				
				' ...then change location to the custom root
				set sysevent.ClientSession = oSession
				set oSession.CurrentLocation = oRoot
				
			end if
		
		end if
	
	end if
	
end if

' end
Thanks for the help.

Frank
 
I tried duplicating your work and ended up with an error message in an unexpected place.
  • I extended the WebSession class with a method that triggers whenever LastUsed is updated.
  • The method resets a simple timer.
  • Whenever the timer expires it attempts to set the sysevent.ClientSession.CurrentLocation to Home.
  • It all works fine until the last step when it attempts to assign something to sysevent.ClientSession. It carps that the object does not exist!
That was unexpected! Still scratching my head on this one ...
 
  • Whenever the timer expires it attempts to set the sysevent.ClientSession.CurrentLocation to Home.
  • It all works fine until the last step when it attempts to assign something to sysevent.ClientSession. It carps that the object does not exist!
I suspect there is no ClientSession associated with the sysevent when the timer fires because a timer runs completely asynchronous to any particular session activity. How would Premise know which WebSession to store in sysevent.ClientSession when it fires your timer?

Instead, your timer script could be "this.MyTimerFunction()". "this" is your WebSession extension. Then your MyTimerFunction would assign "this" to sysevent.ClientSession (as you taught me to do). However, that line would probably cause a type mismatch runtime error (like I've described for my situation).
 
Yup, we're on the same page. When the timer expires it calls "this.OnInactivity".

OnInactivity is a method of the extended WebSession class and it is where "sysevent.ClientSession" fails to have any meaning (i.e. is nothing). There's must be a subtle difference in your extended class that allows it to have a valid sysevent.ClientSession object.

The attached image shows the class and the OnInactivity method.

FWIW, here's the code for CreateInactivityTimer:
Code:
'
debugout "<CreateInactivityTimer>"
system.addTimer 15, "this.OnInactivity", 1, "InactivityTimer_" & this.ObjectID
 

Attachments

  • temp.png
    temp.png
    28.9 KB · Views: 29
There's must be a subtle difference in your extended class that allows it to have a valid sysevent.ClientSession object.
Like yours, my class does not see a valid sysevent.ClientSession when running during a timer callback. But the class itself is an extension of a WebSession so "this" in theory should be sufficient. However as said before there is the odd type mismatch when trying to assign "this" to sysevent.ClientSession (which we can apparently work around with the hacky line of code I showed before).
 
I have this reasonably complete and have been using it for several days without problems. It's comprised of one small self contained module, nothing all that clever in it. If anyone is interested I'll upload it.
 
Absolutely, upload it! From my experience, its a) great to pass back to the group B ) others will need it c) this is a constructive friendly group that can provide feedback, advice and instruction on maximizing Premise to its full potential, and your code can standalone or be the basis for someone else's innovation....

Welcome to the cult!

...back to the beach B) ...(actually I am on my way home tomorrow :) )
 
Here's the module. I'd welcome any constructive feedback on general design approach or specific coding techniques. I'll be in Hawaii in August. For now I'll have to live with the rainy weather here in the Seattle area.
 

Attachments

Back
Top