mqttjs / MQTT.js

The MQTT client for Node.js and the browser
Other
8.53k stars 1.41k forks source link

Remove is-browser.ts detection util in favor of config option #1900

Open olso-nordsec opened 2 months ago

olso-nordsec commented 2 months ago

Is your feature request related to a problem? Please describe.

Describe the solution you'd like Configurable by required option

mqtt.connect(credentials.endpoint, {
  environment: 'browser', // 'react-native' 'electron' 'node'
})

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

robertsLando commented 2 months ago

@olso-nordsec problem is that actually we also need that in order to know which modules to load and which not (as some wouldn't work on browser). For the other points in code I think your solution could work but we firstly should define how to fix this. Maybe there could be a way by using esbuild

If you have something in mind feel free to open a PR

Ref:

https://github.com/mqttjs/MQTT.js/blob/cd0b044b89e8413e99e055529d523eac6d4ddcd4/src/lib/connect/index.ts#L21-L33