Fix "module.exports" no longer available in WebRTC adapter 7.2.5

Since 7.2.5 the "main" property in the "package.json" of WebRTC adapter
points to an ES6 file which does not provide "module.exports" but
"exports.default". Due to this uses of "var adapter =
require('webrtc-adapter');" now fail, as the properties of the module
are loaded in "adapter.default" instead of in "adapter". To restore the
previous and expected behaviour a Babel plugin is now used to also add
"module.exports" if "exports.default" exists.

As WebRTC adapter still provides an ES5 file an alternative solution
would have been to alias "webrtc-adapter" to that file with
'--transform [ aliasify --global --aliases [ --webrtc-adapter
"webrtc-adapter/dist/adapter_core5.js" ] ]'.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2019-07-11 15:06:17 +02:00
parent c0c7a1c9d9
commit ab7f97c011
4 changed files with 1865 additions and 1 deletions

View file

@ -66,7 +66,10 @@ bundle-simplewebrtc:
# webrtc-adapter uses JavaScript features not supported by browserify,
# so the sources need to be transformed using babel to a compatible
# version of JavaScript.
npx browserify --standalone SimpleWebRTC --transform [ babelify --global --presets [ @babel/env ] ] js/simplewebrtc/simplewebrtc.js > js/simplewebrtc/bundled.js
# Its main module does no longer provide "module.exports", which is
# expected by the code using it, so it needs to be added back with a
# plugin.
npx browserify --standalone SimpleWebRTC --transform [ babelify --global --presets [ @babel/env ] --plugins [ add-module-exports ] ] js/simplewebrtc/simplewebrtc.js > js/simplewebrtc/bundled.js
create-tag:
git tag -a v$(version) -m "Tagging the $(version) release."

View file

@ -5233,6 +5233,7 @@ var adapter = (0, _adapter_factory.adapterFactory)({
window: window
});
exports.default = adapter;
module.exports = exports.default;
},{"./adapter_factory.js":16}],16:[function(require,module,exports){
'use strict';

1859
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -13,6 +13,7 @@
"@babel/core": "^7.5.0",
"@babel/preset-env": "^7.5.0",
"attachmediastream": "^2.1.0",
"babel-plugin-add-module-exports": "^1.0.2",
"babelify": "^10.0.0",
"browserify": "^16.3.0",
"browserslist-config-nextcloud": "0.0.1",