comparison lib/js/urweb.js @ 668:b0c1a46b1f15

First message send delivered, but not interpreted
author Adam Chlipala <adamc@hcoop.net>
date Sun, 22 Mar 2009 15:05:07 -0400
parents a93d5324f400
children f68eee90dbcf
comparison
equal deleted inserted replaced
667:a93d5324f400 668:b0c1a46b1f15
131 function cr(n) { 131 function cr(n) {
132 return closures[n](); 132 return closures[n]();
133 } 133 }
134 134
135 135
136 function getXHR() 136 var client_id = 0;
137 var client_pass = 0;
138 var url_prefix = "/";
139
140 function getXHR(uri)
137 { 141 {
138 try { 142 try {
139 return new XMLHttpRequest(); 143 return new XMLHttpRequest();
140 } catch (e) { 144 } catch (e) {
141 try { 145 try {
148 } 152 }
149 } 153 }
150 } 154 }
151 } 155 }
152 156
157 function requestUri(xhr, uri) {
158 xhr.open("GET", uri, true);
159
160 if (client_id != 0) {
161 xhr.setRequestHeader("UrWeb-Client", client_id.toString());
162 xhr.setRequestHeader("UrWeb-Pass", client_pass.toString());
163 }
164
165 xhr.send(null);
166 }
167
153 function rc(uri, parse, k) { 168 function rc(uri, parse, k) {
154 var xhr = getXHR(); 169 var xhr = getXHR();
155 170
156 xhr.onreadystatechange = function() { 171 xhr.onreadystatechange = function() {
157 if (xhr.readyState == 4) { 172 if (xhr.readyState == 4) {
169 throw "Error querying remote server!"; 184 throw "Error querying remote server!";
170 } 185 }
171 } 186 }
172 }; 187 };
173 188
174 xhr.open("GET", uri, true); 189 requestUri(xhr, uri);
175 xhr.send(null); 190 }
176 } 191
177
178
179 var client_id = 0;
180 var client_pass = 0;
181 var url_prefix = "/";
182 192
183 function path_join(s1, s2) { 193 function path_join(s1, s2) {
184 if (s1.length > 0 && s1[s1.length-1] == '/') 194 if (s1.length > 0 && s1[s1.length-1] == '/')
185 return s1 + s2; 195 return s1 + s2;
186 else 196 else
187 return s1 + "/" + s2; 197 return s1 + "/" + s2;
188 } 198 }
189 199
190 function listener() { 200 function listener() {
201 var uri = path_join(url_prefix, ".msgs");
191 var xhr = getXHR(); 202 var xhr = getXHR();
192 203
193 xhr.onreadystatechange = function() { 204 xhr.onreadystatechange = function() {
194 if (xhr.readyState == 4) { 205 if (xhr.readyState == 4) {
195 var isok = false; 206 var isok = false;
197 try { 208 try {
198 if (xhr.status == 200) 209 if (xhr.status == 200)
199 isok = true; 210 isok = true;
200 } catch (e) { } 211 } catch (e) { }
201 212
202 if (isok) 213 if (isok) {
203 alert("Messages: " + xhr.responseText); 214 alert("Messages: " + xhr.responseText);
215 requestUri(xhr, uri);
216 }
204 else { 217 else {
205 alert("Error querying remote server for messages!"); 218 alert("Error querying remote server for messages!");
206 throw "Error querying remote server for messages!"; 219 throw "Error querying remote server for messages!";
207 } 220 }
208 } 221 }
209 }; 222 };
210 223
211 xhr.open("GET", path_join(url_prefix, ".msgs/" + client_id + "/" + client_pass), true); 224 requestUri(xhr, uri);
212 xhr.send(null); 225 }
213 }