I write a webpack.config.js and run webpack –mode production to get ./dist/mediasoup-client.js
when I run the following code, it appears that TypeError: cannot read properties of undefined (reading ‘Device’). What happened? Anyone could help me with this? Thanks in advance.
let device = null; try { device = new MediasoupClient.Device(); } catch (err) { if (err.name === “UnsupportedError”) { console.error(“mediasoup-client doesn’t support this browser”); return; } } global.mediasoup.device = device;
webpack.config.js
‘
const path = require(‘path’);
module.exports = {
entry: ‘./lib/index.js’,
output: {
filename: ‘mediasoup-client.js’,
path: path.resolve(__dirname, ‘dist’),
},
};
‘
I use npm run typescript:build to get lib/index.js
There is a better way of doing it, instead of converting mediasoup-client to vanila js, just include the mediasoup-client library from node_modules into your js file lets say call.js and then do your stuff as mentioned in the docs in that file and use webpack to bundle that call.js file.
fixed.
write a index.js as follows, then use webpack to produce the mediasoup-client.js for web using.
const client = require(‘mediasoup-client’)
window.mediasoupClient = client