You are not logged in.

Zephyr

Professional

  • "Zephyr" started this thread

Posts: 1,003

Location: Netherlands

Occupation: Web developer

  • Send private message

1

Saturday, February 15th 2020, 2:45pm

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:

Source code

1
2
3
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:

Source code

1
2
3
4
5
6
    <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

Source code

1
2
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.

Zephyr

Professional

  • "Zephyr" started this thread

Posts: 1,003

Location: Netherlands

Occupation: Web developer

  • Send private message

2

Sunday, February 16th 2020, 2:53pm

It seems you can get the Plugin Interface by calling krpano.get('global') with the javascript interface.

3

Tuesday, February 18th 2020, 9:53pm

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:

Source code

1
2
3
4
5
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

Zephyr

Professional

  • "Zephyr" started this thread

Posts: 1,003

Location: Netherlands

Occupation: Web developer

  • Send private message

4

Wednesday, February 19th 2020, 5:30pm

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