moto web application
修订版 | 6523cee495a07608313c94b3584a0d6446dd0a3b (tree) |
---|---|
时间 | 2014-01-31 18:17:30 |
作者 | astoria-d <astoria-d@mail...> |
Commiter | astoria-d |
more integration
@@ -13,14 +13,14 @@ | ||
13 | 13 | * License for the specific language governing permissions and limitations under |
14 | 14 | * the License. |
15 | 15 | */ |
16 | -package org.atmosphere.samples.chat; | |
16 | +package motoSample.atmos; | |
17 | 17 | |
18 | 18 | import org.atmosphere.config.service.Disconnect; |
19 | 19 | import org.atmosphere.config.service.ManagedService; |
20 | 20 | import org.atmosphere.config.service.Ready; |
21 | 21 | import org.atmosphere.cpr.AtmosphereResource; |
22 | 22 | import org.atmosphere.cpr.AtmosphereResourceEvent; |
23 | -import org.atmosphere.samples.chat.custom.Config; | |
23 | +//import org.atmosphere.samples.chat.custom.Config; | |
24 | 24 | import org.slf4j.Logger; |
25 | 25 | import org.slf4j.LoggerFactory; |
26 | 26 |
@@ -32,7 +32,7 @@ import static org.atmosphere.cpr.ApplicationConfig.MAX_INACTIVE; | ||
32 | 32 | * Simple annotated class that demonstrate the power of Atmosphere. This class supports all transports, support |
33 | 33 | * message length garantee, heart beat, message cache thanks to the {@link ManagedService}. |
34 | 34 | */ |
35 | -@Config | |
35 | +//@Config | |
36 | 36 | @ManagedService(path = "/chat", atmosphereConfig = MAX_INACTIVE + "=120000") |
37 | 37 | public class Chat { |
38 | 38 | private final Logger logger = LoggerFactory.getLogger(Chat.class); |
@@ -13,7 +13,7 @@ | ||
13 | 13 | * License for the specific language governing permissions and limitations under |
14 | 14 | * the License. |
15 | 15 | */ |
16 | -package org.atmosphere.samples.chat; | |
16 | +package motoSample.atmos; | |
17 | 17 | |
18 | 18 | import org.atmosphere.config.managed.Decoder; |
19 | 19 | import org.codehaus.jackson.map.ObjectMapper; |
@@ -13,7 +13,7 @@ | ||
13 | 13 | * License for the specific language governing permissions and limitations under |
14 | 14 | * the License. |
15 | 15 | */ |
16 | -package org.atmosphere.samples.chat; | |
16 | +package motoSample.atmos; | |
17 | 17 | |
18 | 18 | import org.atmosphere.config.managed.Encoder; |
19 | 19 | import org.codehaus.jackson.map.ObjectMapper; |
@@ -13,7 +13,7 @@ | ||
13 | 13 | * License for the specific language governing permissions and limitations under |
14 | 14 | * the License. |
15 | 15 | */ |
16 | -package org.atmosphere.samples.chat; | |
16 | +package motoSample.atmos; | |
17 | 17 | |
18 | 18 | import java.util.Date; |
19 | 19 |
@@ -1,18 +0,0 @@ | ||
1 | -package org.atmosphere.samples.chat.custom; | |
2 | - | |
3 | -import java.lang.annotation.Documented; | |
4 | -import java.lang.annotation.ElementType; | |
5 | -import java.lang.annotation.Retention; | |
6 | -import java.lang.annotation.RetentionPolicy; | |
7 | -import java.lang.annotation.Target; | |
8 | - | |
9 | -/** | |
10 | - * This annotation is here to demonstrate how simple it is to write custom annotation in Atmosphere. | |
11 | - * @author Jeanfrancois Arcand | |
12 | - */ | |
13 | - | |
14 | -@Target({ElementType.TYPE}) | |
15 | -@Retention(RetentionPolicy.RUNTIME) | |
16 | -@Documented | |
17 | -public @interface Config { | |
18 | -} |
@@ -1,38 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2014 Jeanfrancois Arcand | |
3 | - * | |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
5 | - * use this file except in compliance with the License. You may obtain a copy of | |
6 | - * the License at | |
7 | - * | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * | |
10 | - * Unless required by applicable law or agreed to in writing, software | |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
12 | - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
13 | - * License for the specific language governing permissions and limitations under | |
14 | - * the License. | |
15 | - */ | |
16 | -package org.atmosphere.samples.chat.custom; | |
17 | - | |
18 | -import org.atmosphere.annotation.Processor; | |
19 | -import org.atmosphere.config.AtmosphereAnnotation; | |
20 | -import org.atmosphere.cpr.AtmosphereFramework; | |
21 | -import org.slf4j.Logger; | |
22 | -import org.slf4j.LoggerFactory; | |
23 | - | |
24 | -/** | |
25 | - * A Simple {@link Processor} that demonstrate how you can extend you application with custom annotation. | |
26 | - * | |
27 | - * @author eanfrancois Arcand | |
28 | - */ | |
29 | -@AtmosphereAnnotation(Config.class) | |
30 | -public class SampleConfig implements Processor<Object> { | |
31 | - | |
32 | - private final Logger logger = LoggerFactory.getLogger(SampleConfig.class); | |
33 | - | |
34 | - @Override | |
35 | - public void handle(AtmosphereFramework framework, Class<Object> annotatedClass) { | |
36 | - logger.info("Custom annotation {} discovered. Starting the Chat Sample", annotatedClass.getAnnotation(Config.class)); | |
37 | - } | |
38 | -} |
@@ -1,124 +0,0 @@ | ||
1 | -$(function () { | |
2 | - "use strict"; | |
3 | - | |
4 | - var header = $('#header'); | |
5 | - var content = $('#content'); | |
6 | - var input = $('#input'); | |
7 | - var status = $('#status'); | |
8 | - var myName = false; | |
9 | - var author = null; | |
10 | - var logged = false; | |
11 | - var socket = atmosphere; | |
12 | - var subSocket; | |
13 | - var transport = 'websocket'; | |
14 | - | |
15 | - // We are now ready to cut the request | |
16 | - var request = { url: '/moto_web_app/chat', | |
17 | - contentType : "application/json", | |
18 | - logLevel : 'debug', | |
19 | - transport : transport , | |
20 | - trackMessageLength : true, | |
21 | - reconnectInterval : 5000, | |
22 | - enableXDR: true, | |
23 | - timeout : 60000 }; | |
24 | - | |
25 | - | |
26 | - request.onOpen = function(response) { | |
27 | - content.html($('<p>', { text: 'Atmosphere connected using ' + response.transport })); | |
28 | - input.removeAttr('disabled').focus(); | |
29 | - status.text('Choose name:'); | |
30 | - transport = response.transport; | |
31 | - | |
32 | - // Carry the UUID. This is required if you want to call subscribe(request) again. | |
33 | - request.uuid = response.request.uuid; | |
34 | - }; | |
35 | - | |
36 | - request.onClientTimeout = function(r) { | |
37 | - content.html($('<p>', { text: 'Client closed the connection after a timeout. Reconnecting in ' + request.reconnectInterval })); | |
38 | - subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: 'is inactive and closed the connection. Will reconnect in ' + request.reconnectInterval })); | |
39 | - input.attr('disabled', 'disabled'); | |
40 | - setTimeout(function (){ | |
41 | - subSocket = socket.subscribe(request); | |
42 | - }, request.reconnectInterval); | |
43 | - }; | |
44 | - | |
45 | - request.onReopen = function(response) { | |
46 | - input.removeAttr('disabled').focus(); | |
47 | - content.html($('<p>', { text: 'Atmosphere re-connected using ' + response.transport })); | |
48 | - }; | |
49 | - | |
50 | - // For demonstration of how you can customize the fallbackTransport using the onTransportFailure function | |
51 | - request.onTransportFailure = function(errorMsg, request) { | |
52 | - atmosphere.util.info(errorMsg); | |
53 | - request.fallbackTransport = "long-polling"; | |
54 | - header.html($('<h3>', { text: 'Atmosphere Chat. Default transport is WebSocket, fallback is ' + request.fallbackTransport })); | |
55 | - }; | |
56 | - | |
57 | - request.onMessage = function (response) { | |
58 | - | |
59 | - var message = response.responseBody; | |
60 | - try { | |
61 | - var json = atmosphere.util.parseJSON(message); | |
62 | - } catch (e) { | |
63 | - console.log('This doesn\'t look like a valid JSON: ', message); | |
64 | - return; | |
65 | - } | |
66 | - | |
67 | - input.removeAttr('disabled').focus(); | |
68 | - if (!logged && myName) { | |
69 | - logged = true; | |
70 | - status.text(myName + ': ').css('color', 'blue'); | |
71 | - } else { | |
72 | - var me = json.author == author; | |
73 | - var date = typeof(json.time) == 'string' ? parseInt(json.time) : json.time; | |
74 | - addMessage(json.author, json.message, me ? 'blue' : 'black', new Date(date)); | |
75 | - } | |
76 | - }; | |
77 | - | |
78 | - request.onClose = function(response) { | |
79 | - content.html($('<p>', { text: 'Server closed the connection after a timeout' })); | |
80 | - if (subSocket) { | |
81 | - subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: 'disconnecting' })); | |
82 | - } | |
83 | - input.attr('disabled', 'disabled'); | |
84 | - }; | |
85 | - | |
86 | - request.onError = function(response) { | |
87 | - content.html($('<p>', { text: 'Sorry, but there\'s some problem with your ' | |
88 | - + 'socket or the server is down' })); | |
89 | - logged = false; | |
90 | - }; | |
91 | - | |
92 | - request.onReconnect = function(request, response) { | |
93 | - content.html($('<p>', { text: 'Connection lost, trying to reconnect. Trying to reconnect ' + request.reconnectInterval})); | |
94 | - input.attr('disabled', 'disabled'); | |
95 | - }; | |
96 | - | |
97 | - subSocket = socket.subscribe(request); | |
98 | - | |
99 | - input.keydown(function(e) { | |
100 | - if (e.keyCode === 13) { | |
101 | - var msg = $(this).val(); | |
102 | - | |
103 | - // First message is always the author's name | |
104 | - if (author == null) { | |
105 | - author = msg; | |
106 | - } | |
107 | - | |
108 | - subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: msg })); | |
109 | - $(this).val(''); | |
110 | - | |
111 | - input.attr('disabled', 'disabled'); | |
112 | - if (myName === false) { | |
113 | - myName = msg; | |
114 | - } | |
115 | - } | |
116 | - }); | |
117 | - | |
118 | - function addMessage(author, message, color, datetime) { | |
119 | - content.append('<p><span style="color:' + color + '">' + author + '</span> @ ' + | |
120 | - + (datetime.getHours() < 10 ? '0' + datetime.getHours() : datetime.getHours()) + ':' | |
121 | - + (datetime.getMinutes() < 10 ? '0' + datetime.getMinutes() : datetime.getMinutes()) | |
122 | - + ': ' + message + '</p>'); | |
123 | - } | |
124 | -}); |
@@ -1,1017 +0,0 @@ | ||
1 | -(function(a,b){if(typeof define==="function"&&define.amd){define(b) | |
2 | -}else{a.atmosphere=b() | |
3 | -}}(this,function(){var c="2.1.4-javascript",a={},d,g=[],f=[],e=0,b=Object.prototype.hasOwnProperty; | |
4 | -a={onError:function(h){},onClose:function(h){},onOpen:function(h){},onReopen:function(h){},onMessage:function(h){},onReconnect:function(i,h){},onMessagePublished:function(h){},onTransportFailure:function(i,h){},onLocalMessage:function(h){},onFailureToReconnect:function(i,h){},onClientTimeout:function(h){},AtmosphereRequest:function(M){var O={timeout:300000,method:"GET",headers:{},contentType:"",callback:null,url:"",data:"",suspend:true,maxRequest:-1,reconnect:true,maxStreamingLength:10000000,lastIndex:0,logLevel:"info",requestCount:0,fallbackMethod:"GET",fallbackTransport:"streaming",transport:"long-polling",webSocketImpl:null,webSocketBinaryType:null,dispatchUrl:null,webSocketPathDelimiter:"@@",enableXDR:false,rewriteURL:false,attachHeadersAsQueryString:true,executeCallbackBeforeReconnect:false,readyState:0,lastTimestamp:0,withCredentials:false,trackMessageLength:false,messageDelimiter:"|",connectTimeout:-1,reconnectInterval:0,dropHeaders:true,uuid:0,async:true,shared:false,readResponsesHeaders:false,maxReconnectOnClose:5,enableProtocol:true,onError:function(aA){},onClose:function(aA){},onOpen:function(aA){},onMessage:function(aA){},onReopen:function(aB,aA){},onReconnect:function(aB,aA){},onMessagePublished:function(aA){},onTransportFailure:function(aB,aA){},onLocalMessage:function(aA){},onFailureToReconnect:function(aB,aA){},onClientTimeout:function(aA){}}; | |
5 | -var W={status:200,reasonPhrase:"OK",responseBody:"",messages:[],headers:[],state:"messageReceived",transport:"polling",error:null,request:null,partialMessage:"",errorHandled:false,closedByClientTimeout:false}; | |
6 | -var Z=null; | |
7 | -var o=null; | |
8 | -var v=null; | |
9 | -var E=null; | |
10 | -var G=null; | |
11 | -var ak=true; | |
12 | -var l=0; | |
13 | -var aw=false; | |
14 | -var aa=null; | |
15 | -var aq; | |
16 | -var q=null; | |
17 | -var J=a.util.now(); | |
18 | -var K; | |
19 | -var az; | |
20 | -ay(M); | |
21 | -function ar(){ak=true; | |
22 | -aw=false; | |
23 | -l=0; | |
24 | -Z=null; | |
25 | -o=null; | |
26 | -v=null; | |
27 | -E=null | |
28 | -}function A(){am(); | |
29 | -ar() | |
30 | -}function L(aB,aA){if(W.partialMessage===""&&(aA.transport==="streaming")&&(aB.responseText.length>aA.maxStreamingLength)){W.messages=[]; | |
31 | -ai(true); | |
32 | -D(); | |
33 | -am(); | |
34 | -R(aB,aA,0) | |
35 | -}}function D(){if(O.enableProtocol&&!O.firstMessage){var aC="X-Atmosphere-Transport=close&X-Atmosphere-tracking-id="+O.uuid; | |
36 | -a.util.each(O.headers,function(aE,aG){var aF=a.util.isFunction(aG)?aG.call(this,O,O,W):aG; | |
37 | -if(aF!=null){aC+="&"+encodeURIComponent(aE)+"="+encodeURIComponent(aF) | |
38 | -}}); | |
39 | -var aA=O.url.replace(/([?&])_=[^&]*/,aC); | |
40 | -aA=aA+(aA===O.url?(/\?/.test(O.url)?"&":"?")+aC:""); | |
41 | -var aB={connected:false}; | |
42 | -var aD=new a.AtmosphereRequest(aB); | |
43 | -aD.attachHeadersAsQueryString=false; | |
44 | -aD.dropHeaders=true; | |
45 | -aD.url=aA; | |
46 | -aD.contentType="text/plain"; | |
47 | -aD.transport="polling"; | |
48 | -aD.async=false; | |
49 | -n("",aD) | |
50 | -}}function an(){if(O.reconnectId){clearTimeout(O.reconnectId); | |
51 | -delete O.reconnectId | |
52 | -}O.reconnect=false; | |
53 | -aw=true; | |
54 | -W.request=O; | |
55 | -W.state="unsubscribe"; | |
56 | -W.responseBody=""; | |
57 | -W.status=408; | |
58 | -W.partialMessage=""; | |
59 | -C(); | |
60 | -D(); | |
61 | -am() | |
62 | -}function am(){W.partialMessage=""; | |
63 | -if(O.id){clearTimeout(O.id) | |
64 | -}if(E!=null){E.close(); | |
65 | -E=null | |
66 | -}if(G!=null){G.abort(); | |
67 | -G=null | |
68 | -}if(v!=null){v.abort(); | |
69 | -v=null | |
70 | -}if(Z!=null){if(Z.webSocketOpened){Z.close() | |
71 | -}Z=null | |
72 | -}if(o!=null){o.close(); | |
73 | -o=null | |
74 | -}at() | |
75 | -}function at(){if(aq!=null){clearInterval(K); | |
76 | -document.cookie=az+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"; | |
77 | -aq.signal("close",{reason:"",heir:!aw?J:(aq.get("children")||[])[0]}); | |
78 | -aq.close() | |
79 | -}if(q!=null){q.close() | |
80 | -}}function ay(aA){A(); | |
81 | -O=a.util.extend(O,aA); | |
82 | -O.mrequest=O.reconnect; | |
83 | -if(!O.reconnect){O.reconnect=true | |
84 | -}}function p(){return O.webSocketImpl!=null||window.WebSocket||window.MozWebSocket | |
85 | -}function S(){return window.EventSource | |
86 | -}function t(){if(O.shared){q=ah(O); | |
87 | -if(q!=null){if(O.logLevel==="debug"){a.util.debug("Storage service available. All communication will be local") | |
88 | -}if(q.open(O)){return | |
89 | -}}if(O.logLevel==="debug"){a.util.debug("No Storage service available.") | |
90 | -}q=null | |
91 | -}O.firstMessage=e==0?true:false; | |
92 | -O.isOpen=false; | |
93 | -O.ctime=a.util.now(); | |
94 | -if(O.uuid===0){O.uuid=e | |
95 | -}W.closedByClientTimeout=false; | |
96 | -if(O.transport!=="websocket"&&O.transport!=="sse"){s(O) | |
97 | -}else{if(O.transport==="websocket"){if(!p()){Q("Websocket is not supported, using request.fallbackTransport ("+O.fallbackTransport+")") | |
98 | -}else{aj(false) | |
99 | -}}else{if(O.transport==="sse"){if(!S()){Q("Server Side Events(SSE) is not supported, using request.fallbackTransport ("+O.fallbackTransport+")") | |
100 | -}else{I(false) | |
101 | -}}}}}function ah(aE){var aF,aD,aI,aA="atmosphere-"+aE.url,aB={storage:function(){function aJ(aN){if(aN.key===aA&&aN.newValue){aC(aN.newValue) | |
102 | -}}if(!a.util.storage){return | |
103 | -}var aM=window.localStorage,aK=function(aN){return a.util.parseJSON(aM.getItem(aA+"-"+aN)) | |
104 | -},aL=function(aN,aO){aM.setItem(aA+"-"+aN,a.util.stringifyJSON(aO)) | |
105 | -}; | |
106 | -return{init:function(){aL("children",aK("children").concat([J])); | |
107 | -a.util.on(window,"storage",aJ); | |
108 | -return aK("opened") | |
109 | -},signal:function(aN,aO){aM.setItem(aA,a.util.stringifyJSON({target:"p",type:aN,data:aO})) | |
110 | -},close:function(){var aN=aK("children"); | |
111 | -a.util.off(window,"storage",aJ); | |
112 | -if(aN){if(aG(aN,aE.id)){aL("children",aN) | |
113 | -}}}} | |
114 | -},windowref:function(){var aJ=window.open("",aA.replace(/\W/g,"")); | |
115 | -if(!aJ||aJ.closed||!aJ.callbacks){return | |
116 | -}return{init:function(){aJ.callbacks.push(aC); | |
117 | -aJ.children.push(J); | |
118 | -return aJ.opened | |
119 | -},signal:function(aK,aL){if(!aJ.closed&&aJ.fire){aJ.fire(a.util.stringifyJSON({target:"p",type:aK,data:aL})) | |
120 | -}},close:function(){if(!aI){aG(aJ.callbacks,aC); | |
121 | -aG(aJ.children,J) | |
122 | -}}} | |
123 | -}}; | |
124 | -function aG(aM,aL){var aJ,aK=aM.length; | |
125 | -for(aJ=0; | |
126 | -aJ<aK; | |
127 | -aJ++){if(aM[aJ]===aL){aM.splice(aJ,1) | |
128 | -}}return aK!==aM.length | |
129 | -}function aC(aJ){var aL=a.util.parseJSON(aJ),aK=aL.data; | |
130 | -if(aL.target==="c"){switch(aL.type){case"open":N("opening","local",O); | |
131 | -break; | |
132 | -case"close":if(!aI){aI=true; | |
133 | -if(aK.reason==="aborted"){an() | |
134 | -}else{if(aK.heir===J){t() | |
135 | -}else{setTimeout(function(){t() | |
136 | -},100) | |
137 | -}}}break; | |
138 | -case"message":F(aK,"messageReceived",200,aE.transport); | |
139 | -break; | |
140 | -case"localMessage":ac(aK); | |
141 | -break | |
142 | -}}}function aH(){var aJ=new RegExp("(?:^|; )("+encodeURIComponent(aA)+")=([^;]*)").exec(document.cookie); | |
143 | -if(aJ){return a.util.parseJSON(decodeURIComponent(aJ[2])) | |
144 | -}}aF=aH(); | |
145 | -if(!aF||a.util.now()-aF.ts>1000){return | |
146 | -}aD=aB.storage()||aB.windowref(); | |
147 | -if(!aD){return | |
148 | -}return{open:function(){var aJ; | |
149 | -K=setInterval(function(){var aK=aF; | |
150 | -aF=aH(); | |
151 | -if(!aF||aK.ts===aF.ts){aC(a.util.stringifyJSON({target:"c",type:"close",data:{reason:"error",heir:aK.heir}})) | |
152 | -}},1000); | |
153 | -aJ=aD.init(); | |
154 | -if(aJ){setTimeout(function(){N("opening","local",aE) | |
155 | -},50) | |
156 | -}return aJ | |
157 | -},send:function(aJ){aD.signal("send",aJ) | |
158 | -},localSend:function(aJ){aD.signal("localSend",a.util.stringifyJSON({id:J,event:aJ})) | |
159 | -},close:function(){if(!aw){clearInterval(K); | |
160 | -aD.signal("close"); | |
161 | -aD.close() | |
162 | -}}} | |
163 | -}function ad(){var aB,aA="atmosphere-"+O.url,aF={storage:function(){function aG(aI){if(aI.key===aA&&aI.newValue){aC(aI.newValue) | |
164 | -}}if(!a.util.storage){return | |
165 | -}var aH=window.localStorage; | |
166 | -return{init:function(){a.util.on(window,"storage",aG) | |
167 | -},signal:function(aI,aJ){aH.setItem(aA,a.util.stringifyJSON({target:"c",type:aI,data:aJ})) | |
168 | -},get:function(aI){return a.util.parseJSON(aH.getItem(aA+"-"+aI)) | |
169 | -},set:function(aI,aJ){aH.setItem(aA+"-"+aI,a.util.stringifyJSON(aJ)) | |
170 | -},close:function(){a.util.off(window,"storage",aG); | |
171 | -aH.removeItem(aA); | |
172 | -aH.removeItem(aA+"-opened"); | |
173 | -aH.removeItem(aA+"-children") | |
174 | -}} | |
175 | -},windowref:function(){var aH=aA.replace(/\W/g,""),aG=document.getElementById(aH),aI; | |
176 | -if(!aG){aG=document.createElement("div"); | |
177 | -aG.id=aH; | |
178 | -aG.style.display="none"; | |
179 | -aG.innerHTML='<iframe name="'+aH+'" />'; | |
180 | -document.body.appendChild(aG) | |
181 | -}aI=aG.firstChild.contentWindow; | |
182 | -return{init:function(){aI.callbacks=[aC]; | |
183 | -aI.fire=function(aJ){var aK; | |
184 | -for(aK=0; | |
185 | -aK<aI.callbacks.length; | |
186 | -aK++){aI.callbacks[aK](aJ) | |
187 | -}} | |
188 | -},signal:function(aJ,aK){if(!aI.closed&&aI.fire){aI.fire(a.util.stringifyJSON({target:"c",type:aJ,data:aK})) | |
189 | -}},get:function(aJ){return !aI.closed?aI[aJ]:null | |
190 | -},set:function(aJ,aK){if(!aI.closed){aI[aJ]=aK | |
191 | -}},close:function(){}} | |
192 | -}}; | |
193 | -function aC(aG){var aI=a.util.parseJSON(aG),aH=aI.data; | |
194 | -if(aI.target==="p"){switch(aI.type){case"send":al(aH); | |
195 | -break; | |
196 | -case"localSend":ac(aH); | |
197 | -break; | |
198 | -case"close":an(); | |
199 | -break | |
200 | -}}}aa=function aE(aG){aB.signal("message",aG) | |
201 | -}; | |
202 | -function aD(){document.cookie=az+"="+encodeURIComponent(a.util.stringifyJSON({ts:a.util.now()+1,heir:(aB.get("children")||[])[0]}))+"; path=/" | |
203 | -}aB=aF.storage()||aF.windowref(); | |
204 | -aB.init(); | |
205 | -if(O.logLevel==="debug"){a.util.debug("Installed StorageService "+aB) | |
206 | -}aB.set("children",[]); | |
207 | -if(aB.get("opened")!=null&&!aB.get("opened")){aB.set("opened",false) | |
208 | -}az=encodeURIComponent(aA); | |
209 | -aD(); | |
210 | -K=setInterval(aD,1000); | |
211 | -aq=aB | |
212 | -}function N(aC,aF,aB){if(O.shared&&aF!=="local"){ad() | |
213 | -}if(aq!=null){aq.set("opened",true) | |
214 | -}aB.close=function(){an() | |
215 | -}; | |
216 | -if(l>0&&aC==="re-connecting"){aB.isReopen=true; | |
217 | -ae(W) | |
218 | -}else{if(W.error==null){W.request=aB; | |
219 | -var aD=W.state; | |
220 | -W.state=aC; | |
221 | -var aA=W.transport; | |
222 | -W.transport=aF; | |
223 | -var aE=W.responseBody; | |
224 | -C(); | |
225 | -W.responseBody=aE; | |
226 | -W.state=aD; | |
227 | -W.transport=aA | |
228 | -}}}function z(aC){aC.transport="jsonp"; | |
229 | -var aB=O,aA; | |
230 | -if((aC!=null)&&(typeof(aC)!=="undefined")){aB=aC | |
231 | -}G={open:function(){var aE="atmosphere"+(++J); | |
232 | -function aD(){var aF=aB.url; | |
233 | -if(aB.dispatchUrl!=null){aF+=aB.dispatchUrl | |
234 | -}var aH=aB.data; | |
235 | -if(aB.attachHeadersAsQueryString){aF=X(aB); | |
236 | -if(aH!==""){aF+="&X-Atmosphere-Post-Body="+encodeURIComponent(aH) | |
237 | -}aH="" | |
238 | -}var aG=document.head||document.getElementsByTagName("head")[0]||document.documentElement; | |
239 | -aA=document.createElement("script"); | |
240 | -aA.src=aF+"&jsonpTransport="+aE; | |
241 | -aA.clean=function(){aA.clean=aA.onerror=aA.onload=aA.onreadystatechange=null; | |
242 | -if(aA.parentNode){aA.parentNode.removeChild(aA) | |
243 | -}}; | |
244 | -aA.onload=aA.onreadystatechange=function(){if(!aA.readyState||/loaded|complete/.test(aA.readyState)){aA.clean() | |
245 | -}}; | |
246 | -aA.onerror=function(){aA.clean(); | |
247 | -aB.lastIndex=0; | |
248 | -if(aB.openId){clearTimeout(aB.openId) | |
249 | -}if(aB.reconnect&&l++<aB.maxReconnectOnClose){N("re-connecting",aB.transport,aB); | |
250 | -R(G,aB,aC.reconnectInterval); | |
251 | -aB.openId=setTimeout(function(){ao(aB) | |
252 | -},aB.reconnectInterval+1000) | |
253 | -}else{af(0,"maxReconnectOnClose reached") | |
254 | -}}; | |
255 | -aG.insertBefore(aA,aG.firstChild) | |
256 | -}window[aE]=function(aH){if(aB.reconnect){if(aB.maxRequest===-1||aB.requestCount++<aB.maxRequest){if(!aB.executeCallbackBeforeReconnect){R(G,aB,0) | |
257 | -}if(aH!=null&&typeof aH!=="string"){try{aH=aH.message | |
258 | -}catch(aG){}}var aF=x(aH,aB,W); | |
259 | -if(!aF){F(W.responseBody,"messageReceived",200,aB.transport) | |
260 | -}if(aB.executeCallbackBeforeReconnect){R(G,aB,0) | |
261 | -}}else{a.util.log(O.logLevel,["JSONP reconnect maximum try reached "+O.requestCount]); | |
262 | -af(0,"maxRequest reached") | |
263 | -}}}; | |
264 | -setTimeout(function(){aD() | |
265 | -},50) | |
266 | -},abort:function(){if(aA.clean){aA.clean() | |
267 | -}}}; | |
268 | -G.open() | |
269 | -}function j(aA){if(O.webSocketImpl!=null){return O.webSocketImpl | |
270 | -}else{if(window.WebSocket){return new WebSocket(aA) | |
271 | -}else{return new MozWebSocket(aA) | |
272 | -}}}function k(){return a.util.getAbsoluteURL(X(O)).replace(/^http/,"ws") | |
273 | -}function ax(){var aA=X(O); | |
274 | -return aA | |
275 | -}function I(aB){W.transport="sse"; | |
276 | -var aA=ax(); | |
277 | -if(O.logLevel==="debug"){a.util.debug("Invoking executeSSE"); | |
278 | -a.util.debug("Using URL: "+aA) | |
279 | -}if(O.enableProtocol&&aB){var aD=a.util.now()-O.ctime; | |
280 | -O.lastTimestamp=Number(O.stime)+Number(aD) | |
281 | -}if(aB&&!O.reconnect){if(o!=null){am() | |
282 | -}return | |
283 | -}try{o=new EventSource(aA,{withCredentials:O.withCredentials}) | |
284 | -}catch(aC){af(0,aC); | |
285 | -Q("SSE failed. Downgrading to fallback transport and resending"); | |
286 | -return | |
287 | -}if(O.connectTimeout>0){O.id=setTimeout(function(){if(!aB){am() | |
288 | -}},O.connectTimeout) | |
289 | -}o.onopen=function(aE){y(O); | |
290 | -if(O.logLevel==="debug"){a.util.debug("SSE successfully opened") | |
291 | -}if(!O.enableProtocol){if(!aB){N("opening","sse",O) | |
292 | -}else{N("re-opening","sse",O) | |
293 | -}}else{if(O.isReopen){O.isReopen=false; | |
294 | -N("re-opening",O.transport,O) | |
295 | -}}aB=true; | |
296 | -if(O.method==="POST"){W.state="messageReceived"; | |
297 | -o.send(O.data) | |
298 | -}}; | |
299 | -o.onmessage=function(aF){y(O); | |
300 | -if(!O.enableXDR&&aF.origin&&aF.origin!==window.location.protocol+"//"+window.location.host){a.util.log(O.logLevel,["Origin was not "+window.location.protocol+"//"+window.location.host]); | |
301 | -return | |
302 | -}W.state="messageReceived"; | |
303 | -W.status=200; | |
304 | -aF=aF.data; | |
305 | -var aE=x(aF,O,W); | |
306 | -if(!aE){C(); | |
307 | -W.responseBody=""; | |
308 | -W.messages=[] | |
309 | -}}; | |
310 | -o.onerror=function(aE){clearTimeout(O.id); | |
311 | -if(W.closedByClientTimeout){return | |
312 | -}ai(aB); | |
313 | -am(); | |
314 | -if(aw){a.util.log(O.logLevel,["SSE closed normally"]) | |
315 | -}else{if(!aB){Q("SSE failed. Downgrading to fallback transport and resending") | |
316 | -}else{if(O.reconnect&&(W.transport==="sse")){if(l++<O.maxReconnectOnClose){N("re-connecting",O.transport,O); | |
317 | -if(O.reconnectInterval>0){O.reconnectId=setTimeout(function(){I(true) | |
318 | -},O.reconnectInterval) | |
319 | -}else{I(true) | |
320 | -}W.responseBody=""; | |
321 | -W.messages=[] | |
322 | -}else{a.util.log(O.logLevel,["SSE reconnect maximum try reached "+l]); | |
323 | -af(0,"maxReconnectOnClose reached") | |
324 | -}}}}} | |
325 | -}function aj(aB){W.transport="websocket"; | |
326 | -if(O.enableProtocol&&aB){var aC=a.util.now()-O.ctime; | |
327 | -O.lastTimestamp=Number(O.stime)+Number(aC) | |
328 | -}var aA=k(O.url); | |
329 | -if(O.logLevel==="debug"){a.util.debug("Invoking executeWebSocket"); | |
330 | -a.util.debug("Using URL: "+aA) | |
331 | -}if(aB&&!O.reconnect){if(Z!=null){am() | |
332 | -}return | |
333 | -}Z=j(aA); | |
334 | -if(O.webSocketBinaryType!=null){Z.binaryType=O.webSocketBinaryType | |
335 | -}if(O.connectTimeout>0){O.id=setTimeout(function(){if(!aB){var aD={code:1002,reason:"",wasClean:false}; | |
336 | -Z.onclose(aD); | |
337 | -try{am() | |
338 | -}catch(aE){}return | |
339 | -}},O.connectTimeout) | |
340 | -}Z.onopen=function(aE){y(O); | |
341 | -if(O.logLevel==="debug"){a.util.debug("Websocket successfully opened") | |
342 | -}var aD=aB; | |
343 | -aB=true; | |
344 | -if(Z!=null){Z.webSocketOpened=aB | |
345 | -}if(!O.enableProtocol){if(aD){N("re-opening","websocket",O) | |
346 | -}else{N("opening","websocket",O) | |
347 | -}}if(Z!=null){if(O.method==="POST"){W.state="messageReceived"; | |
348 | -Z.send(O.data) | |
349 | -}}}; | |
350 | -Z.onmessage=function(aF){y(O); | |
351 | -W.state="messageReceived"; | |
352 | -W.status=200; | |
353 | -aF=aF.data; | |
354 | -var aD=typeof(aF)==="string"; | |
355 | -if(aD){var aE=x(aF,O,W); | |
356 | -if(!aE){C(); | |
357 | -W.responseBody=""; | |
358 | -W.messages=[] | |
359 | -}}else{if(!u(O,aF)){return | |
360 | -}W.responseBody=aF; | |
361 | -C(); | |
362 | -W.responseBody=null | |
363 | -}}; | |
364 | -Z.onerror=function(aD){clearTimeout(O.id) | |
365 | -}; | |
366 | -Z.onclose=function(aD){clearTimeout(O.id); | |
367 | -if(W.state==="closed"){return | |
368 | -}var aE=aD.reason; | |
369 | -if(aE===""){switch(aD.code){case 1000:aE="Normal closure; the connection successfully completed whatever purpose for which it was created."; | |
370 | -break; | |
371 | -case 1001:aE="The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection."; | |
372 | -break; | |
373 | -case 1002:aE="The endpoint is terminating the connection due to a protocol error."; | |
374 | -break; | |
375 | -case 1003:aE="The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data)."; | |
376 | -break; | |
377 | -case 1004:aE="The endpoint is terminating the connection because a data frame was received that is too large."; | |
378 | -break; | |
379 | -case 1005:aE="Unknown: no status code was provided even though one was expected."; | |
380 | -break; | |
381 | -case 1006:aE="Connection was closed abnormally (that is, with no close frame being sent)."; | |
382 | -break | |
383 | -}}if(O.logLevel==="warn"){a.util.warn("Websocket closed, reason: "+aE); | |
384 | -a.util.warn("Websocket closed, wasClean: "+aD.wasClean) | |
385 | -}if(W.closedByClientTimeout){return | |
386 | -}ai(aB); | |
387 | -W.state="closed"; | |
388 | -if(aw){a.util.log(O.logLevel,["Websocket closed normally"]) | |
389 | -}else{if(!aB){Q("Websocket failed. Downgrading to Comet and resending") | |
390 | -}else{if(O.reconnect&&W.transport==="websocket"){am(); | |
391 | -if(l++<O.maxReconnectOnClose){N("re-connecting",O.transport,O); | |
392 | -if(O.reconnectInterval>0){O.reconnectId=setTimeout(function(){W.responseBody=""; | |
393 | -W.messages=[]; | |
394 | -aj(true) | |
395 | -},O.reconnectInterval) | |
396 | -}else{W.responseBody=""; | |
397 | -W.messages=[]; | |
398 | -aj(true) | |
399 | -}}else{a.util.log(O.logLevel,["Websocket reconnect maximum try reached "+O.requestCount]); | |
400 | -if(O.logLevel==="warn"){a.util.warn("Websocket error, reason: "+aD.reason) | |
401 | -}af(0,"maxReconnectOnClose reached") | |
402 | -}}}}}; | |
403 | -if(Z.url===undefined){Z.onclose({reason:"Android 4.1 does not support websockets.",wasClean:false}) | |
404 | -}}function u(aD,aC){var aA=true; | |
405 | -if(aD.transport==="polling"){return aA | |
406 | -}if(a.util.trim(aC).length!==0&&aD.enableProtocol&&aD.firstMessage){aD.firstMessage=false; | |
407 | -var aB=aC.split(aD.messageDelimiter); | |
408 | -var aE=aB.length===2?0:1; | |
409 | -aD.uuid=a.util.trim(aB[aE]); | |
410 | -aD.stime=a.util.trim(aB[aE+1]); | |
411 | -aA=false; | |
412 | -if(aD.transport!=="long-polling"){ao(aD) | |
413 | -}e=aD.uuid | |
414 | -}else{if(aD.enableProtocol&&aD.firstMessage){aA=false | |
415 | -}else{ao(aD) | |
416 | -}}return aA | |
417 | -}function y(aA){clearTimeout(aA.id); | |
418 | -if(aA.timeout>0&&aA.transport!=="polling"){aA.id=setTimeout(function(){r(aA); | |
419 | -D(); | |
420 | -am() | |
421 | -},aA.timeout) | |
422 | -}}function r(aA){W.closedByClientTimeout=true; | |
423 | -W.state="closedByClient"; | |
424 | -W.responseBody=""; | |
425 | -W.status=408; | |
426 | -W.messages=[]; | |
427 | -C() | |
428 | -}function af(aA,aB){am(); | |
429 | -clearTimeout(O.id); | |
430 | -W.state="error"; | |
431 | -W.reasonPhrase=aB; | |
432 | -W.responseBody=""; | |
433 | -W.status=aA; | |
434 | -W.messages=[]; | |
435 | -C() | |
436 | -}function x(aE,aD,aA){if(!u(aD,aE)){return true | |
437 | -}if(aE.length===0){return true | |
438 | -}if(aD.trackMessageLength){aE=aA.partialMessage+aE; | |
439 | -var aC=[]; | |
440 | -var aB=aE.indexOf(aD.messageDelimiter); | |
441 | -while(aB!==-1){var aG=a.util.trim(aE.substring(0,aB)); | |
442 | -var aF=+aG; | |
443 | -if(isNaN(aF)){throw new Error('message length "'+aG+'" is not a number') | |
444 | -}aB+=aD.messageDelimiter.length; | |
445 | -if(aB+aF>aE.length){aB=-1 | |
446 | -}else{aC.push(aE.substring(aB,aB+aF)); | |
447 | -aE=aE.substring(aB+aF,aE.length); | |
448 | -aB=aE.indexOf(aD.messageDelimiter) | |
449 | -}}aA.partialMessage=aE; | |
450 | -if(aC.length!==0){aA.responseBody=aC.join(aD.messageDelimiter); | |
451 | -aA.messages=aC; | |
452 | -return false | |
453 | -}else{aA.responseBody=""; | |
454 | -aA.messages=[]; | |
455 | -return true | |
456 | -}}else{aA.responseBody=aE | |
457 | -}return false | |
458 | -}function Q(aA){a.util.log(O.logLevel,[aA]); | |
459 | -if(typeof(O.onTransportFailure)!=="undefined"){O.onTransportFailure(aA,O) | |
460 | -}else{if(typeof(a.util.onTransportFailure)!=="undefined"){a.util.onTransportFailure(aA,O) | |
461 | -}}O.transport=O.fallbackTransport; | |
462 | -var aB=O.connectTimeout===-1?0:O.connectTimeout; | |
463 | -if(O.reconnect&&O.transport!=="none"||O.transport==null){O.method=O.fallbackMethod; | |
464 | -W.transport=O.fallbackTransport; | |
465 | -O.fallbackTransport="none"; | |
466 | -if(aB>0){O.reconnectId=setTimeout(function(){t() | |
467 | -},aB) | |
468 | -}else{t() | |
469 | -}}else{af(500,"Unable to reconnect with fallback transport") | |
470 | -}}function X(aC,aA){var aB=O; | |
471 | -if((aC!=null)&&(typeof(aC)!=="undefined")){aB=aC | |
472 | -}if(aA==null){aA=aB.url | |
473 | -}if(!aB.attachHeadersAsQueryString){return aA | |
474 | -}if(aA.indexOf("X-Atmosphere-Framework")!==-1){return aA | |
475 | -}aA+=(aA.indexOf("?")!==-1)?"&":"?"; | |
476 | -aA+="X-Atmosphere-tracking-id="+aB.uuid; | |
477 | -aA+="&X-Atmosphere-Framework="+c; | |
478 | -aA+="&X-Atmosphere-Transport="+aB.transport; | |
479 | -if(aB.trackMessageLength){aA+="&X-Atmosphere-TrackMessageSize=true" | |
480 | -}if(aB.lastTimestamp!=null){aA+="&X-Cache-Date="+aB.lastTimestamp | |
481 | -}else{aA+="&X-Cache-Date="+0 | |
482 | -}if(aB.contentType!==""){aA+="&Content-Type="+(aB.transport==="websocket"?aB.contentType:encodeURIComponent(aB.contentType)) | |
483 | -}if(aB.enableProtocol){aA+="&X-atmo-protocol=true" | |
484 | -}a.util.each(aB.headers,function(aD,aF){var aE=a.util.isFunction(aF)?aF.call(this,aB,aC,W):aF; | |
485 | -if(aE!=null){aA+="&"+encodeURIComponent(aD)+"="+encodeURIComponent(aE) | |
486 | -}}); | |
487 | -return aA | |
488 | -}function ao(aA){if(!aA.isOpen){aA.isOpen=true; | |
489 | -N("opening",aA.transport,aA) | |
490 | -}else{if(aA.isReopen){aA.isReopen=false; | |
491 | -N("re-opening",aA.transport,aA) | |
492 | -}}}function s(aC){var aA=O; | |
493 | -if((aC!=null)||(typeof(aC)!=="undefined")){aA=aC | |
494 | -}aA.lastIndex=0; | |
495 | -aA.readyState=0; | |
496 | -if((aA.transport==="jsonp")||((aA.enableXDR)&&(a.util.checkCORSSupport()))){z(aA); | |
497 | -return | |
498 | -}if(a.util.browser.msie&&+a.util.browser.version.split(".")[0]<10){if((aA.transport==="streaming")){if(aA.enableXDR&&window.XDomainRequest){P(aA) | |
499 | -}else{av(aA) | |
500 | -}return | |
501 | -}if((aA.enableXDR)&&(window.XDomainRequest)){P(aA); | |
502 | -return | |
503 | -}}var aD=function(){aA.lastIndex=0; | |
504 | -if(aA.reconnect&&l++<aA.maxReconnectOnClose){N("re-connecting",aC.transport,aC); | |
505 | -R(aB,aA,aC.reconnectInterval) | |
506 | -}else{af(0,"maxReconnectOnClose reached") | |
507 | -}}; | |
508 | -if(aA.force||(aA.reconnect&&(aA.maxRequest===-1||aA.requestCount++<aA.maxRequest))){aA.force=false; | |
509 | -var aB=a.util.xhr(); | |
510 | -aB.hasData=false; | |
511 | -h(aB,aA,true); | |
512 | -if(aA.suspend){v=aB | |
513 | -}if(aA.transport!=="polling"){W.transport=aA.transport; | |
514 | -aB.onabort=function(){ai(true) | |
515 | -}; | |
516 | -aB.onerror=function(){W.error=true; | |
517 | -try{W.status=XMLHttpRequest.status | |
518 | -}catch(aF){W.status=500 | |
519 | -}if(!W.status){W.status=500 | |
520 | -}if(!W.errorHandled){am(); | |
521 | -aD() | |
522 | -}} | |
523 | -}aB.onreadystatechange=function(){if(aw){return | |
524 | -}W.error=null; | |
525 | -var aG=false; | |
526 | -var aL=false; | |
527 | -if(aA.transport==="streaming"&&aA.readyState>2&&aB.readyState===4){am(); | |
528 | -aD(); | |
529 | -return | |
530 | -}aA.readyState=aB.readyState; | |
531 | -if(aA.transport==="streaming"&&aB.readyState>=3){aL=true | |
532 | -}else{if(aA.transport==="long-polling"&&aB.readyState===4){aL=true | |
533 | -}}y(O); | |
534 | -if(aA.transport!=="polling"){var aF=200; | |
535 | -if(aB.readyState===4){aF=aB.status>1000?0:aB.status | |
536 | -}if(aF>=300||aF===0){W.errorHandled=true; | |
537 | -am(); | |
538 | -aD(); | |
539 | -return | |
540 | -}if((!aA.enableProtocol||!aC.firstMessage)&&aB.readyState===2){ao(aA) | |
541 | -}}else{if(aB.readyState===4){aL=true | |
542 | -}}if(aL){var aJ=aB.responseText; | |
543 | -if(a.util.trim(aJ).length===0&&aA.transport==="long-polling"){if(!aB.hasData){R(aB,aA,0) | |
544 | -}else{aB.hasData=false | |
545 | -}return | |
546 | -}aB.hasData=true; | |
547 | -ag(aB,O); | |
548 | -if(aA.transport==="streaming"){if(!a.util.browser.opera){var aI=aJ.substring(aA.lastIndex,aJ.length); | |
549 | -aG=x(aI,aA,W); | |
550 | -aA.lastIndex=aJ.length; | |
551 | -if(aG){return | |
552 | -}}else{a.util.iterate(function(){if(W.status!==500&&aB.responseText.length>aA.lastIndex){try{W.status=aB.status; | |
553 | -W.headers=a.util.parseHeaders(aB.getAllResponseHeaders()); | |
554 | -ag(aB,O) | |
555 | -}catch(aN){W.status=404 | |
556 | -}y(O); | |
557 | -W.state="messageReceived"; | |
558 | -var aM=aB.responseText.substring(aA.lastIndex); | |
559 | -aA.lastIndex=aB.responseText.length; | |
560 | -aG=x(aM,aA,W); | |
561 | -if(!aG){C() | |
562 | -}L(aB,aA) | |
563 | -}else{if(W.status>400){aA.lastIndex=aB.responseText.length; | |
564 | -return false | |
565 | -}}},0) | |
566 | -}}else{aG=x(aJ,aA,W) | |
567 | -}try{W.status=aB.status; | |
568 | -W.headers=a.util.parseHeaders(aB.getAllResponseHeaders()); | |
569 | -ag(aB,aA) | |
570 | -}catch(aK){W.status=404 | |
571 | -}if(aA.suspend){W.state=W.status===0?"closed":"messageReceived" | |
572 | -}else{W.state="messagePublished" | |
573 | -}var aH=aC.transport!=="streaming"&&aC.transport!=="polling"; | |
574 | -if(aH&&!aA.executeCallbackBeforeReconnect){R(aB,aA,0) | |
575 | -}if(W.responseBody.length!==0&&!aG){C() | |
576 | -}if(aH&&aA.executeCallbackBeforeReconnect){R(aB,aA,0) | |
577 | -}L(aB,aA) | |
578 | -}}; | |
579 | -try{aB.send(aA.data); | |
580 | -ak=true | |
581 | -}catch(aE){a.util.log(aA.logLevel,["Unable to connect to "+aA.url]) | |
582 | -}}else{if(aA.logLevel==="debug"){a.util.log(aA.logLevel,["Max re-connection reached."]) | |
583 | -}af(0,"maxRequest reached") | |
584 | -}}function h(aC,aD,aB){var aA=aD.url; | |
585 | -if(aD.dispatchUrl!=null&&aD.method==="POST"){aA+=aD.dispatchUrl | |
586 | -}aA=X(aD,aA); | |
587 | -aA=a.util.prepareURL(aA); | |
588 | -if(aB){aC.open(aD.method,aA,aD.async); | |
589 | -if(aD.connectTimeout>0){aD.id=setTimeout(function(){if(aD.requestCount===0){am(); | |
590 | -F("Connect timeout","closed",200,aD.transport) | |
591 | -}},aD.connectTimeout) | |
592 | -}}if(O.withCredentials){if("withCredentials" in aC){aC.withCredentials=true | |
593 | -}}if(!O.dropHeaders){aC.setRequestHeader("X-Atmosphere-Framework",a.util.version); | |
594 | -aC.setRequestHeader("X-Atmosphere-Transport",aD.transport); | |
595 | -if(aD.lastTimestamp!=null){aC.setRequestHeader("X-Cache-Date",aD.lastTimestamp) | |
596 | -}else{aC.setRequestHeader("X-Cache-Date",0) | |
597 | -}if(aD.trackMessageLength){aC.setRequestHeader("X-Atmosphere-TrackMessageSize","true") | |
598 | -}aC.setRequestHeader("X-Atmosphere-tracking-id",aD.uuid); | |
599 | -a.util.each(aD.headers,function(aE,aG){var aF=a.util.isFunction(aG)?aG.call(this,aC,aD,aB,W):aG; | |
600 | -if(aF!=null){aC.setRequestHeader(aE,aF) | |
601 | -}}) | |
602 | -}if(aD.contentType!==""){aC.setRequestHeader("Content-Type",aD.contentType) | |
603 | -}}function R(aB,aC,aD){if(aC.reconnect||(aC.suspend&&ak)){var aA=0; | |
604 | -if(aB&&aB.readyState>1){aA=aB.status>1000?0:aB.status | |
605 | -}W.status=aA===0?204:aA; | |
606 | -W.reason=aA===0?"Server resumed the connection or down.":"OK"; | |
607 | -clearTimeout(aC.id); | |
608 | -if(aC.reconnectId){clearTimeout(aC.reconnectId); | |
609 | -delete aC.reconnectId | |
610 | -}if(aD>0){O.reconnectId=setTimeout(function(){s(aC) | |
611 | -},aD) | |
612 | -}else{s(aC) | |
613 | -}}}function ae(aA){aA.state="re-connecting"; | |
614 | -ab(aA) | |
615 | -}function P(aA){if(aA.transport!=="polling"){E=V(aA); | |
616 | -E.open() | |
617 | -}else{V(aA).open() | |
618 | -}}function V(aC){var aB=O; | |
619 | -if((aC!=null)&&(typeof(aC)!=="undefined")){aB=aC | |
620 | -}var aH=aB.transport; | |
621 | -var aG=0; | |
622 | -var aA=new window.XDomainRequest(); | |
623 | -var aE=function(){if(aB.transport==="long-polling"&&(aB.reconnect&&(aB.maxRequest===-1||aB.requestCount++<aB.maxRequest))){aA.status=200; | |
624 | -P(aB) | |
625 | -}}; | |
626 | -var aF=aB.rewriteURL||function(aJ){var aI=/(?:^|;\s*)(JSESSIONID|PHPSESSID)=([^;]*)/.exec(document.cookie); | |
627 | -switch(aI&&aI[1]){case"JSESSIONID":return aJ.replace(/;jsessionid=[^\?]*|(\?)|$/,";jsessionid="+aI[2]+"$1"); | |
628 | -case"PHPSESSID":return aJ.replace(/\?PHPSESSID=[^&]*&?|\?|$/,"?PHPSESSID="+aI[2]+"&").replace(/&$/,"") | |
629 | -}return aJ | |
630 | -}; | |
631 | -aA.onprogress=function(){aD(aA) | |
632 | -}; | |
633 | -aA.onerror=function(){if(aB.transport!=="polling"){am(); | |
634 | -if(l++<aB.maxReconnectOnClose){if(aB.reconnectInterval>0){aB.reconnectId=setTimeout(function(){N("re-connecting",aC.transport,aC); | |
635 | -P(aB) | |
636 | -},aB.reconnectInterval) | |
637 | -}else{N("re-connecting",aC.transport,aC); | |
638 | -P(aB) | |
639 | -}}else{af(0,"maxReconnectOnClose reached") | |
640 | -}}}; | |
641 | -aA.onload=function(){}; | |
642 | -var aD=function(aI){clearTimeout(aB.id); | |
643 | -var aK=aI.responseText; | |
644 | -aK=aK.substring(aG); | |
645 | -aG+=aK.length; | |
646 | -if(aH!=="polling"){y(aB); | |
647 | -var aJ=x(aK,aB,W); | |
648 | -if(aH==="long-polling"&&a.util.trim(aK).length===0){return | |
649 | -}if(aB.executeCallbackBeforeReconnect){aE() | |
650 | -}if(!aJ){F(W.responseBody,"messageReceived",200,aH) | |
651 | -}if(!aB.executeCallbackBeforeReconnect){aE() | |
652 | -}}}; | |
653 | -return{open:function(){var aI=aB.url; | |
654 | -if(aB.dispatchUrl!=null){aI+=aB.dispatchUrl | |
655 | -}aI=X(aB,aI); | |
656 | -aA.open(aB.method,aF(aI)); | |
657 | -if(aB.method==="GET"){aA.send() | |
658 | -}else{aA.send(aB.data) | |
659 | -}if(aB.connectTimeout>0){aB.id=setTimeout(function(){if(aB.requestCount===0){am(); | |
660 | -F("Connect timeout","closed",200,aB.transport) | |
661 | -}},aB.connectTimeout) | |
662 | -}},close:function(){aA.abort() | |
663 | -}} | |
664 | -}function av(aA){E=w(aA); | |
665 | -E.open() | |
666 | -}function w(aD){var aC=O; | |
667 | -if((aD!=null)&&(typeof(aD)!=="undefined")){aC=aD | |
668 | -}var aB; | |
669 | -var aE=new window.ActiveXObject("htmlfile"); | |
670 | -aE.open(); | |
671 | -aE.close(); | |
672 | -var aA=aC.url; | |
673 | -if(aC.dispatchUrl!=null){aA+=aC.dispatchUrl | |
674 | -}if(aC.transport!=="polling"){W.transport=aC.transport | |
675 | -}return{open:function(){var aF=aE.createElement("iframe"); | |
676 | -aA=X(aC); | |
677 | -if(aC.data!==""){aA+="&X-Atmosphere-Post-Body="+encodeURIComponent(aC.data) | |
678 | -}aA=a.util.prepareURL(aA); | |
679 | -aF.src=aA; | |
680 | -aE.body.appendChild(aF); | |
681 | -var aG=aF.contentDocument||aF.contentWindow.document; | |
682 | -aB=a.util.iterate(function(){try{if(!aG.firstChild){return | |
683 | -}var aJ=aG.body?aG.body.lastChild:aG; | |
684 | -var aL=function(){var aN=aJ.cloneNode(true); | |
685 | -aN.appendChild(aG.createTextNode(".")); | |
686 | -var aM=aN.innerText; | |
687 | -aM=aM.substring(0,aM.length-1); | |
688 | -return aM | |
689 | -}; | |
690 | -if(!aG.body||!aG.body.firstChild||aG.body.firstChild.nodeName.toLowerCase()!=="pre"){var aI=aG.head||aG.getElementsByTagName("head")[0]||aG.documentElement||aG; | |
691 | -var aH=aG.createElement("script"); | |
692 | -aH.text="document.write('<plaintext>')"; | |
693 | -aI.insertBefore(aH,aI.firstChild); | |
694 | -aI.removeChild(aH); | |
695 | -aJ=aG.body.lastChild | |
696 | -}if(aC.closed){aC.isReopen=true | |
697 | -}aB=a.util.iterate(function(){var aN=aL(); | |
698 | -if(aN.length>aC.lastIndex){y(O); | |
699 | -W.status=200; | |
700 | -W.error=null; | |
701 | -aJ.innerText=""; | |
702 | -var aM=x(aN,aC,W); | |
703 | -if(aM){return"" | |
704 | -}F(W.responseBody,"messageReceived",200,aC.transport) | |
705 | -}aC.lastIndex=0; | |
706 | -if(aG.readyState==="complete"){ai(true); | |
707 | -N("re-connecting",aC.transport,aC); | |
708 | -if(aC.reconnectInterval>0){aC.reconnectId=setTimeout(function(){av(aC) | |
709 | -},aC.reconnectInterval) | |
710 | -}else{av(aC) | |
711 | -}return false | |
712 | -}},null); | |
713 | -return false | |
714 | -}catch(aK){W.error=true; | |
715 | -N("re-connecting",aC.transport,aC); | |
716 | -if(l++<aC.maxReconnectOnClose){if(aC.reconnectInterval>0){aC.reconnectId=setTimeout(function(){av(aC) | |
717 | -},aC.reconnectInterval) | |
718 | -}else{av(aC) | |
719 | -}}else{af(0,"maxReconnectOnClose reached") | |
720 | -}aE.execCommand("Stop"); | |
721 | -aE.close(); | |
722 | -return false | |
723 | -}}) | |
724 | -},close:function(){if(aB){aB() | |
725 | -}aE.execCommand("Stop"); | |
726 | -ai(true) | |
727 | -}} | |
728 | -}function al(aA){if(q!=null){m(aA) | |
729 | -}else{if(v!=null||o!=null){i(aA) | |
730 | -}else{if(E!=null){Y(aA) | |
731 | -}else{if(G!=null){U(aA) | |
732 | -}else{if(Z!=null){H(aA) | |
733 | -}else{af(0,"No suspended connection available"); | |
734 | -a.util.error("No suspended connection available. Make sure atmosphere.subscribe has been called and request.onOpen invoked before invoking this method") | |
735 | -}}}}}}function n(aB,aA){if(!aA){aA=ap(aB) | |
736 | -}aA.transport="polling"; | |
737 | -aA.method="GET"; | |
738 | -aA.async=false; | |
739 | -aA.withCredentials=false; | |
740 | -aA.reconnect=false; | |
741 | -aA.force=true; | |
742 | -aA.suspend=false; | |
743 | -aA.timeout=1000; | |
744 | -s(aA) | |
745 | -}function m(aA){q.send(aA) | |
746 | -}function B(aB){if(aB.length===0){return | |
747 | -}try{if(q){q.localSend(aB) | |
748 | -}else{if(aq){aq.signal("localMessage",a.util.stringifyJSON({id:J,event:aB})) | |
749 | -}}}catch(aA){a.util.error(aA) | |
750 | -}}function i(aB){var aA=ap(aB); | |
751 | -s(aA) | |
752 | -}function Y(aB){if(O.enableXDR&&a.util.checkCORSSupport()){var aA=ap(aB); | |
753 | -aA.reconnect=false; | |
754 | -z(aA) | |
755 | -}else{i(aB) | |
756 | -}}function U(aA){i(aA) | |
757 | -}function T(aA){var aB=aA; | |
758 | -if(typeof(aB)==="object"){aB=aA.data | |
759 | -}return aB | |
760 | -}function ap(aB){var aC=T(aB); | |
761 | -var aA={connected:false,timeout:60000,method:"POST",url:O.url,contentType:O.contentType,headers:O.headers,reconnect:true,callback:null,data:aC,suspend:false,maxRequest:-1,logLevel:"info",requestCount:0,withCredentials:O.withCredentials,async:O.async,transport:"polling",isOpen:true,attachHeadersAsQueryString:true,enableXDR:O.enableXDR,uuid:O.uuid,dispatchUrl:O.dispatchUrl,enableProtocol:false,messageDelimiter:"|",maxReconnectOnClose:O.maxReconnectOnClose}; | |
762 | -if(typeof(aB)==="object"){aA=a.util.extend(aA,aB) | |
763 | -}return aA | |
764 | -}function H(aA){var aD=a.util.isBinary(aA)?aA:T(aA); | |
765 | -var aB; | |
766 | -try{if(O.dispatchUrl!=null){aB=O.webSocketPathDelimiter+O.dispatchUrl+O.webSocketPathDelimiter+aD | |
767 | -}else{aB=aD | |
768 | -}if(!Z.webSocketOpened){a.util.error("WebSocket not connected."); | |
769 | -return | |
770 | -}Z.send(aB) | |
771 | -}catch(aC){Z.onclose=function(aE){}; | |
772 | -am(); | |
773 | -Q("Websocket failed. Downgrading to Comet and resending "+aA); | |
774 | -i(aA) | |
775 | -}}function ac(aB){var aA=a.util.parseJSON(aB); | |
776 | -if(aA.id!==J){if(typeof(O.onLocalMessage)!=="undefined"){O.onLocalMessage(aA.event) | |
777 | -}else{if(typeof(a.util.onLocalMessage)!=="undefined"){a.util.onLocalMessage(aA.event) | |
778 | -}}}}function F(aD,aA,aB,aC){W.responseBody=aD; | |
779 | -W.transport=aC; | |
780 | -W.status=aB; | |
781 | -W.state=aA; | |
782 | -C() | |
783 | -}function ag(aA,aD){if(!aD.readResponsesHeaders){if(!aD.enableProtocol){aD.lastTimestamp=a.util.now(); | |
784 | -aD.uuid=J | |
785 | -}}else{try{var aC=aA.getResponseHeader("X-Cache-Date"); | |
786 | -if(aC&&aC!=null&&aC.length>0){aD.lastTimestamp=aC.split(" ").pop() | |
787 | -}var aB=aA.getResponseHeader("X-Atmosphere-tracking-id"); | |
788 | -if(aB&&aB!=null){aD.uuid=aB.split(" ").pop() | |
789 | -}}catch(aE){}}}function ab(aA){au(aA,O); | |
790 | -au(aA,a.util) | |
791 | -}function au(aB,aC){switch(aB.state){case"messageReceived":l=0; | |
792 | -if(typeof(aC.onMessage)!=="undefined"){aC.onMessage(aB) | |
793 | -}break; | |
794 | -case"error":if(typeof(aC.onError)!=="undefined"){aC.onError(aB) | |
795 | -}break; | |
796 | -case"opening":delete O.closed; | |
797 | -if(typeof(aC.onOpen)!=="undefined"){aC.onOpen(aB) | |
798 | -}break; | |
799 | -case"messagePublished":if(typeof(aC.onMessagePublished)!=="undefined"){aC.onMessagePublished(aB) | |
800 | -}break; | |
801 | -case"re-connecting":if(typeof(aC.onReconnect)!=="undefined"){aC.onReconnect(O,aB) | |
802 | -}break; | |
803 | -case"closedByClient":if(typeof(aC.onClientTimeout)!=="undefined"){aC.onClientTimeout(O) | |
804 | -}break; | |
805 | -case"re-opening":delete O.closed; | |
806 | -if(typeof(aC.onReopen)!=="undefined"){aC.onReopen(O,aB) | |
807 | -}break; | |
808 | -case"fail-to-reconnect":if(typeof(aC.onFailureToReconnect)!=="undefined"){aC.onFailureToReconnect(O,aB) | |
809 | -}break; | |
810 | -case"unsubscribe":case"closed":var aA=typeof(O.closed)!=="undefined"?O.closed:false; | |
811 | -if(typeof(aC.onClose)!=="undefined"&&!aA){aC.onClose(aB) | |
812 | -}O.closed=true; | |
813 | -break | |
814 | -}}function ai(aA){if(W.state!=="closed"){W.state="closed"; | |
815 | -W.responseBody=""; | |
816 | -W.messages=[]; | |
817 | -W.status=!aA?501:200; | |
818 | -C() | |
819 | -}}function C(){var aC=function(aF,aG){aG(W) | |
820 | -}; | |
821 | -if(q==null&&aa!=null){aa(W.responseBody) | |
822 | -}O.reconnect=O.mrequest; | |
823 | -var aA=typeof(W.responseBody)==="string"; | |
824 | -var aD=(aA&&O.trackMessageLength)?(W.messages.length>0?W.messages:[""]):new Array(W.responseBody); | |
825 | -for(var aB=0; | |
826 | -aB<aD.length; | |
827 | -aB++){if(aD.length>1&&aD[aB].length===0){continue | |
828 | -}W.responseBody=(aA)?a.util.trim(aD[aB]):aD[aB]; | |
829 | -if(q==null&&aa!=null){aa(W.responseBody) | |
830 | -}if(W.responseBody.length===0&&W.state==="messageReceived"){continue | |
831 | -}ab(W); | |
832 | -if(f.length>0){if(O.logLevel==="debug"){a.util.debug("Invoking "+f.length+" global callbacks: "+W.state) | |
833 | -}try{a.util.each(f,aC) | |
834 | -}catch(aE){a.util.log(O.logLevel,["Callback exception"+aE]) | |
835 | -}}if(typeof(O.callback)==="function"){if(O.logLevel==="debug"){a.util.debug("Invoking request callbacks") | |
836 | -}try{O.callback(W) | |
837 | -}catch(aE){a.util.log(O.logLevel,["Callback exception"+aE]) | |
838 | -}}}}this.subscribe=function(aA){ay(aA); | |
839 | -t() | |
840 | -}; | |
841 | -this.execute=function(){t() | |
842 | -}; | |
843 | -this.close=function(){an() | |
844 | -}; | |
845 | -this.disconnect=function(){D() | |
846 | -}; | |
847 | -this.getUrl=function(){return O.url | |
848 | -}; | |
849 | -this.push=function(aC,aB){if(aB!=null){var aA=O.dispatchUrl; | |
850 | -O.dispatchUrl=aB; | |
851 | -al(aC); | |
852 | -O.dispatchUrl=aA | |
853 | -}else{al(aC) | |
854 | -}}; | |
855 | -this.getUUID=function(){return O.uuid | |
856 | -}; | |
857 | -this.pushLocal=function(aA){B(aA) | |
858 | -}; | |
859 | -this.enableProtocol=function(aA){return O.enableProtocol | |
860 | -}; | |
861 | -this.request=O; | |
862 | -this.response=W | |
863 | -}}; | |
864 | -a.subscribe=function(h,k,j){if(typeof(k)==="function"){a.addCallback(k) | |
865 | -}e=0; | |
866 | -if(typeof(h)!=="string"){j=h | |
867 | -}else{j.url=h | |
868 | -}var i=new a.AtmosphereRequest(j); | |
869 | -i.execute(); | |
870 | -g[g.length]=i; | |
871 | -return i | |
872 | -}; | |
873 | -a.unsubscribe=function(){if(g.length>0){var h=[].concat(g); | |
874 | -for(var k=0; | |
875 | -k<h.length; | |
876 | -k++){var j=h[k]; | |
877 | -j.close(); | |
878 | -clearTimeout(j.response.request.id) | |
879 | -}}g=[]; | |
880 | -f=[] | |
881 | -}; | |
882 | -a.unsubscribeUrl=function(j){var h=-1; | |
883 | -if(g.length>0){for(var l=0; | |
884 | -l<g.length; | |
885 | -l++){var k=g[l]; | |
886 | -if(k.getUrl()===j){k.close(); | |
887 | -clearTimeout(k.response.request.id); | |
888 | -h=l; | |
889 | -break | |
890 | -}}}if(h>=0){g.splice(h,1) | |
891 | -}}; | |
892 | -a.addCallback=function(h){if(a.util.inArray(h,f)===-1){f.push(h) | |
893 | -}}; | |
894 | -a.removeCallback=function(i){var h=a.util.inArray(i,f); | |
895 | -if(h!==-1){f.splice(h,1) | |
896 | -}}; | |
897 | -a.util={browser:{},parseHeaders:function(i){var h,k=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,j={}; | |
898 | -while(h=k.exec(i)){j[h[1]]=h[2] | |
899 | -}return j | |
900 | -},now:function(){return new Date().getTime() | |
901 | -},isArray:function(h){return Object.prototype.toString.call(h)==="[object Array]" | |
902 | -},inArray:function(k,l){if(!Array.prototype.indexOf){var h=l.length; | |
903 | -for(var j=0; | |
904 | -j<h; | |
905 | -++j){if(l[j]===k){return j | |
906 | -}}return -1 | |
907 | -}return l.indexOf(k) | |
908 | -},isBinary:function(h){return/^\[object\s(?:Blob|ArrayBuffer|.+Array)\]$/.test(Object.prototype.toString.call(h)) | |
909 | -},isFunction:function(h){return Object.prototype.toString.call(h)==="[object Function]" | |
910 | -},getAbsoluteURL:function(h){var i=document.createElement("div"); | |
911 | -i.innerHTML='<a href="'+h+'"/>'; | |
912 | -return encodeURI(decodeURI(i.firstChild.href)) | |
913 | -},prepareURL:function(i){var j=a.util.now(); | |
914 | -var h=i.replace(/([?&])_=[^&]*/,"$1_="+j); | |
915 | -return h+(h===i?(/\?/.test(i)?"&":"?")+"_="+j:"") | |
916 | -},trim:function(h){if(!String.prototype.trim){return h.toString().replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"").replace(/\s+/g," ") | |
917 | -}else{return h.toString().trim() | |
918 | -}},param:function(l){var j,h=[]; | |
919 | -function k(m,n){n=a.util.isFunction(n)?n():(n==null?"":n); | |
920 | -h.push(encodeURIComponent(m)+"="+encodeURIComponent(n)) | |
921 | -}function i(n,o){var m; | |
922 | -if(a.util.isArray(o)){a.util.each(o,function(q,p){if(/\[\]$/.test(n)){k(n,p) | |
923 | -}else{i(n+"["+(typeof p==="object"?q:"")+"]",p) | |
924 | -}}) | |
925 | -}else{if(Object.prototype.toString.call(o)==="[object Object]"){for(m in o){i(n+"["+m+"]",o[m]) | |
926 | -}}else{k(n,o) | |
927 | -}}}for(j in l){i(j,l[j]) | |
928 | -}return h.join("&").replace(/%20/g,"+") | |
929 | -},storage:!!(window.localStorage&&window.StorageEvent),iterate:function(j,i){var k; | |
930 | -i=i||0; | |
931 | -(function h(){k=setTimeout(function(){if(j()===false){return | |
932 | -}h() | |
933 | -},i) | |
934 | -})(); | |
935 | -return function(){clearTimeout(k) | |
936 | -} | |
937 | -},each:function(n,o,j){if(!n){return | |
938 | -}var m,k=0,l=n.length,h=a.util.isArray(n); | |
939 | -if(j){if(h){for(; | |
940 | -k<l; | |
941 | -k++){m=o.apply(n[k],j); | |
942 | -if(m===false){break | |
943 | -}}}else{for(k in n){m=o.apply(n[k],j); | |
944 | -if(m===false){break | |
945 | -}}}}else{if(h){for(; | |
946 | -k<l; | |
947 | -k++){m=o.call(n[k],k,n[k]); | |
948 | -if(m===false){break | |
949 | -}}}else{for(k in n){m=o.call(n[k],k,n[k]); | |
950 | -if(m===false){break | |
951 | -}}}}return n | |
952 | -},extend:function(l){var k,j,h; | |
953 | -for(k=1; | |
954 | -k<arguments.length; | |
955 | -k++){if((j=arguments[k])!=null){for(h in j){l[h]=j[h] | |
956 | -}}}return l | |
957 | -},on:function(j,i,h){if(j.addEventListener){j.addEventListener(i,h,false) | |
958 | -}else{if(j.attachEvent){j.attachEvent("on"+i,h) | |
959 | -}}},off:function(j,i,h){if(j.removeEventListener){j.removeEventListener(i,h,false) | |
960 | -}else{if(j.detachEvent){j.detachEvent("on"+i,h) | |
961 | -}}},log:function(j,i){if(window.console){var h=window.console[j]; | |
962 | -if(typeof h==="function"){h.apply(window.console,i) | |
963 | -}}},warn:function(){a.util.log("warn",arguments) | |
964 | -},info:function(){a.util.log("info",arguments) | |
965 | -},debug:function(){a.util.log("debug",arguments) | |
966 | -},error:function(){a.util.log("error",arguments) | |
967 | -},xhr:function(){try{return new window.XMLHttpRequest() | |
968 | -}catch(i){try{return new window.ActiveXObject("Microsoft.XMLHTTP") | |
969 | -}catch(h){}}},parseJSON:function(h){return !h?null:window.JSON&&window.JSON.parse?window.JSON.parse(h):new Function("return "+h)() | |
970 | -},stringifyJSON:function(j){var m=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,k={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"}; | |
971 | -function h(n){return'"'+n.replace(m,function(o){var p=k[o]; | |
972 | -return typeof p==="string"?p:"\\u"+("0000"+o.charCodeAt(0).toString(16)).slice(-4) | |
973 | -})+'"' | |
974 | -}function i(o){return o<10?"0"+o:o | |
975 | -}return window.JSON&&window.JSON.stringify?window.JSON.stringify(j):(function l(s,r){var q,p,n,o,u=r[s],t=typeof u; | |
976 | -if(u&&typeof u==="object"&&typeof u.toJSON==="function"){u=u.toJSON(s); | |
977 | -t=typeof u | |
978 | -}switch(t){case"string":return h(u); | |
979 | -case"number":return isFinite(u)?String(u):"null"; | |
980 | -case"boolean":return String(u); | |
981 | -case"object":if(!u){return"null" | |
982 | -}switch(Object.prototype.toString.call(u)){case"[object Date]":return isFinite(u.valueOf())?'"'+u.getUTCFullYear()+"-"+i(u.getUTCMonth()+1)+"-"+i(u.getUTCDate())+"T"+i(u.getUTCHours())+":"+i(u.getUTCMinutes())+":"+i(u.getUTCSeconds())+'Z"':"null"; | |
983 | -case"[object Array]":n=u.length; | |
984 | -o=[]; | |
985 | -for(q=0; | |
986 | -q<n; | |
987 | -q++){o.push(l(q,u)||"null") | |
988 | -}return"["+o.join(",")+"]"; | |
989 | -default:o=[]; | |
990 | -for(q in u){if(b.call(u,q)){p=l(q,u); | |
991 | -if(p){o.push(h(q)+":"+p) | |
992 | -}}}return"{"+o.join(",")+"}" | |
993 | -}}})("",{"":j}) | |
994 | -},checkCORSSupport:function(){if(a.util.browser.msie&&!window.XDomainRequest){return true | |
995 | -}else{if(a.util.browser.opera&&a.util.browser.version<12){return true | |
996 | -}else{if(a.util.trim(navigator.userAgent).slice(0,16)==="KreaTVWebKit/531"){return true | |
997 | -}else{if(a.util.trim(navigator.userAgent).slice(-7).toLowerCase()==="kreatel"){return true | |
998 | -}}}}var h=navigator.userAgent.toLowerCase(); | |
999 | -var i=h.indexOf("android")>-1; | |
1000 | -if(i){return true | |
1001 | -}return false | |
1002 | -}}; | |
1003 | -d=a.util.now(); | |
1004 | -(function(){var i=navigator.userAgent.toLowerCase(),h=/(chrome)[ \/]([\w.]+)/.exec(i)||/(webkit)[ \/]([\w.]+)/.exec(i)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(i)||/(msie) ([\w.]+)/.exec(i)||/(trident)(?:.*? rv:([\w.]+)|)/.exec(i)||i.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(i)||[]; | |
1005 | -a.util.browser[h[1]||""]=true; | |
1006 | -a.util.browser.version=h[2]||"0"; | |
1007 | -if(a.util.browser.trident){a.util.browser.msie=true | |
1008 | -}if(a.util.browser.msie||(a.util.browser.mozilla&&a.util.browser.version.split(".")[0]==="1")){a.util.storage=false | |
1009 | -}})(); | |
1010 | -a.util.on(window,"unload",function(h){a.unsubscribe() | |
1011 | -}); | |
1012 | -a.util.on(window,"keypress",function(h){if(h.charCode===27||h.keyCode===27){if(h.preventDefault){h.preventDefault() | |
1013 | -}}}); | |
1014 | -a.util.on(window,"offline",function(){a.unsubscribe() | |
1015 | -}); | |
1016 | -return a | |
1017 | -})); | |
\ No newline at end of file |
@@ -62,16 +62,139 @@ | ||
62 | 62 | <script type="text/javascript" src="../javascript/atmosphere.js"></script> |
63 | 63 | <!-- Application --> |
64 | 64 | <script type="text/javascript" src="../javascript/jquery-1.9.0.js"></script> |
65 | - <script type="text/javascript" src="../javascript/application.js"></script> | |
66 | - <style> | |
67 | - * {font-family: tahoma; font-size: 12px; padding: 0px; margin: 0px;} | |
68 | - p {line-height: 18px;} | |
69 | - div {width: 500px; margin-left: auto; margin-right: auto;} | |
70 | - #content {padding: 5px; background: #ddd; border-radius: 5px; border: 1px solid #CCC; margin-top: 10px;} | |
71 | - #header {padding: 5px; background: #f5deb3; border-radius: 5px; border: 1px solid #CCC; margin-top: 10px;} | |
72 | - #input {border-radius: 2px; border: 1px solid #ccc; margin-top: 10px; padding: 5px; width: 400px;} | |
73 | - #status {width: 88px; display: block; float: left; margin-top: 15px;} | |
74 | - </style> | |
65 | + | |
66 | + <!-- chat application --> | |
67 | + <script type="text/javascript"> | |
68 | + //<![CDATA[ | |
69 | + | |
70 | +$(function () { | |
71 | + "use strict"; | |
72 | + | |
73 | + var header = $('#header'); | |
74 | + var content = $('#content'); | |
75 | + var input = $('#input'); | |
76 | + var status = $('#status'); | |
77 | + var myName = false; | |
78 | + var author = null; | |
79 | + var logged = false; | |
80 | + var socket = atmosphere; | |
81 | + var subSocket; | |
82 | + var transport = 'websocket'; | |
83 | + | |
84 | + // We are now ready to cut the request | |
85 | + var request = { url: '/moto_web_app/chat', | |
86 | + contentType : "application/json", | |
87 | + logLevel : 'debug', | |
88 | + transport : transport , | |
89 | + trackMessageLength : true, | |
90 | + reconnectInterval : 5000, | |
91 | + enableXDR: true, | |
92 | + timeout : 60000 }; | |
93 | + | |
94 | + | |
95 | + request.onOpen = function(response) { | |
96 | + content.html($('<p>', { text: 'Atmosphere connected using ' + response.transport })); | |
97 | + input.removeAttr('disabled').focus(); | |
98 | + status.text('Choose name:'); | |
99 | + transport = response.transport; | |
100 | + | |
101 | + // Carry the UUID. This is required if you want to call subscribe(request) again. | |
102 | + request.uuid = response.request.uuid; | |
103 | + }; | |
104 | + | |
105 | + request.onClientTimeout = function(r) { | |
106 | + content.html($('<p>', { text: 'Client closed the connection after a timeout. Reconnecting in ' + request.reconnectInterval })); | |
107 | + subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: 'is inactive and closed the connection. Will reconnect in ' + request.reconnectInterval })); | |
108 | + input.attr('disabled', 'disabled'); | |
109 | + setTimeout(function (){ | |
110 | + subSocket = socket.subscribe(request); | |
111 | + }, request.reconnectInterval); | |
112 | + }; | |
113 | + | |
114 | + request.onReopen = function(response) { | |
115 | + input.removeAttr('disabled').focus(); | |
116 | + content.html($('<p>', { text: 'Atmosphere re-connected using ' + response.transport })); | |
117 | + }; | |
118 | + | |
119 | + // For demonstration of how you can customize the fallbackTransport using the onTransportFailure function | |
120 | + request.onTransportFailure = function(errorMsg, request) { | |
121 | + atmosphere.util.info(errorMsg); | |
122 | + request.fallbackTransport = "long-polling"; | |
123 | + header.html($('<h3>', { text: 'Atmosphere Chat. Default transport is WebSocket, fallback is ' + request.fallbackTransport })); | |
124 | + }; | |
125 | + | |
126 | + request.onMessage = function (response) { | |
127 | + | |
128 | + var message = response.responseBody; | |
129 | + try { | |
130 | + var json = atmosphere.util.parseJSON(message); | |
131 | + } catch (e) { | |
132 | + console.log('This doesn\'t look like a valid JSON: ', message); | |
133 | + return; | |
134 | + } | |
135 | + | |
136 | + input.removeAttr('disabled').focus(); | |
137 | + if (!logged && myName) { | |
138 | + logged = true; | |
139 | + status.text(myName + ': ').css('color', 'blue'); | |
140 | + } else { | |
141 | + var me = json.author == author; | |
142 | + var date = typeof(json.time) == 'string' ? parseInt(json.time) : json.time; | |
143 | + addMessage(json.author, json.message, me ? 'blue' : 'black', new Date(date)); | |
144 | + } | |
145 | + }; | |
146 | + | |
147 | + request.onClose = function(response) { | |
148 | + content.html($('<p>', { text: 'Server closed the connection after a timeout' })); | |
149 | + if (subSocket) { | |
150 | + subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: 'disconnecting' })); | |
151 | + } | |
152 | + input.attr('disabled', 'disabled'); | |
153 | + }; | |
154 | + | |
155 | + request.onError = function(response) { | |
156 | + content.html($('<p>', { text: 'Sorry, but there\'s some problem with your ' | |
157 | + + 'socket or the server is down' })); | |
158 | + logged = false; | |
159 | + }; | |
160 | + | |
161 | + request.onReconnect = function(request, response) { | |
162 | + content.html($('<p>', { text: 'Connection lost, trying to reconnect. Trying to reconnect ' + request.reconnectInterval})); | |
163 | + input.attr('disabled', 'disabled'); | |
164 | + }; | |
165 | + | |
166 | + subSocket = socket.subscribe(request); | |
167 | + | |
168 | + input.keydown(function(e) { | |
169 | + if (e.keyCode === 13) { | |
170 | + var msg = $(this).val(); | |
171 | + | |
172 | + // First message is always the author's name | |
173 | + if (author == null) { | |
174 | + author = msg; | |
175 | + } | |
176 | + | |
177 | + subSocket.push(atmosphere.util.stringifyJSON({ author: author, message: msg })); | |
178 | + $(this).val(''); | |
179 | + | |
180 | + input.attr('disabled', 'disabled'); | |
181 | + if (myName === false) { | |
182 | + myName = msg; | |
183 | + } | |
184 | + } | |
185 | + }); | |
186 | + | |
187 | + function addMessage(author, message, color, datetime) { | |
188 | + content.append('<p><span style="color:' + color + '">' + author + '</span> @ ' + | |
189 | + + (datetime.getHours() < 10 ? '0' + datetime.getHours() : datetime.getHours()) + ':' | |
190 | + + (datetime.getMinutes() < 10 ? '0' + datetime.getMinutes() : datetime.getMinutes()) | |
191 | + + ': ' + message + '</p>'); | |
192 | + } | |
193 | +}); | |
194 | + | |
195 | + //]]> | |
196 | + </script> | |
197 | + | |
75 | 198 | |
76 | 199 | </ui:define> |
77 | 200 |