Temasys / AdapterJS

AdapterJS Javascript Polyfill and Tools for WebRTC - Skylink WebRTC
http://skylink.io/web
Other
428 stars 100 forks source link

AdapterJS global object is not properly detected when used with module bundlers like WebPack #299

Closed aszmyd closed 6 years ago

aszmyd commented 6 years ago

We cant properly setup global global AdapterJS options like forceSafariPlugin when including library using module bundler (i.e. WebPack).

Consider this code:

window.AdapterJS = {
    options: {
        forceSafariPlugin: true
    }
};
require('adapterjs');

The option is actually not being set because in library you dont explicity try to grab AdapterJS object from Window:

var AdapterJS = AdapterJS || {};

and bundlers like webpack resolves such runtime require with functions that adds scope to execution and this kind of syntax is not working.

Super simple solution for this is to use this kind of syntax:

var AdapterJS = AdapterJS || window.AdapterJS || {};

Without this change i actually dont know how to override those options in such case.

Pull Request created: #300