AdapterJS
AdapterJS copied to clipboard
Implementing plugin callback without touching AdapterJS file
If I want to implement theAdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb
callback the source code says that it needs to be overridden but what I don't want to do is to end up using a custom AdapterJS version. Also it would be nice to be able to pass options. For example like this:
window.AdapterJS = {
options: {
hidePluginInstallPrompt: true
},
WebRTCPlugin: {
pluginNeededButNotInstalledCb: function() {
//Do something when the plugin is not installed
}
}
};
After importing AdapterJS you can just do
AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb = function() {
// your code
};
This way you don't need to touch the AdapterJS code.
Hope this helps :)
I forgot to mention that I'm lazy loading AdapterJS this might be causing that at the point where I want to define the callback either AdapterJS is still not defined or the callback was already set to null because of this line https://github.com/Temasys/AdapterJS/blob/master/source/adapter.js#L122
I see. Now it makes more sense to pass it as a config. I'll keep it open for @johache to consider.
Thanks!
Hi,
Good points I think, I saw you PR : https://github.com/Temasys/AdapterJS/pull/70/files Just looking at it it looks quite good, but I will need to run tests before validating it. Hopefully I can get to it by Monday (hopefully...)
Thanks
Sorry but I don't get it :-/
AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb = AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb || function () {...}
I can replace the AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb function with my own function, but it seems to me the original AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb is called immediately after the AdapterJS script loads so my replacement has no effect and I can't figure out to define it before AdapterJS loads, is that possible?.
Could you please provide me with a small working sample of how to intercept the callback method?
@johache @ulifigueroa
The callback function is indeed called immediately as AJS in loaded. You need to set AdapterJS.WebRTCPlugin.pluginNeededButNotInstalledCb BEFORE you include or require AJS.
@joache thanks got it now :-)
Just nut used to the dynamics of JavaScript, so if anybody else is as n00b as me here you have an example:
var AdapterJS = { WebRTCPlugin: { pluginNeededButNotInstalledCb: function () { alert("Plugin needed, I'm in control"); } } };
Hi, I am having problems related to this issue.. I try to set AdapterJS.options.hidePluginInstallPrompt = true;
before requiring AdapterJS, since I don't want to end up with a custom version, but even setting the value to global scope in window (I use strict mode), once the adapter.js is loaded, what is supposed to hold my value, is undefined.
I created a PR that solves this issue: it just picks config values from the global object in window: https://github.com/Temasys/AdapterJS/pull/253
I saw there is a PR to set the AdapterJS itself in window, wich seems related, but is not, this is just picking up config values from the global object. Does this make sense?