ref
This commit is contained in:
+67
-66
@@ -31,45 +31,46 @@
|
||||
/**
|
||||
* Dynamic logic. Handles form appearance and behaviour depending on conditions.
|
||||
*
|
||||
* @class
|
||||
* @param {Object} defs Definitions.
|
||||
* @param {module:views/record/base} recordView A record view.
|
||||
*
|
||||
* @internal Instantiated in advanced-pack.
|
||||
*/
|
||||
const DynamicLogic = function (defs, recordView) {
|
||||
/**
|
||||
* @type {Object} Definitions.
|
||||
* @private
|
||||
*/
|
||||
this.defs = defs || {};
|
||||
class DynamicLogic {
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {module:views/record/base}
|
||||
* @private
|
||||
* @param {Object} defs Definitions.
|
||||
* @param {module:views/record/base} recordView A record view.
|
||||
*/
|
||||
this.recordView = recordView;
|
||||
constructor(defs, recordView) {
|
||||
|
||||
/**
|
||||
* @type {string[]}
|
||||
* @private
|
||||
*/
|
||||
this.fieldTypeList = ['visible', 'required', 'readOnly'];
|
||||
/**
|
||||
* @type {Object} Definitions.
|
||||
* @private
|
||||
*/
|
||||
this.defs = defs || {};
|
||||
|
||||
/**
|
||||
* @type {string[]}
|
||||
* @private
|
||||
*/
|
||||
this.panelTypeList = ['visible', 'styled'];
|
||||
};
|
||||
/**
|
||||
*
|
||||
* @type {module:views/record/base}
|
||||
* @private
|
||||
*/
|
||||
this.recordView = recordView;
|
||||
|
||||
_.extend(DynamicLogic.prototype, /** @lends DynamicLogic# */{
|
||||
/**
|
||||
* @type {string[]}
|
||||
* @private
|
||||
*/
|
||||
this.fieldTypeList = ['visible', 'required', 'readOnly'];
|
||||
|
||||
/**
|
||||
* @type {string[]}
|
||||
* @private
|
||||
*/
|
||||
this.panelTypeList = ['visible', 'styled'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Process.
|
||||
*/
|
||||
process: function () {
|
||||
process() {
|
||||
let fields = this.defs.fields || {};
|
||||
|
||||
Object.keys(fields).forEach(field => {
|
||||
@@ -140,14 +141,14 @@ _.extend(DynamicLogic.prototype, /** @lends DynamicLogic# */{
|
||||
this.resetOptionList(field);
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} panel A panel name.
|
||||
* @param {string} type A type.
|
||||
* @private
|
||||
*/
|
||||
processPanel: function (panel, type) {
|
||||
processPanel(panel, type) {
|
||||
let panels = this.defs.panels || {};
|
||||
let item = (panels[panel] || {});
|
||||
|
||||
@@ -173,7 +174,7 @@ _.extend(DynamicLogic.prototype, /** @lends DynamicLogic# */{
|
||||
}
|
||||
|
||||
this[methodName](panel);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a condition group.
|
||||
@@ -181,7 +182,7 @@ _.extend(DynamicLogic.prototype, /** @lends DynamicLogic# */{
|
||||
* @param {'and'|'or'|'not'} [type='and'] A type.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
checkConditionGroup: function (data, type) {
|
||||
checkConditionGroup(data, type) {
|
||||
type = type || 'and';
|
||||
|
||||
let list;
|
||||
@@ -218,7 +219,7 @@ _.extend(DynamicLogic.prototype, /** @lends DynamicLogic# */{
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a condition.
|
||||
@@ -226,12 +227,12 @@ _.extend(DynamicLogic.prototype, /** @lends DynamicLogic# */{
|
||||
* @param {Object} defs Definitions.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
checkCondition: function (defs) {
|
||||
checkCondition(defs) {
|
||||
defs = defs || {};
|
||||
|
||||
let type = defs.type || 'equals';
|
||||
|
||||
if (~['or', 'and', 'not'].indexOf(type)) {
|
||||
if (['or', 'and', 'not'].includes(type)) {
|
||||
return this.checkConditionGroup(defs.value, type);
|
||||
}
|
||||
|
||||
@@ -398,104 +399,104 @@ _.extend(DynamicLogic.prototype, /** @lends DynamicLogic# */{
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @param {string[]} optionList
|
||||
* @private
|
||||
*/
|
||||
setOptionList: function (field, optionList) {
|
||||
setOptionList(field, optionList) {
|
||||
this.recordView.setFieldOptionList(field, optionList);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @private
|
||||
*/
|
||||
resetOptionList: function (field) {
|
||||
resetOptionList(field) {
|
||||
this.recordView.resetFieldOptionList(field);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @private
|
||||
*/
|
||||
makeFieldVisibleTrue: function (field) {
|
||||
makeFieldVisibleTrue(field) {
|
||||
this.recordView.showField(field);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @private
|
||||
*/
|
||||
makeFieldVisibleFalse: function (field) {
|
||||
makeFieldVisibleFalse(field) {
|
||||
this.recordView.hideField(field);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @private
|
||||
*/
|
||||
makeFieldRequiredTrue: function (field) {
|
||||
makeFieldRequiredTrue(field) {
|
||||
this.recordView.setFieldRequired(field);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @private
|
||||
*/
|
||||
makeFieldRequiredFalse: function (field) {
|
||||
makeFieldRequiredFalse(field) {
|
||||
this.recordView.setFieldNotRequired(field);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @private
|
||||
*/
|
||||
makeFieldReadOnlyTrue: function (field) {
|
||||
makeFieldReadOnlyTrue(field) {
|
||||
this.recordView.setFieldReadOnly(field);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @private
|
||||
*/
|
||||
makeFieldReadOnlyFalse: function (field) {
|
||||
makeFieldReadOnlyFalse(field) {
|
||||
this.recordView.setFieldNotReadOnly(field);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} panel
|
||||
* @private
|
||||
*/
|
||||
makePanelVisibleTrue: function (panel) {
|
||||
makePanelVisibleTrue(panel) {
|
||||
this.recordView.showPanel(panel, 'dynamicLogic');
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} panel
|
||||
* @private
|
||||
*/
|
||||
makePanelVisibleFalse: function (panel) {
|
||||
makePanelVisibleFalse(panel) {
|
||||
this.recordView.hidePanel(panel, false, 'dynamicLogic');
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} panel
|
||||
* @private
|
||||
*/
|
||||
makePanelStyledTrue: function (panel) {
|
||||
this.recordView.stylePanel(panel, 'dynamicLogic');
|
||||
},
|
||||
makePanelStyledTrue(panel) {
|
||||
this.recordView.stylePanel(panel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} panel
|
||||
* @private
|
||||
*/
|
||||
makePanelStyledFalse: function (panel) {
|
||||
this.recordView.unstylePanel(panel, false, 'dynamicLogic');
|
||||
},
|
||||
makePanelStyledFalse(panel) {
|
||||
this.recordView.unstylePanel(panel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a panel-visible condition.
|
||||
@@ -503,14 +504,14 @@ _.extend(DynamicLogic.prototype, /** @lends DynamicLogic# */{
|
||||
* @param {string} name A panel name.
|
||||
* @param {Object} item Condition definitions.
|
||||
*/
|
||||
addPanelVisibleCondition: function (name, item) {
|
||||
addPanelVisibleCondition(name, item) {
|
||||
this.defs.panels = this.defs.panels || {};
|
||||
this.defs.panels[name] = this.defs.panels[name] || {};
|
||||
|
||||
this.defs.panels[name].visible = item;
|
||||
|
||||
this.processPanel(name, 'visible');
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a panel-styled condition.
|
||||
@@ -518,14 +519,14 @@ _.extend(DynamicLogic.prototype, /** @lends DynamicLogic# */{
|
||||
* @param {string} name A panel name.
|
||||
* @param {Object} item Condition definitions.
|
||||
*/
|
||||
addPanelStyledCondition: function (name, item) {
|
||||
addPanelStyledCondition(name, item) {
|
||||
this.defs.panels = this.defs.panels || {};
|
||||
this.defs.panels[name] = this.defs.panels[name] || {};
|
||||
|
||||
this.defs.panels[name].styled = item;
|
||||
|
||||
this.processPanel(name, 'styled');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default DynamicLogic;
|
||||
|
||||
@@ -30,56 +30,54 @@
|
||||
|
||||
import Bull from 'lib!bullbone';
|
||||
|
||||
/**
|
||||
* @class
|
||||
* @mixes Bull.Events
|
||||
* @param {Object.<string,*>} [defaultFieldStates] Default field states.
|
||||
* @param {Object.<string,*>} [defaultPanelStates] Default panel states.
|
||||
*/
|
||||
const ViewRecordHelper = function (defaultFieldStates, defaultPanelStates) {
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this.defaultFieldStates = defaultFieldStates || {};
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this.defaultPanelStates = defaultPanelStates || {};
|
||||
/** @private */
|
||||
this.fieldStateMap = {};
|
||||
/** @private */
|
||||
this.panelStateMap = {};
|
||||
/** @private */
|
||||
this.hiddenFields = {};
|
||||
/** @private */
|
||||
this.hiddenPanels = {};
|
||||
/** @private */
|
||||
this.fieldOptionListMap = {};
|
||||
class ViewRecordHelper {
|
||||
|
||||
_.extend(this, Bull.Events);
|
||||
};
|
||||
|
||||
_.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
/**
|
||||
* @class
|
||||
* @mixes Bull.Events
|
||||
* @param {Object.<string,*>} [defaultFieldStates] Default field states.
|
||||
* @param {Object.<string,*>} [defaultPanelStates] Default panel states.
|
||||
*/
|
||||
constructor(defaultFieldStates, defaultPanelStates) {
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this.defaultFieldStates = defaultFieldStates || {};
|
||||
/**
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this.defaultPanelStates = defaultPanelStates || {};
|
||||
/** @private */
|
||||
this.fieldStateMap = {};
|
||||
/** @private */
|
||||
this.panelStateMap = {};
|
||||
/** @private */
|
||||
this.hiddenFields = {};
|
||||
/** @private */
|
||||
this.hiddenPanels = {};
|
||||
/** @private */
|
||||
this.fieldOptionListMap = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hidden fields.
|
||||
*
|
||||
* @returns {Object.<string, boolean>}
|
||||
*/
|
||||
getHiddenFields: function () {
|
||||
getHiddenFields() {
|
||||
return this.hiddenFields;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hidden panels.
|
||||
*
|
||||
* @returns {Object.<string,boolean>}
|
||||
*/
|
||||
getHiddenPanels: function () {
|
||||
getHiddenPanels() {
|
||||
return this.hiddenPanels;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a field-state parameter.
|
||||
@@ -88,7 +86,7 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
* @param {string} name A parameter.
|
||||
* @param {*} value A value.
|
||||
*/
|
||||
setFieldStateParam: function (field, name, value) {
|
||||
setFieldStateParam(field, name, value) {
|
||||
switch (name) {
|
||||
case 'hidden':
|
||||
if (value) {
|
||||
@@ -103,7 +101,7 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
|
||||
this.fieldStateMap[field] = this.fieldStateMap[field] || {};
|
||||
this.fieldStateMap[field][name] = value;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a field-state parameter.
|
||||
@@ -112,7 +110,7 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
* @param {string} name A parameter.
|
||||
* @returns {*} A value.
|
||||
*/
|
||||
getFieldStateParam: function (field, name) {
|
||||
getFieldStateParam(field, name) {
|
||||
if (field in this.fieldStateMap) {
|
||||
if (name in this.fieldStateMap[field]) {
|
||||
return this.fieldStateMap[field][name];
|
||||
@@ -124,7 +122,7 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a panel-state parameter.
|
||||
@@ -133,7 +131,7 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
* @param {string} name A parameter.
|
||||
* @param {*} value A value.
|
||||
*/
|
||||
setPanelStateParam: function (panel, name, value) {
|
||||
setPanelStateParam(panel, name, value) {
|
||||
switch (name) {
|
||||
case 'hidden':
|
||||
if (value) {
|
||||
@@ -146,7 +144,7 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
|
||||
this.panelStateMap[panel] = this.panelStateMap[panel] || {};
|
||||
this.panelStateMap[panel][name] = value;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a panel-state parameter.
|
||||
@@ -155,7 +153,7 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
* @param {string} name A parameter.
|
||||
* @returns {*} A value.
|
||||
*/
|
||||
getPanelStateParam: function (panel, name) {
|
||||
getPanelStateParam(panel, name) {
|
||||
if (panel in this.panelStateMap) {
|
||||
if (name in this.panelStateMap[panel]) {
|
||||
return this.panelStateMap[panel][name];
|
||||
@@ -167,7 +165,7 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a field option list.
|
||||
@@ -175,18 +173,18 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
* @param {string} field A field name.
|
||||
* @param {string[]} list An option list.
|
||||
*/
|
||||
setFieldOptionList: function (field, list) {
|
||||
setFieldOptionList(field, list) {
|
||||
this.fieldOptionListMap[field] = list;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a field option list.
|
||||
*
|
||||
* @param {string} field A field name.
|
||||
*/
|
||||
clearFieldOptionList: function (field) {
|
||||
clearFieldOptionList(field) {
|
||||
delete this.fieldOptionListMap[field];
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a field option list.
|
||||
@@ -194,9 +192,9 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
* @param {string} field A field name.
|
||||
* @returns {string|null} Null if not set.
|
||||
*/
|
||||
getFieldOptionList: function (field) {
|
||||
getFieldOptionList(field) {
|
||||
return this.fieldOptionListMap[field] || null;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a field option list is set.
|
||||
@@ -204,9 +202,11 @@ _.extend(ViewRecordHelper.prototype, /** @lends ViewRecordHelper# */{
|
||||
* @param {string} field A field name.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasFieldOptionList: function (field) {
|
||||
hasFieldOptionList(field) {
|
||||
return (field in this.fieldOptionListMap);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_.extend(ViewRecordHelper.prototype, Bull.Events);
|
||||
|
||||
export default ViewRecordHelper;
|
||||
|
||||
@@ -379,8 +379,10 @@ class BaseRecordView extends View {
|
||||
* Hide a panel.
|
||||
*
|
||||
* @param {string} name A panel name.
|
||||
* @param {boolean} [locked=false] Won't be able to un-hide.
|
||||
* @param {module:views/record/detail~panelSoftLockedType} [softLockedType='default']
|
||||
*/
|
||||
hidePanel(name) {
|
||||
hidePanel(name, locked, softLockedType) {
|
||||
this.recordHelper.setPanelStateParam(name, 'hidden', true);
|
||||
|
||||
if (this.isRendered()) {
|
||||
|
||||
@@ -32,92 +32,92 @@ import Base64 from 'lib!base64';
|
||||
|
||||
/**
|
||||
* A web-socket manager.
|
||||
*
|
||||
* @class
|
||||
* @param {module:models/settings} config A config.
|
||||
*/
|
||||
const WebSocketManager = function (config) {
|
||||
/**
|
||||
* @private
|
||||
* @type {module:models/settings}
|
||||
*/
|
||||
this.config = config;
|
||||
class WebSocketManager {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {{category: string, callback: Function}[]}
|
||||
* @param {module:models/settings} config A config.
|
||||
*/
|
||||
this.subscribeQueue = [];
|
||||
constructor(config) {
|
||||
/**
|
||||
* @private
|
||||
* @type {module:models/settings}
|
||||
*/
|
||||
this.config = config;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.isConnected = false;
|
||||
/**
|
||||
* @private
|
||||
* @type {{category: string, callback: Function}[]}
|
||||
*/
|
||||
this.subscribeQueue = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
this.connection = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.isConnected = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.url = '';
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
this.connection = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.protocolPart = '';
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.url = '';
|
||||
|
||||
let url = this.config.get('webSocketUrl');
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.protocolPart = '';
|
||||
|
||||
if (url) {
|
||||
if (url.indexOf('wss://') === 0) {
|
||||
this.url = url.substring(6);
|
||||
this.protocolPart = 'wss://';
|
||||
let url = this.config.get('webSocketUrl');
|
||||
|
||||
if (url) {
|
||||
if (url.indexOf('wss://') === 0) {
|
||||
this.url = url.substring(6);
|
||||
this.protocolPart = 'wss://';
|
||||
}
|
||||
else {
|
||||
this.url = url.substring(5);
|
||||
this.protocolPart = 'ws://';
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.url = url.substring(5);
|
||||
this.protocolPart = 'ws://';
|
||||
let siteUrl = this.config.get('siteUrl') || '';
|
||||
|
||||
if (siteUrl.indexOf('https://') === 0) {
|
||||
this.url = siteUrl.substring(8);
|
||||
this.protocolPart = 'wss://';
|
||||
}
|
||||
else {
|
||||
this.url = siteUrl.substring(7);
|
||||
this.protocolPart = 'ws://';
|
||||
}
|
||||
|
||||
if (~this.url.indexOf('/')) {
|
||||
this.url = this.url.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
let port = this.protocolPart === 'wss://' ? 443 : 8080;
|
||||
|
||||
let si = this.url.indexOf('/');
|
||||
|
||||
if (~si) {
|
||||
this.url = this.url.substring(0, si) + ':' + port;
|
||||
}
|
||||
else {
|
||||
this.url += ':' + port;
|
||||
}
|
||||
|
||||
if (this.protocolPart === 'wss://') {
|
||||
this.url += '/wss';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
let siteUrl = this.config.get('siteUrl') || '';
|
||||
|
||||
if (siteUrl.indexOf('https://') === 0) {
|
||||
this.url = siteUrl.substring(8);
|
||||
this.protocolPart = 'wss://';
|
||||
}
|
||||
else {
|
||||
this.url = siteUrl.substring(7);
|
||||
this.protocolPart = 'ws://';
|
||||
}
|
||||
|
||||
if (~this.url.indexOf('/')) {
|
||||
this.url = this.url.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
let port = this.protocolPart === 'wss://' ? 443 : 8080;
|
||||
|
||||
let si = this.url.indexOf('/');
|
||||
|
||||
if (~si) {
|
||||
this.url = this.url.substring(0, si) + ':' + port;
|
||||
}
|
||||
else {
|
||||
this.url += ':' + port;
|
||||
}
|
||||
|
||||
if (this.protocolPart === 'wss://') {
|
||||
this.url += '/wss';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_.extend(WebSocketManager.prototype, /** @lends WebSocketManager# */{
|
||||
|
||||
/**
|
||||
* Connect.
|
||||
@@ -125,7 +125,7 @@ _.extend(WebSocketManager.prototype, /** @lends WebSocketManager# */{
|
||||
* @param {string} auth An auth string.
|
||||
* @param {string} userId A user ID.
|
||||
*/
|
||||
connect: function (auth, userId) {
|
||||
connect(auth, userId) {
|
||||
let authArray = Base64.decode(auth).split(':');
|
||||
|
||||
let authToken = authArray[1];
|
||||
@@ -152,12 +152,7 @@ _.extend(WebSocketManager.prototype, /** @lends WebSocketManager# */{
|
||||
}
|
||||
|
||||
if (e === ab.CONNECTION_LOST || e === ab.CONNECTION_UNREACHABLE) {
|
||||
setTimeout(
|
||||
() => {
|
||||
this.connect(auth, userId);
|
||||
},
|
||||
3000
|
||||
);
|
||||
setTimeout(() => this.connect(auth, userId), 3000);
|
||||
}
|
||||
},
|
||||
{skipSubprotocolCheck: true}
|
||||
@@ -168,7 +163,7 @@ _.extend(WebSocketManager.prototype, /** @lends WebSocketManager# */{
|
||||
|
||||
this.connection = null;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to a topic.
|
||||
@@ -176,7 +171,7 @@ _.extend(WebSocketManager.prototype, /** @lends WebSocketManager# */{
|
||||
* @param {string} category A topic.
|
||||
* @param {Function} callback A callback.
|
||||
*/
|
||||
subscribe: function (category, callback) {
|
||||
subscribe(category, callback) {
|
||||
if (!this.connection) {
|
||||
return;
|
||||
}
|
||||
@@ -201,7 +196,7 @@ _.extend(WebSocketManager.prototype, /** @lends WebSocketManager# */{
|
||||
console.error("WebSocket: Could not subscribe to "+category+".");
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe.
|
||||
@@ -209,7 +204,7 @@ _.extend(WebSocketManager.prototype, /** @lends WebSocketManager# */{
|
||||
* @param {string} category A topic.
|
||||
* @param {Function} [callback] A callback.
|
||||
*/
|
||||
unsubscribe: function (category, callback) {
|
||||
unsubscribe(category, callback) {
|
||||
if (!this.connection) {
|
||||
return;
|
||||
}
|
||||
@@ -229,12 +224,12 @@ _.extend(WebSocketManager.prototype, /** @lends WebSocketManager# */{
|
||||
console.error("WebSocket: Could not unsubscribe from "+category+".");
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a connection.
|
||||
*/
|
||||
close: function () {
|
||||
close() {
|
||||
if (!this.connection) {
|
||||
return;
|
||||
}
|
||||
@@ -247,7 +242,7 @@ _.extend(WebSocketManager.prototype, /** @lends WebSocketManager# */{
|
||||
}
|
||||
|
||||
this.isConnected = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default WebSocketManager;
|
||||
|
||||
Reference in New Issue
Block a user