-
Notifications
You must be signed in to change notification settings - Fork 14
call js function with context #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
See #9 ReactSWF is not involved in this and there's nothing ReactSWF can do that isn't opinionated/intrusive and would require special code built into the SWF. Flash Player can only call functions exposed on window, so you're left with two choices:
I'm refactoring ReactSWF a bit and I may end up providing this functionality through a separate complementary module, but due to the design of FlashPlayer this is not something ReactSWF should provide. EDIT: You cannot pass functions through flashVars because it has to be serialized into a string and passed to FlashPlayer. |
Hmm... it could make sense to have ReactSWF detect functions passed in flash-vars and special-case them perhaps. I'll think about this. |
Oh right facebook/react#4000 prevents this from being a good idea at the moment. |
const SWF_ID_PREFIX = '__MyExternalInterfaceExample_SWFID_';
const SWF_CALL_NAME_PREFIX = '__MyExternalInterfaceExample_SWFCall_';
let nextUID = 0;
class MyExternalInterfaceExample extends React.Component {
constructor(props) {
super(props);
// For most purposes nextUID is sufficient. However, if you rely on
// non-trivial server rendering you must generate deterministic UIDs per
// React root to avoid markup mismatch.
this._uid = nextUID++;
window[SWF_CALL_NAME_PREFIX + this._uid] = this.handleSWFCall.bind(this);
}
componentWillUnmount() {
delete window[SWF_CALL_NAME_PREFIX + this._uid];
}
handleSWFCall() {
// Beware; SWF calls are executed in the context of SWF Player.
console.log('SWFCall', arguments);
return 'foobar';
}
invokeSWFMyCallback(arg) {
// Beware; SWF Player does not sufficiently escape serialized arguments.
return this._swfPlayerNode.myCallback(arg);
}
render() {
// Globally unique ID is required for ExternalInterface callbacks in IE<11.
return (
<ReactSWF
...
ref={c => this._swfPlayerNode = c}
id={SWF_ID_PREFIX + this._uid}
flashVars={{myCallbackName: SWF_CALL_NAME_PREFIX + this._uid}}
/>
);
}
} |
thanks a lot! |
Hello. Thanks for great component!
I have a problem with calling js callback function in context of my parent component:
method onJSBridge allways call in window context. But if I pass flashVars={{javascriptCallbackFunction: this.onJSBridge.bind(this)}} I see error:
Uncaught SyntaxError: Unexpected identifier
in consoleHow could I call method of object?
The text was updated successfully, but these errors were encountered: