Add url get method

This commit is contained in:
Ludovic Stephan 2017-03-31 15:10:41 -03:00
parent 499c081565
commit 413df0806d

View file

@ -40,13 +40,18 @@ class Websocket {
constructor(data) {
$.extend(this, this.constructor.default_data, data);
}
listen(handle_func) {
var that = this;
get url() {
var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws';
var location_host = window.location.host;
var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : location_host;
var socket = new ReconnectingWebSocket(websocket_protocol+"://" + location_url + this.relative_url);
return websocket_protocol+"://" + location_url + this.relative_url ;
}
listen(handle_func) {
var that = this;
var socket = new ReconnectingWebSocket(this.url);
socket.onmessage = function(e) {
var data = $.extend({}, that.default_msg, JSON.parse(e.data));