Send an event from krpano

  • Hello everyone,

    Thank you very much in advance for helping.

    One if my clients have asked if it would be possible to send an event from krpano so they can listen to it and this way know when a new scene has been loaded. This event also should send the scene name or any kind of information to identify this new scene.

    So I've spent a good hour on this but I'm definitely stuck.
    The virtual tour uses the latest Beta version krpano 1.19-pr3 (build 2015-08-04)
    So I thought It would be good use javascript directly like this:

    Code
    <action name="new_event" type="Javascript" devices="html5"><![CDATA[
        ]]></action>


    My client said that if I can create an event like using:

    Code
    var event = new Event("zoneChanged");event.zone = 2;document.dispatchEvent(event);


    Then they can listen to it:

    Code
    document.addEventListener("zoneChanged", function (event) {
       console.log(event.zone);
    });


    I have no experience with Krpano and the JS interface. I know that the information about the scene can be supplied by using

    Code
    get(xml.scene)

    But I haven't managed to get the right commands/syntax to export an event.

    Thanks


  • This is probably pretty close.
    Remove the listener if it's already in javascript outside krpano of course and correct for any typos..
    the documentation for jscall should be enough to figure that out.

  • Hello Sacha,

    Thank you very much for taking your time helping me.

    I added your code to my virtual tour and uploaded HERE
    It gives me an error. Please click on any hotspot and then press letter 'o' to open the console.
    I included in screenshot below:


    Here is the relevant part of the code (sorry for the weird format. I never get it right when I post it in the forum):

    Code
    <action name="activatepano">  loadscene(%1,null,MERGE,BLEND(1));  txtadd(new_scene_setup,'start_' , get(xml.scene));  new_scene_setup();  layer[ga].trackpageview(get(layer[panolist].pano[get(xml.scene)].title));  send_event();  </action>
        <action name="send_event">  jscall('var event = new Event("zoneChanged");event.zone = '+xml.scene+';');  </action>

    I didn't add the add_listener because my client is going to do that in their application.

    Many thanks,

    Rafael

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!