Commit 410ce22f authored by Christian Lölkes's avatar Christian Lölkes
Browse files

Initial commit

parents
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [1.0.0] - 2019-04-30
### Added
- Inital commit
Copyright 2019 Christian Lölkes
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# R-IoT Sensor
Helps you build handle data from the R-IoT Platform.
'use strict';
console.debug('RIoTSensor v1.0.0');
export default class RIoTSensor {
constructor() {
this.isConnected = false;
this.message = false;
}
get statusMessage() {
if( Date.now() - this.lastMessage < 500 ) {
return 'Connected + data';
} else if( this.connection.readyState === 1 ) {
return 'Connected, no data';
}
return 'Not connected';
}
set statusMessage( value ) {
// Cannot be set. Setter only implemented to avoid error.
}
set url( value ) {
this.websocketURL = value;
this.connect();
}
get url() {
return this.websocketURL;
}
reconnect() {
this.connection.close();
console.info('Reconnecting in 2s.');
setTimeout(this.connect.bind(this), 2000);
}
connect() {
console.info('Connecting to websocket server.');
this.connection = new WebSocket( this.url );
this.connection.onerror = function( error ) {
console.error( 'Error in the WS connection.' );
this.close();
};
this.connection.onopen = function() {
console.info( 'OK: Connected to Websocket Server.' );
};
this.connection.onclose = function() {
console.info( 'Closing connection to websocket server.' );
}
this.connection.onmessage = function( message ) {
this.message = message;
let ws_event = new CustomEvent( 'WebSocketMessage' );
document.dispatchEvent( ws_event );
}.bind( this );
}
}
{
"name": "RIoTSensor",
"version": "1.0.0",
"description": "Handle data from a RIoT sensor board",
"main": "index.js",
"repository": {
"url": "https://hertz-gitlab.zkm.de/rapid-prototyping-lab/javascript-modules/r-iot-sensor.git",
"type": "git"
},
"scripts": {},
"author": "Christian Lölkes",
"license": "MIT",
"dependencies": {},
"devDependencies": {}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment