moving from localhost to www

Workarounds and usability notes.

moving from localhost to www

Postby John Robin Dove » Thu May 09, 2019 9:19 am

Hi Clifton,

My project has ground to a halt. This is partly my fault. I have never bothered to test everything on a real web server. I have always assumed that if things worked on XAMPP they would also work on a real web server. They don't. The bigger and more chaotic my files are, the more errors they generate. Different browsers produce different errors. There are all sorts of different error messages. Because my tbk files are too big I cannot dump the actions and this makes things even more difficult. The problems occur mainly when the page is loading. XML files are not found or cannot be parsed, variables remain undefined etc etc. What surprises me most is that none of this happens on XAMPP. The files have always loaded perfectly. Have you any idea why this is so and are there any general rules I could apply?

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Thu May 09, 2019 6:43 pm

Please be aware that any loading issue can make many things fail. Sometimes, only a single issue is the problem and when that is tracked down, then everything may work as expected. If you are connecting to an online database using PHP or some other scripting language, this is the first place that I would look at.

I am working on a large XML/ToolBook project which works fine in XAMPP. There are virtually no ToolBook actions except to load an XML file for each page. But in order to successfully migrate this, I realize that the database must migrate FIRST and successfully. When a connection fails and data is not returned as expected to the calling application, then a lot of cascade failures can occur. It is a good idea to build into the load process, some application flexibility so if something doesn't connect or work as expected the application will generate feedback to you. In my case, when the application loads, it has to verify account details for the user BEFORE it reaches the actual login page.

So basically, take a close look at each step in the load process. A web server will always be a little slower at providing resources than XAMPP because XAMPP is running from your local system. If some of your resources are loading asynchronously (rather than strictly inline), than you must allow for this. When you say variables are undefined and XML files are not loading correctly or at all, it sounds like dependencies that some of these resources depend on are not available at the time expected in the load process. In today's web apps, loading most things asynchronously is the recommended approach, but you must be careful not to expect something to exist and be available when in fact it may or may not be.

Generally, ToolBook and Javascript load inline (or synchronous). XML on the other hand allows for huge flexibility by loading its resources asynchronously. This means that several connections are made to the web server all at once. While this speeds things up, it also means that small files will finish loading before larger ones. So you must be careful as functions written in your XML files may be expecting things from other XML files that haven't yet become available in the DOM.

To solve loading issues with asynchonous files I often use the <config2> ... </config2> section of the XML file to check dependencies before allowing any function to actually execute. Lets say for example you are connecting to a database and once a value is returned it will be stored in a global variable [db] and hold the string "connected". Then, just in case this variable has not been populated you should check for it in your XML <config2> section like this:
    <config2 delay="500">
    <exeJavascriptDirect>
    <![CDATA[
    /* CLIFTON: Check if database has connected.
    ***/
    var fct = function() {
    if (typeof db != "undefined" && db == "connected") {
    [ do some stuff because our variable indicates db has connected ]
    } else setTimeout(fct, 200); //Wait 200ms and check again
    };
    fct(); //Begin looping our function and checking for resources
    ]]>
    </exeJavascriptDirect>
    </config2>
Another approach is to use the notifyObject parameter of PowerPac's XMLHttpRequest() function to expressly send a user event a specific object which you know will always exist during the loading process. When the user event has been received, you can check for other dependencies or run other related functions that you know will work once the XML file has loaded and sent the user event to the specified object. This is the method that I usually use as it is the most reliable. I would not recommend using your own XMLHttpRequest() as the one we've included with the PowerPac allows for a lot more flexibility and provides nice object notification (via user events).

If all of your files must be loaded synchronously or inline, the set the notifyObject parameter in PowerPac's XMLHttpRequest() to false. I don't recommend this, but it will likely make things more predictable and your application will make single requests for resources and wait until they are received before moving on.

This is just a few things to consider that may help to track down the issue(s) you are having. Please remember, just one or two issues can result in the multitude of warnings and errors you are getting from your app. But they all stem from just one or two problems. A couple of alerts well positioned in the load process will likely help you identify those one or two issues.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby John Robin Dove » Fri May 10, 2019 10:14 am

Thanks for your detailed reply. I am trying to apply your recommendations but so far have not made much progress. I must try to break up the loading into sections and create pauses to make sure that all variables etc. are available before continuing. To a certain extent this is what I have tried to do already but the loading process is labyrinthine and, as there is no central code page, most of the time I feel as if I'm programming blindfolded.

If I had to start again I think I would try to use only XML files like you and eliminate the TB action system altogether because it is so time-consuming to debug.

I have had some success with one of the files that refused to load but my solution seems dangerously unscientific. I just added a 500 ms media timed delay action at the top of the load page section and this seems to do the trick which is surprising because all the XML loading takes place after this!

Some specific errors that I get:
(these are in French so the exact wording may not be correct)

cannot load page p0 the page does not exist

is not a number etc.

Both seem to indicate that certain variables have not been defined and are probably 0 and null but where are they? It's like looking for needles in haystacks.

Alerts often, but not always, correct all the errors presumably because they allow the system to catch up with itself.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Fri May 10, 2019 12:21 pm

"Cannot load page p0, the page does not exist."
This is a pretty bad error and indicates something has failed to load very early in the load process.
I would look for some sort of custom function, especially is you have hand modified pages after export.
Essentially this error is telling you that ToolBook cannot even load its basic sub-system.

Hope that helps a little.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby John Robin Dove » Sat May 25, 2019 8:55 am

Hi Clifton,

I still haven't managed to solve this problem. It would seem to be caused by 7 successive calls to pgGotoURL. 4 to load small html files and 3 to load other TB htmls into fields on the main page. The message 'page p0 does not exist' is sent by one of the TB html files which never gets loaded although it is not the biggest. Since the last powerpac update I have new problems. The video starts playing after the page loads and I don't want it to. Using my buttons I can stop it and reset it to the beginning. If I then click on my play button I get this message

Image

and if I press on my pause button, I see this

Image

John

PS I have just seen a similar message about volumeChanged not being a number.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Sat May 25, 2019 6:25 pm

The error messages are likely related to a user event that is checking for a number. Not all events sent by the htmlVideo player send numeric values.
Here is a suggested user event code to successfully treat numeric and string values:
    On user event [value]
    if isNumber( item 2 of value )
    Comment: Here is where we check for numeric values
    if item 2 of value = 5000
    Comment: Actions when video reaches a 5 second time marker
    else if item 2 of value = 25000
    Comment: Actions when video reaches a 25 second time marker
    else if value contains "ended"
    Comment: Actions when video has ended
    end
    else if item 2 of value contains "playStart"
    Comment: Here is where we handle actions when user clicks the play control
    else if item 2 of value contains "isPaused"
    Comment: Here is where we handle actions when user clicks to pause the video
    else if item 2 of vlaue contains "Fullscreen"
    Comment: Here is where we handle actions when user enters/leaves fullscreen
    else if item 2 of value contains "volumeChange"
    Comment: Here is where we handle actions when user changes the volume or mutes it
    else if item 2 of value contains "Controls"
    Commnet: Here is where we handle actions when controls are auto shown/hidden
    end

The latest version of the PowerPac added additional user interaction events. (See the Parameter Help API.)
Hope this helps with the video player problems you have described. 

Regarding the loading issue:
Why not load 1st html file and when it has finished, call the pgGotoURL() to load the 2nd, then the 3rd, then the 4th. This way your server won't get jammed with file requests to the point where it just gives up loading you files. Easiest way to schedule loading additional files is to use a small XML file to just handle the sequential loading of your files. Once you get them to load in the proper order, all should be fine. You also may want to consider using the free CloudFlare content delivery service to speed the loading process.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby Clifton » Sat May 25, 2019 8:34 pm

UPDATE:
I discovered a bug in htmlVideoLoader() which affects ToolBook v9.0 where all videos are forced to auto play.
Please download PowerPac v15.016.4 or greater.

Sorry!
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby John Robin Dove » Mon May 27, 2019 9:37 am

Thanks for your replies, Clifton. I'm a little confused and require further guidance if possible please.

1) Are you saying that the error messages are triggered by the continuous user events sent to the TB field used to contain the video player. My actions code for this object is already quite long.

Image

I need to add your suggested code to/around this?

2} I haven't discovered how to download version 15.016.4

3) I haven't a clue what CloudFlare content delivery service is and where to find it.

4) How can I detect when an html has been loaded by pgGotoURL? Perhaps by using a function triggered by body.onload? Something like top.tbfunction_pgTBObjSet([name], user, [Number 1 to 7]) The number sent in value would determine which html or dhtml to load... ?
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: moving from localhost to www

Postby Clifton » Mon May 27, 2019 2:00 pm

Since you are only handling numeric values then just at a break point at the top of the code:
if not isNumber(item 2 of value)
break out of action sequence
end if
Comment: Your original code follows ...


To upgrade your PowerPac, just select "Check for updates" from the PowerPac menu.

CloudFlare CDN:
https://www.cloudflare.com
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: moving from localhost to www

Postby Clifton » Mon May 27, 2019 2:54 pm

The on load page event in the ToolBook actions system is basically the same as document.onLoad() in JavaScript.
So there are two ways to detect that a file has loaded:
  1. Use the on load page event of the first page of each ToolBook export.
    Begin by loading the 1st export, with the following action for on load page for the first page of the export:
    on load page
    pgGotoURL( [ load url for 2nd ToolBook export ] );
    end load page

    Once the 2nd export has loaded, the following action for on load page for the first page of the export will process:
    on load page
    pgGotoURL( [ load url for 3rd ToolBook export ] );
    end load page

    Once the 3rd export has loaded, the following action for on load page for the first page of the export will process:
    on load page
    pgGotoURL( [ load url for 4th ToolBook export ] );
    end load page

    The above method will process as quickly as the server transfers the data and all dependencies which are connected
    by a previous export will be bound together in a predictable manner.
     
  2. Load an XML file with the first page of each book, which calls pgGotoURL() to load the url for the next book.
    (XML is always my preference as you can do so much more. For example, you can add
    additional delays to increase the separation between the load page events using the <config2> section
    of the XML documents. XML allows you quickly experiment with the best settings to use rather than to
    have to keep making exports of you project. Instead, just modify the XML file and there is no need to
    re-export as often.)
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron