From 6ff9ee6b47c99cf53545f907763efe821b9394bd Mon Sep 17 00:00:00 2001
From: Joachim Bauch <bauch@struktur.de>
Date: Mon, 20 Jun 2016 10:13:17 +0200
Subject: [PATCH] Fix moving between conference rooms.

---
 static/js/mediastream/webrtc.js | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/static/js/mediastream/webrtc.js b/static/js/mediastream/webrtc.js
index 4cfe54b0..0d976d7f 100644
--- a/static/js/mediastream/webrtc.js
+++ b/static/js/mediastream/webrtc.js
@@ -95,6 +95,7 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
 		this.msgQueues = {};
 		this.usermediaReady = false;
 		this.pendingMediaCalls = [];
+		this.pendingMessages = [];
 
 		this.usermedia = null;
 		this.audioMute = false;
@@ -174,6 +175,16 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
 
 		if (this.isConferenceRoom()) {
 			// Switching from a conference room closes all current connections.
+			this.leavingConference = true;
+			this.e.one("stop", _.bind(function() {
+				_.defer(_.bind(function() {
+					this.leavingConference = false;
+					while (this.pendingMessages.length) {
+						var args = this.pendingMessages.shift();
+						this.processReceivedMessage.apply(this, args);
+					}
+				}, this));
+			}, this));
 			_.defer(_.bind(function() {
 				this.doHangup();
 			}, this));
@@ -220,6 +231,13 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
 			return;
 		}
 
+		if (this.leavingConference) {
+			// Defer evaluating of messages until the previous conference room
+			// has been left.
+			this.pendingMessages.push([to, data, type, to2, from]);
+			return;
+		}
+
 		this.processReceivedMessage(to, data, type, to2, from);
 	};