@p4d/hermes-js
v1.4.1
Published
Hermes client library for JS (browser & NodeJs)
Downloads
4
Readme
Hermes JS Library
Description
Hermes library performs the following tasks:
- Queue service
- Event messaging
Queue Service
This service handles the device storage, when there's a new message, it will always be saved in the storage. If storage is unavailable, it will mantain a cache queue that will get deleted on page leave.
Event Messaging
This service needs to be initialized with the hermes url, and then will send events that are in the queue whenever the connection is available
Installation
Simply require the javascript file into your project!
<script type="text/javascript" src="js/hermes-js.js"></script>
Usage
The first step is to create the Hermes object, with the following initial configuration:
- (string) Url: Hermes URL (should be http://hermes.p4d.com.ar:8080)
- (json) Project: A project object is composed of the project ID (e.g: 'nike_run_analysis') and the project readable name (e.g: 'Nike Run Analysis NBA')
- (string) Type: The type of events that will be sent, will probably be either appData or deviceStatus type
Configuration example
// Este es el use case tipico
var hermes = new Hermes({
url: 'http://hermes.p4d.com.ar:8080',
project: {
"id": 'nike_run_analysis',
"name": 'Nike Run Analysis'
},
type: 'appData'
})
After setting up the object, all that remains is to send messages, and there is a simple way to do so:
Send(data)
The send event will send the data to hermes, if internet is not connected, it will be saved in the cache to be sent when internet is available.
Data sent can be anything! But Hermes expects it to be a JSON object. A warning will be sent if it isn't.
Full example
<script type="text/javascript" src="hermes-js.js"></script>
<script type="text/javascript">
var config = {
url: 'http://hermes.p4d.com.ar:8080',
project: {
"id": 'nike_run_analysis',
"name": 'Nike Run Analysis'
},
type: 'appData'
}
var hermes = new Hermes(config)
var event = {
name: 'new_experience',
experience_id: 2
}
hermes.send(event)
</script>
TO-DO
- Code needs some refactoring, as of now, all work lies within the Hermes Class, and probably needs to shift some responsabilities to the HermesEvent class