Web-1/Websockets/Nodered-websockets-test

Uit Inf2019
< Web-1‎ | Websockets
Versie door Eelco (overleg | bijdragen) op 8 nov 2017 om 08:24 (Nieuwe pagina aangemaakt met '<syntaxhighlight lang=json> [{"id":"5c2733ba.69e9cc","type":"tab","label":"Websockets test","disabled":false,"info":""},{"id":"e604a345.718a3","type":"inject","z":"...')
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
Naar navigatie springen Naar zoeken springen
[{"id":"5c2733ba.69e9cc","type":"tab","label":"Websockets test","disabled":false,"info":""},{"id":"e604a345.718a3","type":"inject","z":"5c2733ba.69e9cc","name":"","topic":"","payload":"Server: Hello world!","payloadType":"str","repeat":"","crontab":"","once":false,"x":247,"y":179,"wires":[["9d6cf5b3.240428"]]},{"id":"f1aa2d8c.5b27f","type":"websocket in","z":"5c2733ba.69e9cc","name":"","server":"d1c4a3ad.621f","client":"","x":230,"y":240,"wires":[["9d6cf5b3.240428","cd015ac5.5e5148"]]},{"id":"cd015ac5.5e5148","type":"debug","z":"5c2733ba.69e9cc","name":"","active":true,"console":"false","complete":"false","x":450,"y":292,"wires":[]},{"id":"e93debae.902a98","type":"websocket out","z":"5c2733ba.69e9cc","name":"","server":"d1c4a3ad.621f","client":"","x":650,"y":240,"wires":[]},{"id":"e7381d01.a59c7","type":"http in","z":"5c2733ba.69e9cc","name":"","url":"/ws-test","method":"get","upload":false,"swaggerDoc":"","x":109,"y":382,"wires":[["68725cba.5e3454"]]},{"id":"80a5546a.229048","type":"http response","z":"5c2733ba.69e9cc","name":"","statusCode":"","headers":{},"x":764,"y":383,"wires":[]},{"id":"fd6119c8.7a3178","type":"template","z":"5c2733ba.69e9cc","name":"html","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<html>\n  <head>\n\t<title>Websockets test</title>\n  </head>\n  <body>\n    <h3>Websockets test</h3>\n    <p>Welcome {{user}}!</p>\n    <button id=\"hibutton\">Click to send hello</button>\n    <div id=\"logdiv\">{{{chatlog}}}</div>\n    <script>\n        {{{myscript}}}\n    </script>\n  </body>\n</html>\n","output":"str","x":613,"y":383,"wires":[["80a5546a.229048"]]},{"id":"fb988c45.8e29e","type":"template","z":"5c2733ba.69e9cc","name":"myscript","field":"myscript","fieldType":"msg","format":"javascript","syntax":"mustache","template":"var socket = new WebSocket(\"wss://\" + location.host + \"/ws/test\");\nvar logdiv = document.getElementById(\"logdiv\");     \nvar hiButton = document.getElementById(\"hibutton\");\n\nsocket.onopen = function (event) {\n  logdiv.innerHTML = logdiv.innerHTML + \"<p>[socket open]</p>\";    \n};\n\nsocket.onmessage = function (event) {\n  logdiv.innerHTML = logdiv.innerHTML + (\"<p>\" + event.data + \"</p>\");\n};\n\nhiButton.onclick = function () {\n    socket.send(\"{{user}}: Hi\");\n}","output":"str","x":456,"y":382,"wires":[["fd6119c8.7a3178"]]},{"id":"30af5bdc.bc1d74","type":"comment","z":"5c2733ba.69e9cc","name":"websockets test","info":"## Websockets\n\nThis example shows an echo application for websockets:\nthe client may send and receive; what it sends, is again received.\n","x":124.5,"y":474,"wires":[]},{"id":"9d6cf5b3.240428","type":"function","z":"5c2733ba.69e9cc","name":"kill session","func":"delete msg._session;\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":240,"wires":[["e93debae.902a98"]]},{"id":"68725cba.5e3454","type":"function","z":"5c2733ba.69e9cc","name":"get-name","func":"function newName () {\n  var names = [\"Ad\", \"Bea\", \"Carel\", \"Diana\", \n    \"Eef\", \"Fien\", \"Gerard\", \"Hannie\", \"Iza\", \"Jo\"];\n  var index = context.get(\"index\") || 0;\n  context.set(\"index\", (index + 1) % 10);\n  return names[ index ];\n}\n\nvar user = msg.req.cookies[\"user\"] || \"\";\nif (user === \"\") {\n  user = newName();\n}\n\nmsg.user = user;\nmsg.cookies = {user: user};\nreturn msg;","outputs":1,"noerr":0,"x":285,"y":382,"wires":[["fb988c45.8e29e"]]},{"id":"d1c4a3ad.621f","type":"websocket-listener","z":"","path":"/ws/test","wholemsg":"false"}]