-
Notifications
You must be signed in to change notification settings - Fork 3
WebSocket API
KeyChain contains a WebSocket API. This API can be used to stream information from a KeyChain instance to any client that implements WebSockets. Implementations in different languages:
- JavaScript
- Python
- JavaScript/HTML
- etc
Connect your WebSocket implementation to ws://localhost:8123/api/websocket.
Each WebSocket API message is a JSON serialized object containing a command with the corresponding parameters.
For full comprehensive descriptions of the commands, acceptable parameters and values, go to the Protocol.
Before you proceed with the integration, you need to download and install KeyChain.
After installing KeyChain you will need to create a web page that connects to WebSocket through localhost.
Below is an example of how to write a simple HTML page in JavaScript. [Write our own example in JS]
<!DOCTYPE html>
<html>
<head>
<title>websocketd count example</title>
<style>
#count {
font: bold 150px arial;
margin: auto;
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<div id="count"></div>
<script>
var ws = new WebSocket('ws://localhost:8080/');
ws.onopen = function() {
document.body.style.backgroundColor = '#cfc';
};
ws.onclose = function() {
document.body.style.backgroundColor = null;
};
ws.onmessage = function(event) {
document.getElementById('count').textContent = event.data;
};
</script>
</body>
</html>
Open this page through localhost: ws://localhost:8123/api/websocket
Python ≥ 3.6
NB: This documentation is written for Python ≥ 3.6.
Pip install websockets
Successfully installed websockets-7.0