From 523048f111250b92ab64b694941fdec487ef306e Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han <jacky_cute0808@hotmail.com>
Date: Fri, 25 Sep 2015 16:57:18 +0800
Subject: [PATCH] Fixed to handle startConnection and finishConnection
 undefined exceptions

---
 lib/realtime.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/realtime.js b/lib/realtime.js
index af33cad..86d361e 100644
--- a/lib/realtime.js
+++ b/lib/realtime.js
@@ -260,7 +260,7 @@ function finishConnection(socket, note, user) {
 
     //clear finished socket in queue
     for (var i = 0; i < connectionSocketQueue.length; i++) {
-        if (connectionSocketQueue[i].id == socket.id)
+        if (!connectionSocketQueue[i] || connectionSocketQueue[i].id == socket.id)
             connectionSocketQueue.splice(i, 1);
     }
     //seek for next socket
@@ -386,7 +386,7 @@ function disconnect(socket) {
 
     //clear finished socket in queue
     for (var i = 0; i < disconnectSocketQueue.length; i++) {
-        if (disconnectSocketQueue[i].id == socket.id)
+        if (!disconnectSocketQueue[i] || disconnectSocketQueue[i].id == socket.id)
             disconnectSocketQueue.splice(i, 1);
     }
     //seek for next socket