1.1.1 • Published 2 years ago
frontline-client v1.1.1
Frontline Javascript Client
This library is used to interact with the Frontline WebSocket API.
An example usage is below.
import {Client} from './index.js';
const url = location.origin;
function save_session(data) {
localStorage.setItem("session", JSON.stringify(data));
}
function maybe_session() {
let s = localStorage.getItem("session");
s = JSON.parse(s);
return s;
}
function init(session) {
save_session(session)
fl.init(session)
}
let session = maybe_session();
function open(event){
console.info("Open:", event.detail);
}
function initialized(event){
console.log("channel initialized:", event.detail);
}
function updated(event){
console.log("channel updated:", event.detail);
}
window.fl = new Client(url);
window.fl.addEventListener("open", open);
window.fl.addEventListener("initialized", initialized);
window.fl.addEventListener("updated", updated);
if(!session){
let email = prompt("Email Address");
fl.send_login_email(email);
let token = prompt("Login Token");
fl.authenticate(token)
.then(session => init(session));
}else{
init(session);
}