|
24 | 24 | #include "lwan.h"
|
25 | 25 | #include "lwan-pubsub.h"
|
26 | 26 |
|
| 27 | +#include "websocket-sample.h" |
| 28 | + |
27 | 29 | static struct lwan_pubsub_topic *chat;
|
28 | 30 |
|
29 | 31 | /* This is a write-only sample of the API: it just sends random integers
|
@@ -197,116 +199,10 @@ LWAN_HANDLER_ROUTE(ws_chat, "/ws-chat")
|
197 | 199 |
|
198 | 200 | LWAN_HANDLER_ROUTE(index, "/")
|
199 | 201 | {
|
200 |
| - static const char message[] = |
201 |
| - "<html>\n" |
202 |
| - " <head>\n" |
203 |
| - " <script type=\"text/javascript\">\n" |
204 |
| - " write_sock = new " |
205 |
| - "WebSocket(\"ws://localhost:8080/ws-write\")\n" |
206 |
| - " write_sock.onmessage = function (event) {\n" |
207 |
| - " document.getElementById(\"write-output\").innerText = " |
208 |
| - "event.data;\n" |
209 |
| - " }\n" |
210 |
| - " write_sock.onerror = function(event) {\n" |
211 |
| - " document.getElementById(\"write-output\").innerText = " |
212 |
| - "\"Disconnected\";\n" |
213 |
| - " " |
214 |
| - "document.getElementById(\"write-output\").style.background = " |
215 |
| - "\"red\";\n" |
216 |
| - " }\n" |
217 |
| - " write_sock.onopen = function(event) {\n" |
218 |
| - " " |
219 |
| - "document.getElementById(\"write-output\").style.background = " |
220 |
| - "\"blue\";\n" |
221 |
| - " }\n" |
222 |
| - " read_sock = new " |
223 |
| - "WebSocket(\"ws://localhost:8080/ws-read\")\n" |
224 |
| - " read_sock.onmessage = function (event) {\n" |
225 |
| - " document.getElementById(\"read-output\").innerText = " |
226 |
| - "event.data;\n" |
227 |
| - " }\n" |
228 |
| - " read_sock.onopen = function(event) {\n" |
229 |
| - " document.getElementById(\"read-button\").disabled = " |
230 |
| - "false;\n" |
231 |
| - " document.getElementById(\"read-input\").disabled = " |
232 |
| - "false;\n" |
233 |
| - " " |
234 |
| - "document.getElementById(\"read-output\").style.background = " |
235 |
| - "\"blue\";\n" |
236 |
| - " document.getElementById(\"read-output\").innerText = " |
237 |
| - "\"\";\n" |
238 |
| - " }\n" |
239 |
| - " read_sock.onerror = function(event) {\n" |
240 |
| - " document.getElementById(\"read-button\").disabled = " |
241 |
| - "true;\n" |
242 |
| - " document.getElementById(\"read-input\").disabled = " |
243 |
| - "true;\n" |
244 |
| - " document.getElementById(\"read-output\").innerText = " |
245 |
| - "\"Disconnected\";\n" |
246 |
| - " " |
247 |
| - "document.getElementById(\"read-output\").style.background = \"red\";\n" |
248 |
| - " }\n" |
249 |
| - " send_to_read_sock = function() {\n" |
250 |
| - " " |
251 |
| - "read_sock.send(document.getElementById(\"read-input\").value);\n" |
252 |
| - " }\n" |
253 |
| - " chat_sock = new " |
254 |
| - "WebSocket(\"ws://localhost:8080/ws-chat\")\n" |
255 |
| - " chat_sock.onopen = function(event) {\n" |
256 |
| - " document.getElementById(\"chat-button\").disabled = " |
257 |
| - "false;\n" |
258 |
| - " document.getElementById(\"chat-input\").disabled = " |
259 |
| - "false;\n" |
260 |
| - " " |
261 |
| - "document.getElementById(\"chat-textarea\").style.background = " |
262 |
| - "\"blue\";\n" |
263 |
| - " document.getElementById(\"chat-input\").innerText = " |
264 |
| - "\"\";\n" |
265 |
| - " }\n" |
266 |
| - " chat_sock.onerror = function(event) {\n" |
267 |
| - " document.getElementById(\"chat-button\").disabled = " |
268 |
| - "true;\n" |
269 |
| - " document.getElementById(\"chat-input\").disabled = " |
270 |
| - "true;\n" |
271 |
| - " document.getElementById(\"chat-input\").innerText = " |
272 |
| - "\"Disconnected\";\n" |
273 |
| - " " |
274 |
| - "document.getElementById(\"chat-textarea\").style.background = " |
275 |
| - "\"red\";\n" |
276 |
| - " }\n" |
277 |
| - " chat_sock.onmessage = function (event) {\n" |
278 |
| - " document.getElementById(\"chat-textarea\").value += " |
279 |
| - "event.data;\n" |
280 |
| - " }\n" |
281 |
| - " send_chat_msg = function() {\n" |
282 |
| - " " |
283 |
| - "chat_sock.send(document.getElementById(\"chat-input\").value);\n" |
284 |
| - " document.getElementById(\"chat-input\").value = \"\";\n" |
285 |
| - " }\n" |
286 |
| - " </script>\n" |
287 |
| - " </head>\n" |
288 |
| - " <body>\n" |
289 |
| - " <h1>Lwan WebSocket demo!</h1>\n" |
290 |
| - " <h2>Send-only sample: server is writing this " |
291 |
| - "continuously:</h2>\n" |
292 |
| - " <p><div id=\"write-output\" style=\"background: red; color: " |
293 |
| - "yellow\">Disconnected</div></p>\n" |
294 |
| - " <h2>Echo server sample:</h2>\n" |
295 |
| - " <p><input id=\"read-input\" disabled><button disabled " |
296 |
| - "id=\"read-button\" onclick=\"send_to_read_sock()\">Send</button></p>\n" |
297 |
| - " <p>Server said this: <div id=\"read-output\" " |
298 |
| - "style=\"background: red; color: yellow\">Disconnected</div></p>\n" |
299 |
| - " <h3>Chat sample:</h3>\n" |
300 |
| - " Send message: <input id=\"chat-input\" disabled><button " |
301 |
| - "disabled id=\"chat-button\" " |
302 |
| - "onclick=\"send_chat_msg()\">Send</button></p>\n" |
303 |
| - " <textarea id=\"chat-textarea\" rows=\"20\" cols=\"120\" " |
304 |
| - "style=\"color: yellow; background-color: red\"></textarea>\n" |
305 |
| - " </body>\n" |
306 |
| - "</html>"; |
307 |
| - |
308 | 202 | request->response.mime_type = "text/html";
|
309 |
| - lwan_strbuf_set_static(response->buffer, message, sizeof(message) - 1); |
| 203 | + lwan_strbuf_set_static(response->buffer, |
| 204 | + index_html_value.value, |
| 205 | + index_html_value.len); |
310 | 206 |
|
311 | 207 | return HTTP_OK;
|
312 | 208 | }
|
|
0 commit comments