Skip to content

Commit

Permalink
Use Maps for Janus.sessions in janus.js
Browse files Browse the repository at this point in the history
  • Loading branch information
i8-pi committed May 7, 2023
1 parent 0e043d2 commit 3d8f1fd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions html/janus.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

// List of sessions
Janus.sessions = {};
Janus.sessions = new Map();

Janus.isExtensionEnabled = function() {
if(navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia) {
Expand Down Expand Up @@ -478,10 +478,10 @@ Janus.init = function(options) {
let oldOBF = window["on" + eventName];
window.addEventListener(eventName, function() {
Janus.log("Closing window");
for(let s in Janus.sessions) {
if(Janus.sessions[s] && Janus.sessions[s].destroyOnUnload) {
Janus.log("Destroying session " + s);
Janus.sessions[s].destroy({unload: true, notifyDestroyed: false});
for(const [sessionId, session] of Janus.sessions) {
if(session && session.destroyOnUnload) {
Janus.log("Destroying session " + sessionId);
session.destroy({unload: true, notifyDestroyed: false});
}
}
if(oldOBF && typeof oldOBF == "function") {
Expand Down Expand Up @@ -1014,7 +1014,7 @@ function Janus(gatewayCallbacks) {
} else {
Janus.log("Created session: " + sessionId);
}
Janus.sessions[sessionId] = that;
Janus.sessions.set(sessionId, that);
callbacks.success();
});
ws.send(JSON.stringify(request));
Expand Down Expand Up @@ -1058,7 +1058,7 @@ function Janus(gatewayCallbacks) {
} else {
Janus.log("Created session: " + sessionId);
}
Janus.sessions[sessionId] = that;
Janus.sessions.set(sessionId, that);
eventHandler();
callbacks.success();
},
Expand Down

0 comments on commit 3d8f1fd

Please sign in to comment.