Jeedom plugin to provide a reliable low latency bidirectional client-server communication over websocket protocol.
Events are pushed to clients avoiding long polling (Ajax request) overhead.
Reduce server load by sharing the Jeedom query and broadcast result to multiples clients.
Install plugin:
Websocket.zip
file in the Jeedom plugin admin GUI,Websocket
,Tune plugin configuration (from plugin configuration GUI):
8090
),myjeedom.ltd,10.0.0.42
(default set to your internal and external Jeedom instance hosts).(Optional) proxying websocket port (8090
) to regular http (80
) / https (443
) with Apache (require proxy_wstunnel
module) by adding the following lines in /etc/apache2/sites-enabled/000-default.conf
:
<Location "/myawesomesocket">
ProxyPass ws://localhost:8090
ProxyPassReverse ws://localhost:8090
</Location>
Check daemon configuration:
www-data
?
User=www-data
/var/www/html/
?
WorkingDirectory=/var/www/html/plugins/Websocket/core/php
/usr/bin/php
?
ExecStart=/usr/bin/php bin/server.php
To get Jeedom events, client:
onopen
event occurs,JavaScript example:
//1. connect
const websocket = new WebSocket('ws://10.0.0.42/myawesomesocket')
//2. send user credentials
websocket.onopen = (e) => {
const authMsg = JSON.stringify({ apiKey: 'userApiKey' })
websocket.send(authMsg)
}
//3. Handle events
websocket.onmessage = (e) => {
//do stuff with Jeedom events (e.data.result)
}
websocket.onerror = (e) => {
//handle error
}
websocket.onclose = (e) => {
//handle connection closed
}
See also the list of contributors to this project.
This project is powered by the following components: