{"id":1540,"date":"2019-11-05T19:24:10","date_gmt":"2019-11-05T22:24:10","guid":{"rendered":"http:\/\/www.l2maker.com.br\/documentacao\/?p=1540"},"modified":"2020-02-17T13:48:16","modified_gmt":"2020-02-17T16:48:16","slug":"testando-a-comunicacao-com-o-websocket","status":"publish","type":"post","link":"https:\/\/www.l2maker.com.br\/documentacao\/2019\/11\/testando-a-comunicacao-com-o-websocket\/","title":{"rendered":"Testando a comunica\u00e7\u00e3o com o WebSocket"},"content":{"rendered":"<p>Verifique abaixo se o plugin foi instalado no Webrun e est\u00e1 recebendo mensagens:<\/p>\n<p>Informe a URL do seu Webrun: <input id=\"websocket_url\" name=\"websocket_url\" size=\"70\" type=\"text\" placeholder=\"EXEMPLO: ws:\/\/localhost:8049\/webrunstudio\/wppplugin-ws\"><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>Exemplos:<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li>ws:\/\/localhost:8049\/webrunstudio\/wppplugin-ws<\/li>\n<li>ws:\/\/localhost:8036\/webrun\/wppplugin-ws<\/li>\n<\/ul>\n<p>Informe o n\u00famero do telefone: <input id=\"websocket_telefone\" name=\"websocket_telefone\" size=\"14\" type=\"text\" placeholder=\"55 + DDD + N\u00famero\"><\/p>\n<p>Clique em testar: <input id=\"websocket_testar\" type=\"button\" value=\"Testar\"><br \/>\n<script>function wsTeste() {\r\n  var telNumero = document.getElementById(\"websocket_telefone\").value;\r\n  var wsURL = document.getElementById(\"websocket_url\").value;\/\/'ws:\/\/127.0.0.1:8088\/webrun39\/wppplugin-ws';\r\nif(!wsURL) {\r\n  alert('Informe a URL do WebSocket.');\r\n  return;\r\n }\r\n if(!telNumero) {\r\n  alert('Informe o n\u00famero do telefone.');\r\n  return;\r\n }\r\n  var ws = new WebSocket(wsURL);\r\n  ws.onerror = function(event) {\r\n\talert('Erro na chamada do WebSocket.');\r\n\tconsole.error(\"WebSocket error observed:\", event);\r\n  }\r\n\r\n  ws.onopen = function(msg) {\r\n\tconsole.log('APPBOT - CONECTADO.');\r\n\tconsole.log('APPBOT - Enviando PING...');\r\n\tws.send(JSON.stringify({\"type\":\"ping\", \"number\": telNumero }));\r\n  };\r\n\r\n  ws.onmessage = function(event) {\r\n    console.debug(\"WebSocket message received:\", event.data);\r\n    alert('Resposta do WebSocket recebida. API instalada.');\r\n  };\r\n}\r\n\r\ndocument.getElementById(\"websocket_testar\").addEventListener('click', wsTeste);\r\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Verifique abaixo se o plugin foi instalado no Webrun e est\u00e1 recebendo mensagens: Informe a URL do seu Webrun: Exemplos: &nbsp; ws:\/\/localhost:8049\/webrunstudio\/wppplugin-ws ws:\/\/localhost:8036\/webrun\/wppplugin-ws Informe o n\u00famero do telefone: Clique em testar:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1540","post","type-post","status-publish","format-standard","hentry","category-sem-categoria"],"_links":{"self":[{"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/posts\/1540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/comments?post=1540"}],"version-history":[{"count":17,"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/posts\/1540\/revisions"}],"predecessor-version":[{"id":1734,"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/posts\/1540\/revisions\/1734"}],"wp:attachment":[{"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/media?parent=1540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/categories?post=1540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.l2maker.com.br\/documentacao\/wp-json\/wp\/v2\/tags?post=1540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}