Added Guest name support to multiplexor, fix for #2812

Ylian Saint-Hilaire committed Jul 2, 2021 at 14:09 UTC 69aa0c0d1c35bc853e85f7196d0528a8d12331ef
1 file changed +9 -1
meshdesktopmultiplex.js
+9 -1
@@ -318,7 +318,14 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
318 obj.sendSessionMetadata = function () {
319 var allUsers = {};
320 if (obj.viewers != null) {
321 - for (var i in obj.viewers) { var v = obj.viewers[i]; if ((v.user != null) && (v.user._id != null)) { if (allUsers[v.user._id] == null) { allUsers[v.user._id] = 1; } else { allUsers[v.user._id]++; } } }
321 + for (var i in obj.viewers) {
322 + var v = obj.viewers[i];
323 + if ((v.user != null) && (v.user._id != null)) {
324 + var id = v.user._id;
325 + if (v.guestName) { id += '/guest:' + Buffer.from(v.guestName).toString('base64'); } // If this is a guest connect, add the Base64 guest name.
326 + if (allUsers[id] == null) { allUsers[id] = 1; } else { allUsers[id]++; }
327 + }
328 + }
329 obj.sendToAllViewers(JSON.stringify({ type: 'metadata', 'ctrlChannel': '102938', users: allUsers, startTime: obj.startTime }));
330 }
331
@@ -907,6 +914,7 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
914 // If the identifier is removed, drop the connection
915 if ((cookie != null) && (typeof cookie.pid == 'string')) {
916 obj.pid = cookie.pid;
917 + obj.guestName = cookie.gn;
918 parent.parent.AddEventDispatch([obj.nodeid], obj);
919 obj.HandleEvent = function (source, event, ids, id) { if ((event.action == 'removedDeviceShare') && (obj.pid == event.publicid)) { obj.close(); } }
920 }