-
Notifications
You must be signed in to change notification settings - Fork 6
WebSocket
dave-p edited this page Mar 6, 2024
·
5 revisions
Tvheadend has a websocket interface on port 9981. It is used by the UI to provide 'live' actions and updates, avoiding the need to refresh the screen.
The example below creates a WebSocket connection to the Tvheadend server and listens for updates.
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<title>Websocket Test</title>
<script>
let socket = new WebSocket("ws://192.168.0.1:9981/comet/ws");
socket.onmessage = function(event) {
let message = event.data;
let messageElem = document.createElement('div');
messageElem.textContent = message;
document.getElementById('messages').prepend(messageElem);
}
</script>
</head>
<body>
<header></header>
<main>
<div id="messages"></div>
</main>
<footer></footer>
</body>
</html>
Tvheadend transmits messages on the Websocket interface asynchronously, when either a event occurs or in some cases at scheduled intervals. The output format is JSON.
Each message contains a key "messages" whose value is an array of message objects. Each message object contains a key "notificationClass" which specifies the source of the message, and a series of message-specific key-value pairs.