Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.state = 0;
this.parse = {state: 0};
this.packet = 1;
if (dictionary.timeout)
this.timeout = dictionary.timeout;
if (this.path) {
// presence of this.path triggers WebSockets mode, as MQTT has no native concept of path
const port = dictionary.port ? dictionary.port : 80;
if (dictionary.Socket)
this.ws = new WSClient({host: dictionary.host, port, path, protocol: "mqtt", Socket: dictionary.Socket, secure: dictionary.secure});
else
this.ws = new WSClient({host: dictionary.host, port, path, protocol: "mqtt"});
this.ws.callback = ws_callback.bind(this);
} else {
const port = dictionary.port ? dictionary.port : 1883;
if (dictionary.Socket)
this.ws = new (dictionary.Socket)({host: dictionary.host, port, secure: dictionary.secure});
else
this.ws = new Socket({host: dictionary.host, port});
this.ws.callback = socket_callback.bind(this);
}
}
publish(topic, data) {
onCreate(application) {
this.ws = new Client({host: "192.168.4.1"});
this.ws.callback = function(message, value)
{
switch (message) {
case 1:
trace("socket connect\n");
break;
case 2:
trace("websocket handshake success\n");
break;
case 3:
trace(`websocket message received: ${value}\n`);
break;
case 4:
* Copyright (c) 2016-2019 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK.
*
* This work is licensed under the
* Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit
* .
* or send a letter to Creative Commons, PO Box 1866,
* Mountain View, CA 94042, USA.
*
*/
import {Client} from "websocket"
let ws = new Client({host: "echo.websocket.org"});
ws.callback = function(message, value) {
switch (message) {
case Client.connect:
trace("socket connect\n");
break;
case Client.handshake:
trace("websocket handshake success\n");
this.write(JSON.stringify({count: 1, toggle: true}));
break;
case Client.receive:
trace(`websocket message received: ${value}\n`);
value = JSON.parse(value);
value.count += 1;