Troubles with panda/javascript interation

Hi buddies

I’m work on test web application and i can’t setup Panda3d and Javascript integration properlly. Either i can’t see my mistake :confused:

In my python side:

text=OnscreenText(mayChange=1, …)

def setText(message):
text.setText(message)

if base.appRunner:
base.appRunner.main.setText=setText
base.appRunner.main.setText(“Default”) # this works

In Javascript side:

In onPythonLoad i already try others callbacks with the same result e.r. nothing :wink:

In function loadPluginClient…

This code prints “Got Main” but when my app run, in the onscreentext i got only “default” writed. In error console (Firefox) i got a message : plugin.main.setText is not a function :open_mouth:

What’s wrong? :confused:
Thanx

No ideas fellows? :cry:

First, onPythonLoad is the wrong event to listen for: at the time of this event, Python itself has loaded, but your application hasn’t necessarily started to run yet. There’s no built-in event that you can listen for to know when your application has assigned main.setText, because there’s no way for the plugin to know that this action has occurred.

If you want something to occur at startup time, it’s best to have your Python code initiate that. If you really want JavaScript to initiate it, you have to generate your own event, for instance by calling base.appRunner.notifyRequest(‘onSetTextReady’) after you have assigned main.setText, and then write your web page to listen for onSetTextReady.

The second problem is a feature that isn’t yet mentioned in the manual: as a security precaution, JavaScript by default isn’t allowed to call Python methods. You have to enable this feature when you generate the p3d file, with something like “-c script_origin=myhost.com” where myhost.com is the page that will be hosting the p3d file. If you really don’t care about security, you can use “-c script_origin=*”, which allows any web page at all to call any Python methods you accidentally leave exposed, which can be dangerous.

David

Thanx 4 master David

One more: i suppose -c script_origin supports multiples hosts with comma separated (This is right?)

Off course client security at first place :wink:

Thanx again

Right, actually, semicolon-delimited.

I plan to add this documentation to the manual soon. I just haven’t had a chance yet, my apologies.

David

Work’s very fine :smiley: