From: Darren <darren@darrenwhitlen.com>
Date: Fri, 19 Sep 2014 13:34:22 +0000 (+0100)
Subject: Cleaning up existing WebsocketRpc instances on reconnect
X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6a12279524ea3ba21811917ea2bd97e0c5a417b5;p=KiwiIRC.git

Cleaning up existing WebsocketRpc instances on reconnect
---

diff --git a/client/src/models/gateway.js b/client/src/models/gateway.js
index a8d8f1a..7fe7cf3 100644
--- a/client/src/models/gateway.js
+++ b/client/src/models/gateway.js
@@ -40,6 +40,10 @@ _kiwi.model.Gateway = Backbone.Model.extend({
             reconnect_delay: 2000
         });
 
+        // If we have an existing RPC object, clean it up before replacing it
+        if (this.rpc) {
+            rpc.dispose();
+        }
         this.rpc = new EngineioTools.Rpc(this.socket);
 
         this.socket.on('connect_failed', function (reason) {