Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results

Target

Select target project
  • oss/libraries/javascript/monster
1 result
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results
Show changes
Commits on Source (4)
<a name="v3.2.0"></a>
## [v3.2.0] - 2023-01-06
### Add Features
- connect return now a promise
<a name="v3.1.2"></a>
## [v3.1.2] - 2023-01-06
### Bug Fixes
......@@ -143,6 +149,7 @@
<a name="1.8.0"></a>
## 1.8.0 - 2021-08-15
[v3.2.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.1.2...v3.2.0
[v3.1.2]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.1.1...v3.1.2
[v3.1.1]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.1.0...v3.1.1
[v3.1.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.0.0...v3.1.0
......
{
"name": "@schukai/monster",
"version": "3.1.1",
"version": "3.1.2",
"description": "Monster is a simple library for creating fast, robust and lightweight websites.",
"keywords": [
"framework",
......
......@@ -56,52 +56,31 @@ const connectionStatusCode = {
};
/**
* The RestAPI is a class that enables a REST API server.
*
* @externalExample ../../../example/data/storage/restapi.mjs
* @license AGPLv3
* @since 3.1.0
* @copyright schukai GmbH
* @memberOf Monster.Data.Datasource
* @summary The LocalStorage class encapsulates the access to data objects.
*/
class WebSocketDatasource extends Datasource {
/**
*
* @param {Object} [options] options contains definitions for the datasource.
* @private
* @this {WebSocketDatasource}
* @throws {Error} No url defined for websocket datasource.
*/
constructor(options) {
super();
function connectServer(resolve, reject) {
const self = this;
if (isString(options)) {
options = {url: options};
let promiseAllredyResolved = false;
let connectionTimeout = self.getOption('connection.timeout');
if (!isInteger(connectionTimeout) || connectionTimeout < 100) {
connectionTimeout = 5000;
}
if (!isObject(options)) options = {};
this.setOptions(options);
this[receiveQueueSymbol] = new Queue();
this[connectionSymbol] = {};
this[connectionSymbol].socket = null;
this[connectionSymbol].reconnectCounter = 0;
this[manualCloseSymbol]=false;
setTimeout(() => {
if (promiseAllredyResolved) {
return;
}
reject(new Error("Connection timeout"));
}, connectionTimeout);
/**
*
* @returns {Websocketdatasource}
* @throws {Error} No url defined for websocket datasource.
*/
connect() {
const self = this;
let connected = false;
let reconnectTimeout = self.getOption('reconnect.timeout');
let reconnectTimeout = self.getOption('connection.reconnect.timeout');
if (!isInteger(reconnectTimeout) || reconnectTimeout < 1000) reconnectTimeout = 1000;
let reconnectAttempts = self.getOption('reconnect.attempts');
let reconnectAttempts = self.getOption('connection.reconnect.attempts');
if (!isInteger(reconnectAttempts) || reconnectAttempts < 1) reconnectAttempts = 1;
let reconnectEnabled = self.getOption('reconnect.enabled');
let reconnectEnabled = self.getOption('connection.reconnect.enabled');
if (reconnectEnabled !== true) reconnectEnabled = false;
self[manualCloseSymbol] = false;
......@@ -113,7 +92,10 @@ class WebSocketDatasource extends Datasource {
self[connectionSymbol].socket = null;
const url = self.getOption('url');
if (!url) throw new Error('No url defined for websocket datasource.');
if (!url) {
reject('No url defined for websocket datasource.');
return;
}
self[connectionSymbol].socket = new WebSocket(url);
......@@ -121,12 +103,15 @@ class WebSocketDatasource extends Datasource {
self[receiveQueueSymbol].add(event);
setTimeout(function () {
self.read();
}, 0);
}, 1);
};
self[connectionSymbol].socket.onopen = function () {
connected = true;
self[connectionSymbol].reconnectCounter = 0;
if (typeof resolve === 'function' && !promiseAllredyResolved) {
promiseAllredyResolved = true;
resolve();
}
};
self[connectionSymbol].socket.close = function (event) {
......@@ -150,13 +135,66 @@ class WebSocketDatasource extends Datasource {
setTimeout(() => {
self.connect();
}, reconnectTimeout * this[connectionSymbol].reconnectCounter);
} else {
if (typeof reject === 'function' && !promiseAllredyResolved) {
promiseAllredyResolved = true;
reject(error);
}
}
};
}
/**
* The RestAPI is a class that enables a REST API server.
*
* @externalExample ../../../example/data/storage/restapi.mjs
* @license AGPLv3
* @since 3.1.0
* @copyright schukai GmbH
* @memberOf Monster.Data.Datasource
* @summary The LocalStorage class encapsulates the access to data objects.
*/
class WebSocketDatasource extends Datasource {
/**
*
* @param {Object} [options] options contains definitions for the datasource.
*/
constructor(options) {
super();
if (isString(options)) {
options = {url: options};
}
if (!isObject(options)) options = {};
this.setOptions(options);
this[receiveQueueSymbol] = new Queue();
this[connectionSymbol] = {};
this[connectionSymbol].socket = null;
this[connectionSymbol].reconnectCounter = 0;
this[manualCloseSymbol] = false;
}
/**
*
* @returns {Promise}
*/
connect() {
const self = this;
return new Promise((resolve, reject) => {
connectServer.call(this, resolve, reject);
});
}
/**
* @returns {boolean}
*/
isConnected() {
return this[connectionSymbol].socket && this[connectionSymbol].socket.readyState === 1;
return this[connectionSymbol]?.socket?.readyState === 1;
}
/**
......@@ -169,9 +207,11 @@ class WebSocketDatasource extends Datasource {
/**
* @property {string} url=undefined Defines the resource that you wish to fetch.
* @property {Number} reconnect.timeout The timeout in milliseconds for the reconnect.
* @property {Number} reconnect.attempts The maximum number of reconnects.
* @property {Bool} reconnect.enabled If the reconnect is enabled.
* @property {Object} connection
* @property {Object} connection.timeout=5000 Defines the timeout for the connection.
* @property {Number} connection.reconnect.timeout The timeout in milliseconds for the reconnect.
* @property {Number} connection.reconnect.attempts The maximum number of reconnects.
* @property {Bool} connection.reconnect.enabled If the reconnect is enabled.
* @property {Object} write={} Options
* @property {Object} write.mapping the mapping is applied before writing.
* @property {String} write.mapping.transformer Transformer to select the appropriate entries
......@@ -208,10 +248,13 @@ class WebSocketDatasource extends Datasource {
callbacks: []
},
},
connection: {
timeout: 5000,
reconnect: {
timeout: 1000,
attempts: 10,
enabled: true
attempts: 1,
enabled: false,
}
}
});
}
......
......@@ -149,7 +149,7 @@ function getMonsterVersion() {
}
/** don't touch, replaced by make with package.json version */
monsterVersion = new Version('3.1.1')
monsterVersion = new Version('3.1.2')
return monsterVersion;
......
{
"name": "monster",
"version": "3.1.1",
"version": "3.1.2",
"description": "monster",
"repository": {
"type": "git",
......
......@@ -7,7 +7,7 @@ describe('Monster', function () {
let monsterVersion
/** don´t touch, replaced by make with package.json version */
monsterVersion = new Version('3.1.1')
monsterVersion = new Version('3.1.2')
let m = getMonsterVersion();
......
{"version":"3.1.2"}
{"version":"3.2.0"}