Changeset View
Changeset View
Standalone View
Standalone View
web/static/js/api.js
- This file was added.
import {Socket} from "phoenix" | |||||
class KolabChat | |||||
{ | |||||
constructor(config) | |||||
{ | |||||
this.config = config || {}; | |||||
} | |||||
init(config) | |||||
{ | |||||
if (config) | |||||
this.config = KolabChat.extend(this.config, config); | |||||
var params = { | |||||
token: this.config.token, | |||||
logger: ((kind, msg, data) => { console.log(`${kind}: ${msg}`, data) }) | |||||
}; | |||||
// FIXME: for some reason full URL did not work here | |||||
// We may need it for integration with external systems | |||||
this.socket = new Socket("/socket", {params: params}); | |||||
this.socket.connect(); | |||||
this.socket.onOpen(e => console.log("OPEN", e)) | |||||
this.socket.onError(e => console.log("ERROR", e)) | |||||
this.socket.onClose(e => console.log("CLOSE", e)) | |||||
} | |||||
static extend(obj, src) | |||||
{ | |||||
Object.keys(src).forEach(function(key) { obj[key] = src[key]; }); | |||||
return obj; | |||||
} | |||||
} | |||||
export default KolabChat |