forked from DGNum/gestioCOF
Add url get method
This commit is contained in:
parent
499c081565
commit
413df0806d
1 changed files with 9 additions and 4 deletions
|
@ -40,13 +40,18 @@ class Websocket {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
$.extend(this, this.constructor.default_data, data);
|
$.extend(this, this.constructor.default_data, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
listen(handle_func) {
|
get url() {
|
||||||
var that = this;
|
|
||||||
var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws';
|
var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws';
|
||||||
var location_host = window.location.host;
|
var location_host = window.location.host;
|
||||||
var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : 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) {
|
socket.onmessage = function(e) {
|
||||||
var data = $.extend({}, that.default_msg, JSON.parse(e.data));
|
var data = $.extend({}, that.default_msg, JSON.parse(e.data));
|
||||||
|
|
Loading…
Add table
Reference in a new issue