Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/node-red/node_modules/tiny-lr/lib/ drwxr-xr-x | |
| Viewing file: Select action/file-type: import events from 'events';
import WebSocket from 'faye-websocket';
import objectAssign from 'object-assign';
const debug = require('debug')('tinylr:client');
let idCounter = 0;
export default class Client extends events.EventEmitter {
constructor (req, socket, head, options = {}) {
super();
this.options = options;
this.ws = new WebSocket(req, socket, head);
this.ws.onmessage = this.message.bind(this);
this.ws.onclose = this.close.bind(this);
this.id = this.uniqueId('ws');
}
message (event) {
let data = this.data(event);
if (this[data.command]) return this[data.command](data);
}
close (event) {
if (this.ws) {
this.ws.close();
this.ws = null;
}
this.emit('end', event);
}
// Commands
hello () {
this.send({
command: 'hello',
protocols: [
'http://livereload.com/protocols/official-7'
],
serverName: 'tiny-lr'
});
}
info (data) {
if (data) {
debug('Info', data);
this.emit('info', objectAssign({}, data, { id: this.id }));
this.plugins = data.plugins;
this.url = data.url;
}
return objectAssign({}, data || {}, { id: this.id, url: this.url });
}
// Server commands
reload (files) {
files.forEach(function (file) {
this.send({
command: 'reload',
path: file,
liveCSS: this.options.liveCSS !== false,
reloadMissingCSS: this.options.reloadMissingCSS !== false,
liveImg: this.options.liveImg !== false
});
}, this);
}
alert (message) {
this.send({
command: 'alert',
message: message
});
}
// Utilities
data (event) {
let data = {};
try {
data = JSON.parse(event.data);
} catch (e) {}
return data;
}
send (data) {
if (!this.ws) return;
this.ws.send(JSON.stringify(data));
}
uniqueId (prefix) {
let id = idCounter++;
return prefix ? prefix + id : id;
}
}
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0049 ]-- |