[IMAGE: https://cdn.steemitimages.com/DQmYjiC4VYNHRm6tRcaNiSr6Hzx3ZUJdMgzSBGv1sgSRyaf/spectrum.jpeg]
EOS Tribe launched a beta version of it's web-socket streaming Spectrum API on Telos Testnet (https://www.telosfoundation.io/).
Telos Testnet Spectrum API web-socket endpoint: wss://testnet.telos.eostribe.io
Sample HTML/JS Client code for Get Actions:
Spectrum Web Sockets
let socket = new WebSocket("wss://testnet.telos.eostribe.io/streaming");
var actionsList = ["transfer","buyram"];
var messageBody = {
"apikey":"test-api-key",
"event":"subscribe",
"type":"get_actions",
"data": {"account":"eosio"}
};
socket.onopen = function(e) {
console.log("[open] Connection established");
console.log("Sending to server: "+JSON.stringify(messageBody));
socket.send(JSON.stringify(messageBody));
};
socket.onmessage = function(event) {
html_log("[message] Data received from server: "+event.data);
};
socket.onclose = function(event) {
if (event.wasClean) {
html_log("[close] Connection closed cleanly, code=${event.code} reason=${event.reason}");
} else {
html_log("[close] Connection died");
}
};
socket.onerror = function(error) {
html_log("[error] ${error.message}");
};
function html_log(data) {
var divLog = document.getElementById("log");
divLog.innerHTML += "
"+data+"";
}
Spectrum Web Sockets Test: Get Actions
Sample HTML/JS Client code for Get Blocks:
Spectrum Web Sockets
let socket = new WebSocket("wss://testnet.telos.eostribe.io/streaming");
var messageBody = {
"apikey":"test-api-key",
"event":"subscribe",
"type":"get_blocks"
};
socket.onopen = function(e) {
html_log("[open] Connection established");
html_log("[subscribe] sending message to server");
socket.send(JSON.stringify(messageBody));
};
socket.onmessage = function(event) {
html_log("[message] Data received from server: "+event.data);
};
socket.onclose = function(event) {
if (event.wasClean) {
html_log("[close] Connection closed cleanly, code=${event.code} reason=${event.reason}");
} else {
html_log("[close] Connection died");
}
};
socket.onerror = function(error) {
html_log("[error] ${error.message}");
};
function html_log(data) {
var divLog = document.getElementById("log");
divLog.innerHTML += "
"+data+"";
}
Spectrum Web Sockets Test: Get Blocks
Sample HTML/JS Client code for Get Transaction:
Spectrum Web Sockets
let socket = new WebSocket("wss://testnet.telos.eostribe.io/streaming");
var messageBody ={
"apikey":"test-api-key",
"event":"subscribe",
"type":"get_transaction",
"data": {"account":"eosio"}
};
socket.onopen = function(e) {
console.log("[open] Connection established");
console.log("Sending to server: "+JSON.stringify(messageBody));
socket.send(JSON.stringify(messageBody));
};
socket.onmessage = function(event) {
html_log("[message] Data received from server: "+event.data);
};
socket.onclose = function(event) {
if (event.wasClean) {
html_log("[close] Connection closed cleanly, code=${event.code} reason=${event.reason}");
} else {
html_log("[close] Connection died");
}
};
socket.onerror = function(error) {
html_log("[error] ${error.message}");
};
function html_log(data) {
var divLog = document.getElementById("log");
divLog.innerHTML += "
"+data+"";
}
Spectrum Web Sockets Test: Get Transactions