azq2 zhumarin svn spaces ru spaces branches zhumarin SPAC-4758 svn dif

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
azq2@zhumarin:~/svn/f.spaces.ru/spaces/branches/zhumarin/SPAC-4758$ svn diff -x -b -r 113793:113835 templates/JS/pushstream.js | colordiff
Index: templates/JS/pushstream.js
===================================================================
--- templates/JS/pushstream.js (revision 113793)
+++ templates/JS/pushstream.js (revision 113835)
@@ -467,6 +467,12 @@
/* wrappers */
var WebSocketWrapper = function(pushstream) {
+ var ver;
+ if (/Safari/i.test(navigator.userAgent) && (ver = navigator.userAgent.match(/Version\/([\d]+)/i))) {
+ ver = +ver[1];
+ if (ver < 6)
+ throw "WebSocket not supported";
+ }
if (!window.WebSocket && !window.MozWebSocket) { throw "WebSocket not supported"; }
this.type = WebSocketWrapper.TYPE;
this.pushstream = pushstream;
@@ -933,9 +939,19 @@
if (isNaN(this.port)) { throw "PushStream port not specified"; }
if (!this.channelsCount) { throw "No channels specified"; }
if (this.wrappers.length === 0) { throw "No available support for this browser"; }
-
+
this._keepConnected = true;
this._lastUsedMode = 0;
+ var lpm;
+ if ((lpm = document.cookie.match(/lpm=([^\s;]+)/))) {
+ var mode = decodeURIComponent(lpm[1]);
+ for (var i in this.wrappers) {
+ if (this.wrappers[i].type == mode) {
+ this._lastUsedMode = i;
+ break;
+ }
+ }
+ }
this._connect();
Log4js.debug("leaving connect");
@@ -1001,7 +1017,14 @@
this._setState(PushStream.OPEN);
if (this._lastUsedMode > 0) {
this._lastUsedMode--; //use same mode on next connection
+ // Сохраним последний режим
+ if (document.cookie.indexOf('hws=1') == -1 && this.wrapper.type != WebSocketWrapper.TYPE)
+ document.cookie = "lpm=" + encodeURIComponent (this.wrapper.type) + "; path=/; domain=.spaces.ru; expires=" + (new Date(2038, 1, 1).toUTCString());
}
+ if (this.wrapper.type == WebSocketWrapper.TYPE) {
+ // Сохраняем флаг о том, что WS тут точно работал однажды!
+ document.cookie = "hws=1; path=/; domain=.spaces.ru; expires=" + (new Date(2038, 1, 1).toUTCString());
+ }
},
_onclose: function() {
@@ -1069,4 +1092,4 @@
if (window.attachEvent) { window.attachEvent("onunload", PushStream.unload); }
if (window.addEventListener) { window.addEventListener.call(window, "unload", PushStream.unload, false); }
-})(window, document);
\ No newline at end of file
+})(window, document);