Difference between Javascript Interface and Plugin Interface

  • Hi all/Klaus,

    When embedding krpano and using the onready callback, I get the krpano Javascript Interface returned. https://krpano.com/docu/js/#interfaceobject
    It contains 5 methods (get, set, call, spheretoscreen and screentosphere)

    If I want to add a hotspot, I need to do something like this:

    Code
    krpano.call('addhotspot(test)');
    krpano.set('hotspot[test].ath', 0);
    // or krpano.get('hotspot[test]').atv = 0

    When I approach it via the plugin interface way:

    Code
    <action name="test" type="Javascript" autorun="onstart">
            <![CDATA[
            window.krpano = krpano
             // or onReay(krpano)
            ]]>
        </action>

    I get a lot more tooling to my dispossal. Adding a hotspot would be

    Code
    var hs = window.krpano.addhotspot(name)
    hs.ath = 0

    I was wondering what is the difference?

    My usecase: I want to create a tour manager, which loads in hotspots from a json api, and places them in krpano and can control other things of krpano also. Krpano needs to be as simple as possible and just focus on presenting the panoramas and leave the behaviours to the javascript layer. It also allows me to write React and use Es6 and let it bundle by webpack.

    Thats why I thought going the javascript interface way is the best way forward. But then I saw that for example addhotspot is not available via the onready, but it is via an action.

    What would be your opinion.

  • Hi,

    the reason for the different interfaces are the unified HTML5+Flash support.
    The JS interface can be used to control the HTML5 and the Flash viewer by using the same API.
    The 'plugin interface' is basically a reference to the internal global data structure and is only compatible either to HTML5 or to Flash, but not both.

    The Flash-support aspect is today almost not relevant anymore, but additionally there is also the 'protection'-aspect - the JS-API can be disabled or restricted to allow only secure action calls.

    If that doesn't matter you can get the most direct API to krpano by getting the global object and working with it.
    Here an example:

    Code
    embedpano({xml:null, target:"pano", html5:"webgl+only",onready:function(krpanoJSinterface)
    {
      var krpano = krpanoJSinterface.get("global");
      krpano.actions.loadxml("...");
    }});

    Many krpano actions can be also used directly from JS this way.

    Best regards,
    Klaus

  • Thanks Klaus! Learned something new :)

    Flash support is not important for me. The secure flag, could be handy for development purposes to create a clearer indication in how actions should be used, but Im not that worried that people will call unintended actions via the Interface. I will use the 'global' approach

Jetzt mitmachen!

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