summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-02-08 07:30:16 -0500
committerChristopher Speller <crspeller@gmail.com>2016-02-08 07:30:16 -0500
commitdaa363574a3cb01fecdf8cdbfabd0a9739bf13c9 (patch)
tree5edfa02a939bc95438a18f6f5184341e620124cd /web
parent91c78682f5db0a6323753422f20c0a55a60ad35b (diff)
parentf0a84897b451a0e27eac6d16ef24b642254a0f2c (diff)
downloadchat-daa363574a3cb01fecdf8cdbfabd0a9739bf13c9.tar.gz
chat-daa363574a3cb01fecdf8cdbfabd0a9739bf13c9.tar.bz2
chat-daa363574a3cb01fecdf8cdbfabd0a9739bf13c9.zip
Merge pull request #2094 from mattermost/GIT-1812
GIT-1812 fixing wesocket issue with firefox
Diffstat (limited to 'web')
-rw-r--r--web/react/stores/socket_store.jsx24
-rw-r--r--web/templates/head.html6
2 files changed, 22 insertions, 8 deletions
diff --git a/web/react/stores/socket_store.jsx b/web/react/stores/socket_store.jsx
index 9c3270f68..bc2bdbe64 100644
--- a/web/react/stores/socket_store.jsx
+++ b/web/react/stores/socket_store.jsx
@@ -28,10 +28,13 @@ class SocketStoreClass extends EventEmitter {
this.addChangeListener = this.addChangeListener.bind(this);
this.removeChangeListener = this.removeChangeListener.bind(this);
this.sendMessage = this.sendMessage.bind(this);
+ this.close = this.close.bind(this);
+
this.failCount = 0;
this.initialize();
}
+
initialize() {
if (!UserStore.getCurrentId()) {
return;
@@ -106,15 +109,19 @@ class SocketStoreClass extends EventEmitter {
};
}
}
+
emitChange(msg) {
this.emit(CHANGE_EVENT, msg);
}
+
addChangeListener(callback) {
this.on(CHANGE_EVENT, callback);
}
+
removeChangeListener(callback) {
this.removeListener(CHANGE_EVENT, callback);
}
+
handleMessage(msg) {
switch (msg.action) {
case SocketEvents.POSTED:
@@ -153,6 +160,7 @@ class SocketStoreClass extends EventEmitter {
default:
}
}
+
sendMessage(msg) {
if (conn && conn.readyState === WebSocket.OPEN) {
conn.send(JSON.stringify(msg));
@@ -161,9 +169,16 @@ class SocketStoreClass extends EventEmitter {
this.initialize();
}
}
+
setTranslations(messages) {
this.translations = messages;
}
+
+ close() {
+ if (conn && conn.readyState === WebSocket.OPEN) {
+ conn.close();
+ }
+ }
}
function handleNewPostEvent(msg, translations) {
@@ -305,12 +320,5 @@ function handlePreferenceChangedEvent(msg) {
var SocketStore = new SocketStoreClass();
-/*SocketStore.dispatchToken = AppDispatcher.register((payload) => {
- var action = payload.action;
-
- switch (action.type) {
- default:
- }
- });*/
-
export default SocketStore;
+window.SocketStore = SocketStore;
diff --git a/web/templates/head.html b/web/templates/head.html
index b1ec905b5..da65e1779 100644
--- a/web/templates/head.html
+++ b/web/templates/head.html
@@ -122,6 +122,12 @@
}
});
});
+
+ $(window).on('beforeunload', function(){
+ if (window.SocketStore) {
+ SocketStore.close();
+ }
+ });
</script>
<script>