---
title: WebSocket
project: Total.js V5
version: 0.0.20
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/total-js-v5/0-0-20/reference/websockets/
updated: 2026-11-19T16:17:12.159Z
---

# WebSocket

> L'oggetto WebSocket, i suoi client, WEBSOCKETCLIENT() e la configurazione WebSocket.

Metodi, proprietà ed eventi delle route WebSocket (`ROUTE('SOCKET ...')`), dell'oggetto WebSocket, dei suoi client, di `WEBSOCKETCLIENT()` e delle chiavi di configurazione `$ws*`. Per un'introduzione con esempi leggi la guida [WebSocket](../../guides/websockets/).

## API

### ROUTE('SOCKET /url/ [@flags] [#middleware] [<size]', action, [size])

Type: `method`

Registra una route WebSocket.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | Metodo, percorso, flag e middleware |
| `action` | `Function` | yes |  | Chiamata con l'oggetto WebSocket |
| `size` | `Number` | no | `CONF.$wsmaxsize * 1024` | Dimensione massima di un messaggio in byte |

Returns: `Route` La route registrata

L'azione viene eseguita una volta per URL, quando si connette il primo client, con l'oggetto WebSocket come `this` e come primo argomento. Metti davanti al metodo `+` (solo utenti autorizzati) o `-` (solo anonimi). Flag: `@json` (predefinito), `@text`, `@binary` (i messaggi sono oggetti `Buffer` e vengono inviati come frame binari, anche quando sono compressi) e `@csrf`. Un client che l'autorizzazione rifiuta (non corrisponde a `+` o `-`) viene accettato e poi chiuso con il codice `4001`. `#name` esegue un middleware prima dell'upgrade. Il limite di dimensione è `CONF.$wsmaxsize` kB, a meno che tu non passi `size` in byte o `<NMB` nell'URL. Restituisce la route.

Example: Chat room
```js
exports.install = function() {
	ROUTE('SOCKET /room/{name}/', room);
};

function room() {
	var self = this;
	self.on('message', function(client, message) {
		self.send(message);
	});
}
```

Example: Utenti autorizzati, messaggi di testo, 1 MB
```js
ROUTE('+SOCKET /console/ @text <1MB', terminal);
```

Example: Messaggi binari
```js
ROUTE('SOCKET /files/ @binary', function($) {
	$.on('message', function(client, buffer) {
		client.send(buffer); // a binary frame back
	});
});
```

### CONF.$wsmaxsize

Type: `config`

Dimensione massima predefinita di un messaggio WebSocket in kB.

Returns: `Number`

Predefinito `256`. Un messaggio più grande chiude il client con il codice `1009`. Una route può impostare la propria dimensione.

Example: file di configurazione
```js
$wsmaxsize		: 512
```

### CONF.$wscompress

Type: `config`

Consente la compressione `permessage-deflate`.

Returns: `Boolean`

Predefinito `true`. Quando il browser offre `permessage-deflate`, i messaggi vengono compressi in entrambe le direzioni.

Example: Disattivare la compressione
```js
$wscompress	   : false
```

### CONF.$wsencodedecode

Type: `config`

Codifica e decodifica tutti i messaggi WebSocket con la codifica URI.

Returns: `Boolean`

Predefinito `false`. Con `true`, i messaggi in uscita e i motivi di chiusura passano attraverso `encodeURIComponent()` e quelli in arrivo attraverso `decodeURIComponent()`. L'altra parte deve fare lo stesso.

Example: file di configurazione
```js
$wsencodedecode   : true
```

### CONF.$wsmaxlatency

Type: `config`

Latenza massima in ms prima che il controllo del ping chiuda un client.

Returns: `Number`

Predefinito `2000`. Tre volte al minuto (a 15, 30 e 60 secondi di ogni minuto) il framework invia un ping a tutti i client di tutte le route WebSocket e misura `client.latency` dal pong. Prima di ogni ping controlla i client: un client che non ha risposto al ping precedente, o la cui latenza è superiore a `CONF.$wsmaxlatency` (2000 ms), viene chiuso. In questo modo le connessioni morte vengono rimosse senza codice da parte tua.

Example: file di configurazione
```js
$wsmaxlatency	 : 5000
```

### function() { var websocket = this; }

Type: `class`

L'oggetto che raggruppa tutti i client di un URL WebSocket.

Returns: `WebSocket`

È `this` nell'azione di una route `SOCKET`. Esiste un oggetto per URL: una route dinamica ne ha uno per ogni URL distinto. È un event emitter (`on`, `once`, `emit`, `off`).

Example: Eventi
```js
function live() {
	var self = this;
	self.on('open', function(client) {});
	self.on('message', function(client, message) {});
	self.on('close', function(client) {});
}
```

### websocket.online

Type: `property`

Il numero di client connessi.

Returns: `Number`

Example: Conteggio
```js
self.on('open', function() {
	self.send({ type: 'online', count: self.online });
});
```

### websocket.connections

Type: `property`

I client connessi come oggetto `{ id: client }`.

Returns: `Object`

Example: Iterare
```js
for (var id in self.connections) {
	var client = self.connections[id];
}
```

### websocket.params

Type: `property`

I parametri dinamici dell'URL.

Returns: `Object`

Ricavato dal primo client dell'URL; tutti i client dell'oggetto condividono gli stessi valori.

Example: Nome della stanza
```js
ROUTE('SOCKET /room/{name}/', function() {
	var name = this.params.name;
});
```

### websocket.url

Type: `property`

L'URL del gruppo in minuscolo.

Returns: `String`

### websocket.send(message, [comparer], [replacer], [params])

Type: `method`

Invia un messaggio a tutti i client, o ai client scelti da un comparer.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `message` | `Object|String|Buffer` | yes |  | Il messaggio |
| `comparer` | `Function` | no |  | `function(client, message, params)` che restituisce un booleano |
| `replacer` | `Function` | no |  | Un replacer JSON |
| `params` | `Object` | no |  | Passato al comparer |

Returns: `WebSocket` Lo stesso oggetto

Il messaggio viene serializzato con `JSON.stringify()` una sola volta (per le route `@json` e `@text`); sulle route `@binary` passa un `Buffer`. `comparer(client, message, params)` restituisce `true` per i client che lo ricevono. `replacer` viene passato a `JSON.stringify()`; quando il terzo argomento non è una funzione, viene usato come `params`.

Example: Tutti
```js
self.send({ type: 'refresh' });
```

Example: Solo gli admin
```js
self.send({ type: 'alert' }, function(client) {
	return client.user && client.user.isadmin;
});
```

### websocket.find(fn)

Type: `method`

Trova il primo client per cui `fn(client)` restituisce `true`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fn` | `Function` | yes |  | `function(client)` che restituisce un booleano |

Returns: `Controller` Il client, oppure `undefined`

Example: Per utente
```js
var client = self.find(function(client) {
	return client.user && client.user.id === id;
});
```

### websocket.close([code], [message])

Type: `method`

Chiude tutti i client.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `code` | `Number` | no | `1000` | Il codice di chiusura |
| `message` | `String` | no |  | Il motivo della chiusura |

Returns: `WebSocket`

L'oggetto WebSocket rimane, quindi nuovi client possono connettersi.

Example: Chiudere tutti
```js
self.close(4000, 'Maintenance');
```

### websocket.destroy()

Type: `method`

Chiude tutti i client e rimuove l'oggetto WebSocket.

Emette `destroy`. Il client successivo che si connette all'URL esegue di nuovo l'azione della route e ottiene un nuovo oggetto.

Example: Distruggere
```js
self.destroy();
```

### websocket.autodestroy([callback])

Type: `method`

Distrugge l'oggetto 5 secondi dopo che l'ultimo client se ne va.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | Chiamata prima che l'oggetto venga distrutto |

Returns: `WebSocket`

Se un client si connette in quei 5 secondi, l'oggetto rimane. Prima della distruzione, ogni `callback` viene chiamata con l'oggetto WebSocket come `this`. Chiamalo più volte per aggiungere altre callback.

Example: Fermare un timer
```js
var timer = setInterval(function() {
	self.send({ ts: Date.now() });
}, 1000);

self.autodestroy(function() {
	clearInterval(timer);
});
```

### websocket.encrypt([enable])

Type: `method`

Cifra e decifra tutti i messaggi del gruppo con `CONF.secret_encryption`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `enable` | `Boolean` | no | `true` |  |

Senza argomenti o con `true` attiva la cifratura; `false` la disattiva. Non fa nulla finché `CONF.secret_encryption` è vuoto.

Example: Attivare
```js
function secure() {
	this.encrypt();
}
```

### websocket.ping()

Type: `method`

Invia un ping a tutti i client.

Returns: `WebSocket`

Ogni pong imposta `client.latency`. Il framework lo chiama tre volte al minuto (a 15, 30 e 60 secondi di ogni minuto) per tutti gli oggetti WebSocket.

Example: Ping immediato
```js
self.ping();
```

### websocket.error(err)

Type: `method`

Registra un errore con l'URL del WebSocket.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `err` | `Error|String` | yes |  |  |

Una stringa viene convertita in un `Error`. L'errore finisce nel log degli errori del framework.

Example: Log
```js
self.on('message', function(client, message) {
	if (!message.type)
		self.error('Missing type');
});
```

### websocket.on('open', function(client) {})

Type: `event`

Un client si è connesso.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `client` | `Controller` | yes |  | Il nuovo client |

Example: Benvenuto
```js
self.on('open', function(client) {
	client.send({ type: 'welcome' });
});
```

### websocket.on('message', function(client, message, size) {})

Type: `event`

Un client ha inviato un messaggio.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `client` | `Controller` | yes |  |  |
| `message` | `Object|String|Buffer` | yes |  |  |
| `size` | `Number` | yes |  |  |

Sulle route `@json` `message` è un oggetto analizzato; sulle route `@text` una stringa; sulle route `@binary` un `Buffer`. `size` è la dimensione in byte.

Example: Echo
```js
self.on('message', function(client, message) {
	client.send(message);
});
```

### websocket.on('close', function(client, code, message) {})

Type: `event`

Un client si è disconnesso.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `client` | `Controller` | yes |  |  |
| `code` | `Number` | yes |  |  |
| `message` | `String` | yes |  |  |

`code` e `message` sono il codice e il motivo di chiusura inviati dal client, oppure quelli passati a `close()` quando è il server a chiudere la connessione.

Example: Uscita
```js
self.on('close', function(client) {
	self.send({ type: 'left', id: client.id });
});
```

### websocket.on('error', function(err, client) {})

Type: `event`

Un errore sul socket di un client.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `err` | `Error` | yes |  |  |
| `client` | `Controller` | yes |  |  |

I reset della connessione e le pipe interrotte non lo emettono; chiudono il client. Un errore durante la compressione o la decompressione di un messaggio (`permessage-deflate`) viene emesso qui insieme al client.

Example: Log
```js
self.on('error', function(err, client) {
	self.error(err);
});
```

### websocket.on('destroy', function() {})

Type: `event`

L'oggetto WebSocket sta per essere distrutto.

Emesso da `destroy()` e `autodestroy()`.

Example: Pulizia
```js
self.on('destroy', function() {
	clearInterval(timer);
});
```

### ON('websocket_end', function(websocket, client) {})

Type: `event`

Un qualsiasi client di una qualsiasi route WebSocket si è disconnesso.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `websocket` | `WebSocket` | yes |  |  |
| `client` | `Controller` | yes |  |  |

Example: Log globale
```js
ON('websocket_end', function(websocket, client) {
	console.log(websocket.url, client.ip);
});
```

### client

Type: `class`

Un client connesso a una route WebSocket.

I client arrivano negli eventi dell'oggetto WebSocket. Hanno i dati della richiesta di upgrade: `id`, `ip`, `user`, `query`, `params`, `headers`, `url`, `uri`, `ua`, `mobile`, `robot`, `referrer`, `host`, `address`, `protocol`, `language`, e `req` e `socket`. Puoi aggiungere le tue proprietà. `F.extend('controller', name, fn)` aggiunge un metodo ai controller HTTP e WebSocket.

Example: Dati propri
```js
self.on('open', function(client) {
	client.nick = client.query.nick || 'guest';
});
```

### client.id

Type: `property`

Un identificatore univoco del client.

Returns: `String`

Anche `client.ID`. È la chiave in `websocket.connections`.

Example: Inviare l'id
```js
client.send({ id: client.id });
```

### client.user

Type: `property`

L'utente restituito dal delegate di autorizzazione.

Returns: `Object`

`undefined` per i client anonimi.

Example: Saluto
```js
self.on('open', function(client) {
	client.send({ name: client.user ? client.user.name : 'guest' });
});
```

### client.ip

Type: `property`

L'indirizzo IP del client.

Returns: `String`

Il primo indirizzo di `X-Forwarded-For` dietro un proxy.

### client.query

Type: `property`

La query string dell'URL WebSocket come oggetto.

Returns: `Object`

Usala per passare dati che i browser non possono inviare negli header, come un token.

Example: Token
```js
// new WebSocket('ws://localhost:8000/live/?token=abc')
var token = client.query.token;
```

### client.params

Type: `property`

I parametri dinamici dell'URL.

Returns: `Object`

### client.headers

Type: `property`

Gli header della richiesta di upgrade, con i nomi in minuscolo.

Returns: `Object`

### client.latency

Type: `property`

Il tempo in ms tra l'ultimo ping e il suo pong.

Returns: `Number`

Ogni ping lo azzera a `null`; il pong imposta il tempo misurato.

Example: Mostrare la latenza
```js
self.on('message', function(client) {
	client.send({ latency: client.latency });
});
```

### client.address

Type: `property`

L'URL completo a cui il client si è connesso.

Returns: `String`

Il protocollo (`http` o `https`), l'host e il percorso con la query string.

### client.ua

Type: `property`

Un nome breve del browser e del sistema, ricavato da `User-Agent`.

Returns: `String`

`client.mobile` e `client.robot` sono `true` per i dispositivi mobili e i crawler.

### client.send(message, [raw], [replacer])

Type: `method`

Invia un messaggio a un client.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `message` | `Object|String|Buffer` | yes |  |  |
| `raw` | `Boolean` | no | `false` | Invia una stringa senza serializzazione JSON (route `@text`) |
| `replacer` | `Function` | no |  | Un replacer JSON |

Sulle route `@json` gli oggetti vengono serializzati con `JSON.stringify()` e gli altri valori vengono inviati come stringhe. Sulle route `@text` il messaggio viene serializzato in JSON a meno che `raw` sia `true`, che invia la stringa così com'è. Sulle route `@binary` passa un `Buffer`. `replacer` viene passato a `JSON.stringify()`.

Example: JSON
```js
client.send({ type: 'pong' });
```

Example: Testo semplice
```js
client.send('OK', true);
```

### client.close([code], [message])

Type: `method`

Chiude la connessione con il client.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `code` | `Number` | no | `1000` | Il codice di chiusura |
| `message` | `String` | no |  | Il motivo della chiusura |

Il frame di chiusura viene inviato dopo 1 secondo e poi il socket viene distrutto.

Example: Rifiutare
```js
self.on('open', function(client) {
	if (!client.query.token)
		client.close(4003, 'Forbidden');
});
```

### client.ping()

Type: `method`

Invia un ping al client.

Returns: `Controller` Lo stesso client

Il pong imposta `client.latency`.

### client.cookie(name)

Type: `method`

Legge un cookie della richiesta di upgrade.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  |  |

Returns: `String` Il valore decodificato, oppure una stringa vuota

Example: Sessione
```js
var sid = client.cookie('sid');
```

### client.hostname([path])

Type: `method`

Restituisce il protocollo e l'host della richiesta, con un percorso opzionale.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Aggiunto dopo l'host |

Returns: `String` Per esempio `https://example.com/path/`

### client.destroy()

Type: `method`

Distrugge subito il socket, senza frame di chiusura.

### WEBSOCKETCLIENT([callback])

Type: `method`

Crea un client WebSocket che si connette a un altro server.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(client)` |

Returns: `WebSocketClient` Il client

`callback(client)` viene chiamata subito con il nuovo client. Imposta le opzioni, gli header e gli eventi, poi chiama `client.connect()`.

Example: Connessione
```js
WEBSOCKETCLIENT(function(client) {
	client.on('open', function() {
		client.send({ type: 'hello' });
	});
	client.on('message', function(message) {
		console.log(message);
	});
	client.connect('ws://127.0.0.1:8000/live/');
});
```

### wsclient.connect(url, [protocol], [origin])

Type: `method`

Apre la connessione.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String|Object` | yes |  |  |
| `protocol` | `String` | no |  |  |
| `origin` | `String` | no |  |  |

`url` è un indirizzo `ws://` o `wss://`, oppure un oggetto `{ socket: '/path/to/unix.socket', path: '/live/' }` per un socket Unix. `protocol` viene inviato come `Sec-WebSocket-Protocol` e `origin` come `Sec-WebSocket-Origin`. I redirect HTTP (301, 302) vengono seguiti. Il client emette `open` quando il server accetta la connessione.

Example: Sicuro
```js
client.connect('wss://example.com/live/');
```

### wsclient.options

Type: `property`

Le opzioni del client.

Returns: `Object`

Impostale prima di `connect()`: `type` (`json`, `text` o `binary`, predefinito `json`), `compress` (`true`), `reconnect` (ritardo in ms dopo la chiusura della connessione, `3000`, `0` la disattiva), `reconnectserver` (`true` si riconnette anche quando la connessione non può essere aperta o il server risponde con un errore HTTP), `masking` (`false`), `encodedecode` (`false`), `encrypt` (una chiave per cifrare i messaggi), `size` (dimensione massima in byte di un messaggio decompresso, `0` nessun limite), `rejectunauthorized` (`false`), `timeout` (ritardo del keep-alive TCP in ms, `30000`, `0` lo disattiva), e `key`, `cert`, `dhparam` per TLS.

Example: Client di testo
```js
var client = WEBSOCKETCLIENT();
client.options.type = 'text';
client.options.reconnect = 0;
client.connect('ws://127.0.0.1:8000/terminal/');
```

### wsclient.headers

Type: `property`

Intestazioni aggiuntive della richiesta di upgrade.

Returns: `Object`

Impostali prima di `connect()`.

Example: Token
```js
client.headers['x-token'] = 'secret';
```

### wsclient.send(message, [raw], [replacer])

Type: `method`

Invia un messaggio al server.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `message` | `Object|String|Buffer` | yes |  |  |
| `raw` | `Boolean` | no | `false` | Invia una stringa JSON già pronta |
| `replacer` | `Function` | no |  | Un replacer JSON |

Returns: `Boolean` `true` quando il messaggio è stato scritto

Con il tipo `json`, il messaggio viene serializzato con `JSON.stringify()` a meno che `raw` sia `true`. Con il tipo `text`, gli oggetti vengono serializzati e gli altri valori vengono inviati come stringhe. Con il tipo `binary`, un valore che non è un Buffer viene convertito in un `Buffer`. Restituisce `false` quando la connessione è chiusa.

Example: Invio
```js
client.send({ type: 'subscribe', channel: 'news' });
```

### wsclient.sendcustom(type, message)

Type: `method`

Invia un messaggio come testo o binario, indipendentemente da `options.type`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | `binary` o `text` |
| `message` | `String|Buffer` | yes |  |  |

Returns: `Boolean` `true` quando il messaggio è stato scritto

`type` è `'binary'` o qualsiasi altro valore per il testo.

Example: Binario
```js
client.sendcustom('binary', Buffer.from([1, 2, 3]));
```

### wsclient.close([code], [message])

Type: `method`

Chiude la connessione.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `code` | `Number` | no | `1000` |  |
| `message` | `String|Boolean` | no |  | Il motivo della chiusura, oppure `true` |

Returns: `WebSocketClient`

Interrompe la riconnessione. Passa `true` come `message` per chiudere la connessione e mantenere la riconnessione automatica.

Example: Chiusura
```js
client.close();
```

### wsclient.destroy()

Type: `method`

Distrugge la connessione e interrompe la riconnessione.

Emette `destroy`.

Example: Distruggere
```js
client.destroy();
```

### wsclient.ping([timeout])

Type: `method`

Invia un ping e attende il pong.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `timeout` | `Number` | no | `3000` | Tempo in ms |

Returns: `WebSocketClient`

Il pong imposta `client.latency`. Senza un pong entro `timeout` ms il client emette `error` con un errore `Timeout`, chiude la connessione e si riconnette quando `options.reconnect` è impostato.

Example: Controllo continuo
```js
setInterval(function() {
	client.ping(5000);
}, 30000);
```

### wsclient.api(schema, [data], [callback], [timeout])

Type: `method`

Invia una richiesta API sulla connessione e attende la risposta.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `schema` | `String` | yes |  |  |
| `data` | `Object` | no |  |  |
| `callback` | `Function` | no |  | `function(err, response)` |
| `timeout` | `Number` | no | `5000` | Tempo in ms |

Returns: `Promise` Quando non viene passata una callback

Invia `{ TYPE: 'api', callbackid, data: { schema, data } }` e si risolve quando il server risponde con un messaggio `{ TYPE: 'api', callbackid, data }` (con `error: true`, `data` è l'errore). Senza una risposta entro `timeout` ms (5000) la callback riceve `408`. Senza callback restituisce una promise.

Example: Promise
```js
var response = await client.api('users_list', { page: 1 });
```

### wsclient.on('message', function(message, size) {})

Type: `event`

Un messaggio dal server.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `message` | `Object|String|Buffer` | yes |  |  |
| `size` | `Number` | yes |  |  |

Un oggetto analizzato con il tipo `json`, una stringa con `text`, un `Buffer` con `binary`.

### wsclient.on('open', function() {})

Type: `event`

La connessione è aperta.

Emesso anche dopo ogni riconnessione.

### wsclient.on('close', function(code, message) {})

Type: `event`

La connessione è stata chiusa.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `code` | `Number` | yes |  |  |
| `message` | `String` | yes |  |  |

### wsclient.on('error', function(err) {})

Type: `event`

Un errore di connessione, una risposta HTTP inattesa, una chiave del server non valida o un timeout del ping.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `err` | `Error` | yes |  |  |

Example: Log
```js
client.on('error', function(err) {
	console.log('WS error', err.message);
});
```

### route.remove()

Type: `method` · Since: `0.0.17`

Rimuove una route registrata con `ROUTE()`.

Per una route `SOCKET` rimuove la route e distrugge tutti i suoi oggetti WebSocket, quindi ogni client collegato viene disconnesso.

Example: Rimuovere
```js
var route = ROUTE('SOCKET /live/', live);
route.remove();
```
