From 389cbaf611f47ce375e7e9ea446cd67175c082ad Mon Sep 17 00:00:00 2001 From: Umesh Kadam <43408418+TheUmeshKadam@users.noreply.github.com> Date: Tue, 23 Dec 2025 18:43:40 +0530 Subject: [PATCH] feat: support multiple WebSocket sub-protocols in MQTT connection Allow custom WebSocket sub-protocols to be specified via opts.wsOptions.protocol (comma-separated). Custom protocols are now included alongside the default MQTT protocol during WebSocket connection negotiation. - Changed from single protocol to array of protocols - Parse custom protocols from opts.wsOptions.protocol if provided - Maintain backward compatibility by always including MQTT protocol --- mqtt.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mqtt.js b/mqtt.js index f8c9fe7..e53e068 100644 --- a/mqtt.js +++ b/mqtt.js @@ -4726,14 +4726,19 @@ function createWebSocket (client, url, opts) { } function createBrowserWebSocket (client, opts) { - const websocketSubProtocol = - (opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3) + let websocketSubProtocols = []; + + if (opts != undefined && opts.wsOptions !== undefined && opts.wsOptions.protocol !== undefined) { + websocketSubProtocols = opts.wsOptions.protocol.split(','); + } + + websocketSubProtocols.push((opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3) ? 'mqttv3.1' - : 'mqtt' + : 'mqtt'); const url = buildUrl(opts, client) /* global WebSocket */ - const socket = new WebSocket(url, [websocketSubProtocol]) + const socket = new WebSocket(url, websocketSubProtocols) socket.binaryType = 'arraybuffer' return socket } @@ -18671,4 +18676,4 @@ module.exports = { }; },{}]},{},[17])(17) -}); +}); \ No newline at end of file