keiser-echip-utilities
Advanced tools
Comparing version 0.1.0 to 0.1.1
144
dist/keu.js
@@ -231,3 +231,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.keu = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var appOrigin; | ||
var messengerStatus = { | ||
var status = { | ||
initialized : false, | ||
@@ -242,7 +242,8 @@ connected : false, | ||
var eChipGetMethod; | ||
var eChipSetMethod; | ||
// Connection request message for reference | ||
var connectionRequestID; | ||
var connectionRequestMessage; | ||
var lastRequestID; | ||
// Callback methods for portal requests | ||
var onGetRequestCallback; | ||
var onSetRequestCallback; | ||
@@ -253,6 +254,6 @@ /***************************************** | ||
var receiveMessage = function (messageEvent) { | ||
if (!messengerStatus.initialized) { | ||
initializeMessenger(messageEvent); | ||
if (!status.initialized) { | ||
initialize(messageEvent); | ||
} else { | ||
dispatchMessage(messageEvent.data); | ||
dispatch(messageEvent.data); | ||
} | ||
@@ -266,3 +267,3 @@ }; | ||
if (appWindow && appOrigin) { | ||
appWindow.postMessage(JSON.stringify(messageObject), appOrigin) | ||
appWindow.postMessage(JSON.stringify(messageObject), appOrigin); | ||
} | ||
@@ -272,13 +273,26 @@ }; | ||
/***************************************** | ||
* Compose Message | ||
*****************************************/ | ||
var composeMessage = function (id, type, action, data) { | ||
var messageObject = { | ||
id : id, | ||
type : type, | ||
action : action, | ||
data : data | ||
}; | ||
sendMessage(messageObject); | ||
}; | ||
/***************************************** | ||
* Messenger Initialization | ||
*****************************************/ | ||
var initializeMessenger = function (messageEvent) { | ||
var initialize = function (messageEvent) { | ||
var messageObject = JSON.parse(messageEvent.data); | ||
if ((messageObject || {}).action && messageObject.action == MESSENGER_CONST.ACTION.CONNECT) { | ||
if ((messageObject || {}).action && messageObject.action === MESSENGER_CONST.ACTION.CONNECT) { | ||
appWindow = messageEvent.source; | ||
appOrigin = messageEvent.origin; | ||
connectionRequestMessage = messageObject; | ||
messengerStatus.initialized = true; | ||
if (messengerStatus.enabled) { | ||
messengerConnect(); | ||
connectionRequestID = messageObject.id; | ||
status.initialized = true; | ||
if (status.enabled) { | ||
connect(); | ||
} | ||
@@ -291,18 +305,15 @@ } | ||
*****************************************/ | ||
var dispatchMessage = function (messageData) { | ||
if (messageData && messageData != '') { | ||
var dispatch = function (messageData) { | ||
if (status.enabled) { | ||
var messageObject = JSON.parse(messageData); | ||
if ((messageObject || {}).id) { | ||
lastRequestID = messageObject.id; | ||
if (messengerStatus.enabled) { | ||
switch (messageObject.action) { | ||
case MESSENGER_CONST.ACTION.ECHIP_SET: | ||
eChipSetMethod(messageObject.data, function () { | ||
messengerSetEChip(messageObject.id); | ||
}); | ||
break; | ||
case MESSENGER_CONST.ACTION.ECHIP_GET: | ||
messengerGetEChip(messageObject.id, eChipGetMethod(messageObject)); | ||
break; | ||
} | ||
switch (messageObject.action) { | ||
case MESSENGER_CONST.ACTION.ECHIP_SET: | ||
onSetRequestCallback(messageObject.data, function () { | ||
setRequestResponse(messageObject.id); | ||
}); | ||
break; | ||
case MESSENGER_CONST.ACTION.ECHIP_GET: | ||
getRequestResponse(messageObject.id, onGetRequestCallback(messageObject)); | ||
break; | ||
} | ||
@@ -316,42 +327,26 @@ } | ||
*****************************************/ | ||
var messengerConnect = function () { | ||
if (connectionRequestMessage) { | ||
var connectionResponseObject = { | ||
id : connectionRequestMessage.id, | ||
type : MESSENGER_CONST.TYPE.RESPONSE, | ||
action : MESSENGER_CONST.ACTION.CONNECT, | ||
data : { | ||
actions : [] | ||
} | ||
var connect = function () { | ||
if (connectionRequestID) { | ||
var data = { | ||
actions : [] | ||
}; | ||
if (messengerStatus.actions.eChipSet) { | ||
connectionResponseObject.data.actions.push(MESSENGER_CONST.ACTION.ECHIP_SET); | ||
if (status.actions.eChipSet) { | ||
data.actions.push(MESSENGER_CONST.ACTION.ECHIP_SET); | ||
} | ||
if (messengerStatus.actions.eChipGet) { | ||
connectionResponseObject.data.actions.push(MESSENGER_CONST.ACTION.ECHIP_GET); | ||
if (status.actions.eChipGet) { | ||
data.actions.push(MESSENGER_CONST.ACTION.ECHIP_GET); | ||
} | ||
sendMessage(connectionResponseObject); | ||
composeMessage(connectionRequestID, MESSENGER_CONST.TYPE.RESPONSE, MESSENGER_CONST.ACTION.CONNECT, data); | ||
} | ||
}; | ||
var messengerGetEChip = function (id, data) { | ||
var responseObject = { | ||
id : id, | ||
type : MESSENGER_CONST.TYPE.RESPONSE, | ||
action : MESSENGER_CONST.ACTION.ECHIP_GET, | ||
data : data | ||
}; | ||
sendMessage(responseObject); | ||
var getRequestResponse = function (id, data) { | ||
composeMessage(id, MESSENGER_CONST.TYPE.RESPONSE, MESSENGER_CONST.ACTION.ECHIP_GET, data); | ||
}; | ||
var messengerSetEChip = function (id) { | ||
var responseObject = { | ||
id : id, | ||
type : MESSENGER_CONST.TYPE.RESPONSE, | ||
action : MESSENGER_CONST.ACTION.ECHIP_SET, | ||
data : { | ||
success : true | ||
} | ||
var setRequestResponse = function (id) { | ||
var data = { | ||
success : true | ||
}; | ||
sendMessage(responseObject); | ||
composeMessage(id, MESSENGER_CONST.TYPE.RESPONSE, MESSENGER_CONST.ACTION.ECHIP_SET, data); | ||
}; | ||
@@ -362,17 +357,26 @@ | ||
*****************************************/ | ||
messenger.enable = function (sendMethod, receiveMethod) { | ||
if (typeof sendMethod === 'function') { | ||
messengerStatus.actions.eChipGet = true; | ||
eChipGetMethod = sendMethod; | ||
messenger.enable = function (onGetRequest, onSetRequest) { | ||
if (typeof onGetRequest === 'function') { | ||
status.actions.eChipGet = true; | ||
onGetRequestCallback = onGetRequest; | ||
} | ||
if (typeof receiveMethod === 'function') { | ||
messengerStatus.actions.eChipSet = true; | ||
eChipSetMethod = receiveMethod; | ||
if (typeof onSetRequest === 'function') { | ||
status.actions.eChipSet = true; | ||
onSetRequestCallback = onSetRequest; | ||
} | ||
messengerStatus.enabled = true; | ||
if (messengerStatus.initialized) { | ||
messengerConnect(); | ||
status.enabled = true; | ||
if (status.initialized) { | ||
connect(); | ||
} | ||
}; | ||
/***************************************** | ||
* Messenger Disable | ||
*****************************************/ | ||
messenger.disable = function () { | ||
status.enabled = false; | ||
onGetRequestCallback = null; | ||
onSetRequestCallback = null; | ||
}; | ||
window.addEventListener('message', receiveMessage); | ||
@@ -379,0 +383,0 @@ return messenger; |
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.keu=e()}}(function(){return function e(n,a,t){function o(i,r){if(!a[i]){if(!n[i]){var m="function"==typeof require&&require;if(!r&&m)return m(i,!0);if(s)return s(i,!0);var d=new Error("Cannot find module '"+i+"'");throw d.code="MODULE_NOT_FOUND",d}var l=a[i]={exports:{}};n[i][0].call(l.exports,function(e){var a=n[i][1][e];return o(a?a:e)},l,l.exports,e,n,a,t)}return a[i].exports}for(var s="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({1:[function(e,n,a){n.exports=function(){"use strict";var e={};const n=[{models:[4385,4394],name:"Leg Extension A250"},{models:[4386,4395],name:"Leg Extension A250, Range Limiter"},{models:[4401,4410],name:"Leg Extension A300 120 degree"},{models:[4402,4411],name:"Leg Extension A300 90 degree"},{models:[4641,4650],name:"Leg Curl A250"},{models:[4642,4651],name:"Leg Curl A250, Range Limiter"},{models:[4657,4666],name:"Leg Curl A300"},{models:[4897,4906],name:"Chest Press A250"},{models:[4913,4922],name:"Chest Press A300"},{models:[4917,4923],name:"Biaxial Chest Press A300"},{models:[4918,4924],name:"Straight Push Chest Press A300"},{models:[4919],name:"Straight Push Chest Press A300 2010-3-1"},{models:[4920],name:"Straight Push Chest Press A300 2010-9-1"},{models:[5169,5178],name:"Shoulder Raise A300"},{models:[5425,5434],name:"Squat A300"},{models:[5426,5435],name:"Squat A300"},{models:[5665,5674],name:"Military Press A250"},{models:[5681,5690],name:"Military Press A300"},{models:[5921,5930],name:"Arm Curl A250"},{models:[5942,5947],name:"Arm Curl A300"},{models:[6193,6202],name:"Shrug A300"},{models:[6433,6442],name:"Tricep A250"},{models:[6449,6458],name:"Tricep A300"},{models:[6455],name:"Engineering Test Tricep, one sided"},{models:[8225,8234],name:"Upper Back A250"},{models:[8241,8245,8250,8251],name:"Upper Back A300"},{models:[8481,8490],name:"Lat Pulldown A250"},{models:[8497,8506],name:"Lat Pulldown A300"},{models:[8737,8746],name:"Seated Butterfly A250"},{models:[8753,8762],name:"Seated Butterfly A300"},{models:[8757,8763],name:"Seated Butterfly A350"},{models:[9009,9018],name:"Abductor A300"},{models:[9265,9274],name:"Adductor A300"},{models:[9505,9514],name:"Leg Press A250"},{models:[9521,9530],name:"Leg Press A300"},{models:[9761,9770],name:"Standing Hip A250"},{models:[9777,9786],name:"Standing Hip A300"},{models:[10017,10026],name:"Abdominal A250"},{models:[10033,10042],name:"Abdominal A300"},{models:[10273,10282],name:"Lower Back A250"},{models:[10274,10283],name:"Lower Back A250, Range Limiter"},{models:[10289,10294,10298,10299],name:"Lower Back A300"},{models:[10550,10554],name:"Seated Calf A300"},{models:[12288,12298],name:"Performance Zone"},{models:[12304,12314],name:"Performance Trainer"},{models:[12320,12330],name:"Functional Trainer"},{models:[12336,12346],name:"Triple Trainer"},{models:[12352,12362],name:"Functional Wall Trainer"},{models:[12544],name:"Rack, Seat Settings"},{models:[12547,12548,12549,12550,12560,12561,12576],name:"Rack, Iron Weight"},{models:[12849],name:"Single Runner"},{models:[12850,12858],name:"Dual Runner"},{models:[39312],name:"One arm bandit test stand"},{models:[39321],name:"Pressure Gauge PSI"},{models:[39320],name:"Pressure Gauge KPA"}];return e.getMachineDetails=function(e){for(var a=0;a<n.length;a++)for(var t=0;t<n[a].models.length;t++)if(n[a].models[t]==e)return n[a]},e}()},{}],2:[function(e,n,a){n.exports=function(){"use strict";var n={};return n.machine=e("./machine"),n.messenger=e("./messenger"),n}()},{"./machine":1,"./messenger":3}],3:[function(e,n,a){n.exports=function(){"use strict";var e={};const n={TYPE:{RESPONSE:"response",REQUEST:"request"},ACTION:{CONNECT:"connect",ECHIP_SET:"echip-set",ECHIP_GET:"echip-get"}};var a,t,o,s,i,r,m={initialized:!1,connected:!1,enabled:!1,actions:{eChipSet:!1,eChipGet:!1}},d=function(e){m.initialized?c(e.data):u(e)},l=function(e){a&&t&&a.postMessage(JSON.stringify(e),t)},u=function(e){var o=JSON.parse(e.data);(o||{}).action&&o.action==n.ACTION.CONNECT&&(a=e.source,t=e.origin,i=o,m.initialized=!0,m.enabled&&f())},c=function(e){if(e&&""!=e){var a=JSON.parse(e);if((a||{}).id&&(r=a.id,m.enabled))switch(a.action){case n.ACTION.ECHIP_SET:s(a.data,function(){p(a.id)});break;case n.ACTION.ECHIP_GET:A(a.id,o(a))}}},f=function(){if(i){var e={id:i.id,type:n.TYPE.RESPONSE,action:n.ACTION.CONNECT,data:{actions:[]}};m.actions.eChipSet&&e.data.actions.push(n.ACTION.ECHIP_SET),m.actions.eChipGet&&e.data.actions.push(n.ACTION.ECHIP_GET),l(e)}},A=function(e,a){var t={id:e,type:n.TYPE.RESPONSE,action:n.ACTION.ECHIP_GET,data:a};l(t)},p=function(e){var a={id:e,type:n.TYPE.RESPONSE,action:n.ACTION.ECHIP_SET,data:{success:!0}};l(a)};return e.enable=function(e,n){"function"==typeof e&&(m.actions.eChipGet=!0,o=e),"function"==typeof n&&(m.actions.eChipSet=!0,s=n),m.enabled=!0,m.initialized&&f()},window.addEventListener("message",d),e}()},{}]},{},[2])(2)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.keu=e()}}(function(){return function e(n,a,o){function t(i,r){if(!a[i]){if(!n[i]){var m="function"==typeof require&&require;if(!r&&m)return m(i,!0);if(s)return s(i,!0);var d=new Error("Cannot find module '"+i+"'");throw d.code="MODULE_NOT_FOUND",d}var l=a[i]={exports:{}};n[i][0].call(l.exports,function(e){var a=n[i][1][e];return t(a?a:e)},l,l.exports,e,n,a,o)}return a[i].exports}for(var s="function"==typeof require&&require,i=0;i<o.length;i++)t(o[i]);return t}({1:[function(e,n,a){n.exports=function(){"use strict";var e={};const n=[{models:[4385,4394],name:"Leg Extension A250"},{models:[4386,4395],name:"Leg Extension A250, Range Limiter"},{models:[4401,4410],name:"Leg Extension A300 120 degree"},{models:[4402,4411],name:"Leg Extension A300 90 degree"},{models:[4641,4650],name:"Leg Curl A250"},{models:[4642,4651],name:"Leg Curl A250, Range Limiter"},{models:[4657,4666],name:"Leg Curl A300"},{models:[4897,4906],name:"Chest Press A250"},{models:[4913,4922],name:"Chest Press A300"},{models:[4917,4923],name:"Biaxial Chest Press A300"},{models:[4918,4924],name:"Straight Push Chest Press A300"},{models:[4919],name:"Straight Push Chest Press A300 2010-3-1"},{models:[4920],name:"Straight Push Chest Press A300 2010-9-1"},{models:[5169,5178],name:"Shoulder Raise A300"},{models:[5425,5434],name:"Squat A300"},{models:[5426,5435],name:"Squat A300"},{models:[5665,5674],name:"Military Press A250"},{models:[5681,5690],name:"Military Press A300"},{models:[5921,5930],name:"Arm Curl A250"},{models:[5942,5947],name:"Arm Curl A300"},{models:[6193,6202],name:"Shrug A300"},{models:[6433,6442],name:"Tricep A250"},{models:[6449,6458],name:"Tricep A300"},{models:[6455],name:"Engineering Test Tricep, one sided"},{models:[8225,8234],name:"Upper Back A250"},{models:[8241,8245,8250,8251],name:"Upper Back A300"},{models:[8481,8490],name:"Lat Pulldown A250"},{models:[8497,8506],name:"Lat Pulldown A300"},{models:[8737,8746],name:"Seated Butterfly A250"},{models:[8753,8762],name:"Seated Butterfly A300"},{models:[8757,8763],name:"Seated Butterfly A350"},{models:[9009,9018],name:"Abductor A300"},{models:[9265,9274],name:"Adductor A300"},{models:[9505,9514],name:"Leg Press A250"},{models:[9521,9530],name:"Leg Press A300"},{models:[9761,9770],name:"Standing Hip A250"},{models:[9777,9786],name:"Standing Hip A300"},{models:[10017,10026],name:"Abdominal A250"},{models:[10033,10042],name:"Abdominal A300"},{models:[10273,10282],name:"Lower Back A250"},{models:[10274,10283],name:"Lower Back A250, Range Limiter"},{models:[10289,10294,10298,10299],name:"Lower Back A300"},{models:[10550,10554],name:"Seated Calf A300"},{models:[12288,12298],name:"Performance Zone"},{models:[12304,12314],name:"Performance Trainer"},{models:[12320,12330],name:"Functional Trainer"},{models:[12336,12346],name:"Triple Trainer"},{models:[12352,12362],name:"Functional Wall Trainer"},{models:[12544],name:"Rack, Seat Settings"},{models:[12547,12548,12549,12550,12560,12561,12576],name:"Rack, Iron Weight"},{models:[12849],name:"Single Runner"},{models:[12850,12858],name:"Dual Runner"},{models:[39312],name:"One arm bandit test stand"},{models:[39321],name:"Pressure Gauge PSI"},{models:[39320],name:"Pressure Gauge KPA"}];return e.getMachineDetails=function(e){for(var a=0;a<n.length;a++)for(var o=0;o<n[a].models.length;o++)if(n[a].models[o]==e)return n[a]},e}()},{}],2:[function(e,n,a){n.exports=function(){"use strict";var n={};return n.machine=e("./machine"),n.messenger=e("./messenger"),n}()},{"./machine":1,"./messenger":3}],3:[function(e,n,a){n.exports=function(){"use strict";var e={};const n={TYPE:{RESPONSE:"response",REQUEST:"request"},ACTION:{CONNECT:"connect",ECHIP_SET:"echip-set",ECHIP_GET:"echip-get"}};var a,o,t,s,i,r={initialized:!1,connected:!1,enabled:!1,actions:{eChipSet:!1,eChipGet:!1}},m=function(e){r.initialized?c(e.data):u(e)},d=function(e){a&&o&&a.postMessage(JSON.stringify(e),o)},l=function(e,n,a,o){var t={id:e,type:n,action:a,data:o};d(t)},u=function(e){var s=JSON.parse(e.data);(s||{}).action&&s.action===n.ACTION.CONNECT&&(a=e.source,o=e.origin,t=s.id,r.initialized=!0,r.enabled&&f())},c=function(e){if(r.enabled){var a=JSON.parse(e);if((a||{}).id)switch(a.action){case n.ACTION.ECHIP_SET:i(a.data,function(){p(a.id)});break;case n.ACTION.ECHIP_GET:A(a.id,s(a))}}},f=function(){if(t){var e={actions:[]};r.actions.eChipSet&&e.actions.push(n.ACTION.ECHIP_SET),r.actions.eChipGet&&e.actions.push(n.ACTION.ECHIP_GET),l(t,n.TYPE.RESPONSE,n.ACTION.CONNECT,e)}},A=function(e,a){l(e,n.TYPE.RESPONSE,n.ACTION.ECHIP_GET,a)},p=function(e){var a={success:!0};l(e,n.TYPE.RESPONSE,n.ACTION.ECHIP_SET,a)};return e.enable=function(e,n){"function"==typeof e&&(r.actions.eChipGet=!0,s=e),"function"==typeof n&&(r.actions.eChipSet=!0,i=n),r.enabled=!0,r.initialized&&f()},e.disable=function(){r.enabled=!1,s=null,i=null},window.addEventListener("message",m),e}()},{}]},{},[2])(2)}); |
{ | ||
"name": "keiser-echip-utilities", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Keiser eChip Utilities", | ||
@@ -19,3 +19,12 @@ "main": "./src/main.js", | ||
}, | ||
"homepage": "https://github.com/KeiserCorp/Keiser.Air.eChipUtilities#readme" | ||
"homepage": "https://github.com/KeiserCorp/Keiser.Air.eChipUtilities#readme", | ||
"devDependencies": { | ||
"browserify": "^12.0.1", | ||
"gulp": "^3.9.0", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-streamify": "^1.0.2", | ||
"gulp-uglify": "^1.5.1", | ||
"gulp-watch": "^4.3.5", | ||
"vinyl-source-stream": "^1.1.0" | ||
} | ||
} |
@@ -5,5 +5,87 @@ Keiser eChip Utilities | ||
## Project | ||
Utilities to assist development of applications utilizing the Keiser eChip. | ||
Utilities to assist development of applications utilizing the Keiser eChip and Keiser eChip Portal Tool. | ||
## Getting Started | ||
You have following options to get started: | ||
- Download the [latest release](https://github.com/KeiserCorp/Keiser.Air.eChipUtilities/releases/latest) | ||
- Clone the repo: `git clone git://github.com/KeiserCorp/Keiser.Air.eChipUtilities.git` | ||
- Install with [NPM](https://www.npmjs.com/): `npm install keiser-echip-utilities` | ||
## Loading | ||
Each release includes a minified distribution version of the library which can be loaded with a module loader, or as a stand alone library. The unminified source files are also able to be loaded with tools like [browserify](http://browserify.org/). | ||
Module load the library with [CommonJS](http://www.commonjs.org/): | ||
``` | ||
var keu = require('keiser-echip-utilities'); | ||
``` | ||
Including the library as a stand-alone library: | ||
``` | ||
<script src="keu.min.js"></script> | ||
``` | ||
``` | ||
var keu = window.keu; | ||
``` | ||
## API | ||
The library is namespaced to allow modular loading of individual library sections as needed. | ||
- [Portal Messenger](#portal-messenger) | ||
- [Machine](#machine) | ||
### Portal Messenger | ||
The `portalMessenger` library allows communication with the Keiser eChip Portal Tool. | ||
#### `portalMessenger.enable(onSendRequest, onReceiveRequest)` | ||
Begins communication with the Keiser eChip Portal Tool. | ||
`onGetRequest` argument is a function called whenever a request to get data is made by the portal. The function should return the object to be sent in response to the portal request. | ||
`onSetRequest` agrument is a function called whenever a request to send data is made by the portal. The function should receive a `data` object and an `onSuccess` function. The `data` object is the data received from the portal. The `onSuccess` function should be ran upon successful processing of the `data` object. | ||
Passing a `null` as either argument will disable the corresponding portal capability. | ||
``` | ||
var onGeRequest = function(){ return getUserData(user.id); }; | ||
var onSetRequest = function(data, onSuccess){ | ||
saveUserData(data); | ||
onSuccess(); | ||
}; | ||
keu.portalMessenger.enable(onGeRequest, onSetRequest); | ||
``` | ||
#### `portalMessenger.disable()` | ||
Stops communication with the Keiser eChip Portal Tool. Communication can not be resumed after a `disable` call until a new connection request is made by the portal. | ||
### Machine | ||
#### `machine.getMachineDetails(modelNum)` | ||
Retreives machine details based on model number argument (`modelNum`). | ||
``` | ||
var details = machine.getMachineDetails(0x1335); | ||
``` | ||
``` | ||
{ | ||
models : [0x1335, 0x133B], | ||
name : 'Biaxial Chest Press A300' | ||
} | ||
``` | ||
## Contributors | ||
* [bayssmekanique](https://github.com/bayssmekanique) | ||
* [bayssmekanique](https://github.com/bayssmekanique) | ||
## Copyright and License | ||
Copyright [Keiser Corporation](http://keiser.com/) under the [MIT license](LICENSE.md). |
@@ -22,3 +22,3 @@ module.exports = function () { | ||
var appOrigin; | ||
var messengerStatus = { | ||
var status = { | ||
initialized : false, | ||
@@ -33,7 +33,8 @@ connected : false, | ||
var eChipGetMethod; | ||
var eChipSetMethod; | ||
// Connection request message for reference | ||
var connectionRequestID; | ||
var connectionRequestMessage; | ||
var lastRequestID; | ||
// Callback methods for portal requests | ||
var onGetRequestCallback; | ||
var onSetRequestCallback; | ||
@@ -44,6 +45,6 @@ /***************************************** | ||
var receiveMessage = function (messageEvent) { | ||
if (!messengerStatus.initialized) { | ||
initializeMessenger(messageEvent); | ||
if (!status.initialized) { | ||
initialize(messageEvent); | ||
} else { | ||
dispatchMessage(messageEvent.data); | ||
dispatch(messageEvent.data); | ||
} | ||
@@ -57,3 +58,3 @@ }; | ||
if (appWindow && appOrigin) { | ||
appWindow.postMessage(JSON.stringify(messageObject), appOrigin) | ||
appWindow.postMessage(JSON.stringify(messageObject), appOrigin); | ||
} | ||
@@ -63,13 +64,26 @@ }; | ||
/***************************************** | ||
* Compose Message | ||
*****************************************/ | ||
var composeMessage = function (id, type, action, data) { | ||
var messageObject = { | ||
id : id, | ||
type : type, | ||
action : action, | ||
data : data | ||
}; | ||
sendMessage(messageObject); | ||
}; | ||
/***************************************** | ||
* Messenger Initialization | ||
*****************************************/ | ||
var initializeMessenger = function (messageEvent) { | ||
var initialize = function (messageEvent) { | ||
var messageObject = JSON.parse(messageEvent.data); | ||
if ((messageObject || {}).action && messageObject.action == MESSENGER_CONST.ACTION.CONNECT) { | ||
if ((messageObject || {}).action && messageObject.action === MESSENGER_CONST.ACTION.CONNECT) { | ||
appWindow = messageEvent.source; | ||
appOrigin = messageEvent.origin; | ||
connectionRequestMessage = messageObject; | ||
messengerStatus.initialized = true; | ||
if (messengerStatus.enabled) { | ||
messengerConnect(); | ||
connectionRequestID = messageObject.id; | ||
status.initialized = true; | ||
if (status.enabled) { | ||
connect(); | ||
} | ||
@@ -82,18 +96,15 @@ } | ||
*****************************************/ | ||
var dispatchMessage = function (messageData) { | ||
if (messageData && messageData != '') { | ||
var dispatch = function (messageData) { | ||
if (status.enabled) { | ||
var messageObject = JSON.parse(messageData); | ||
if ((messageObject || {}).id) { | ||
lastRequestID = messageObject.id; | ||
if (messengerStatus.enabled) { | ||
switch (messageObject.action) { | ||
case MESSENGER_CONST.ACTION.ECHIP_SET: | ||
eChipSetMethod(messageObject.data, function () { | ||
messengerSetEChip(messageObject.id); | ||
}); | ||
break; | ||
case MESSENGER_CONST.ACTION.ECHIP_GET: | ||
messengerGetEChip(messageObject.id, eChipGetMethod(messageObject)); | ||
break; | ||
} | ||
switch (messageObject.action) { | ||
case MESSENGER_CONST.ACTION.ECHIP_SET: | ||
onSetRequestCallback(messageObject.data, function () { | ||
setRequestResponse(messageObject.id); | ||
}); | ||
break; | ||
case MESSENGER_CONST.ACTION.ECHIP_GET: | ||
getRequestResponse(messageObject.id, onGetRequestCallback(messageObject)); | ||
break; | ||
} | ||
@@ -107,42 +118,26 @@ } | ||
*****************************************/ | ||
var messengerConnect = function () { | ||
if (connectionRequestMessage) { | ||
var connectionResponseObject = { | ||
id : connectionRequestMessage.id, | ||
type : MESSENGER_CONST.TYPE.RESPONSE, | ||
action : MESSENGER_CONST.ACTION.CONNECT, | ||
data : { | ||
actions : [] | ||
} | ||
var connect = function () { | ||
if (connectionRequestID) { | ||
var data = { | ||
actions : [] | ||
}; | ||
if (messengerStatus.actions.eChipSet) { | ||
connectionResponseObject.data.actions.push(MESSENGER_CONST.ACTION.ECHIP_SET); | ||
if (status.actions.eChipSet) { | ||
data.actions.push(MESSENGER_CONST.ACTION.ECHIP_SET); | ||
} | ||
if (messengerStatus.actions.eChipGet) { | ||
connectionResponseObject.data.actions.push(MESSENGER_CONST.ACTION.ECHIP_GET); | ||
if (status.actions.eChipGet) { | ||
data.actions.push(MESSENGER_CONST.ACTION.ECHIP_GET); | ||
} | ||
sendMessage(connectionResponseObject); | ||
composeMessage(connectionRequestID, MESSENGER_CONST.TYPE.RESPONSE, MESSENGER_CONST.ACTION.CONNECT, data); | ||
} | ||
}; | ||
var messengerGetEChip = function (id, data) { | ||
var responseObject = { | ||
id : id, | ||
type : MESSENGER_CONST.TYPE.RESPONSE, | ||
action : MESSENGER_CONST.ACTION.ECHIP_GET, | ||
data : data | ||
}; | ||
sendMessage(responseObject); | ||
var getRequestResponse = function (id, data) { | ||
composeMessage(id, MESSENGER_CONST.TYPE.RESPONSE, MESSENGER_CONST.ACTION.ECHIP_GET, data); | ||
}; | ||
var messengerSetEChip = function (id) { | ||
var responseObject = { | ||
id : id, | ||
type : MESSENGER_CONST.TYPE.RESPONSE, | ||
action : MESSENGER_CONST.ACTION.ECHIP_SET, | ||
data : { | ||
success : true | ||
} | ||
var setRequestResponse = function (id) { | ||
var data = { | ||
success : true | ||
}; | ||
sendMessage(responseObject); | ||
composeMessage(id, MESSENGER_CONST.TYPE.RESPONSE, MESSENGER_CONST.ACTION.ECHIP_SET, data); | ||
}; | ||
@@ -153,17 +148,26 @@ | ||
*****************************************/ | ||
messenger.enable = function (sendMethod, receiveMethod) { | ||
if (typeof sendMethod === 'function') { | ||
messengerStatus.actions.eChipGet = true; | ||
eChipGetMethod = sendMethod; | ||
messenger.enable = function (onGetRequest, onSetRequest) { | ||
if (typeof onGetRequest === 'function') { | ||
status.actions.eChipGet = true; | ||
onGetRequestCallback = onGetRequest; | ||
} | ||
if (typeof receiveMethod === 'function') { | ||
messengerStatus.actions.eChipSet = true; | ||
eChipSetMethod = receiveMethod; | ||
if (typeof onSetRequest === 'function') { | ||
status.actions.eChipSet = true; | ||
onSetRequestCallback = onSetRequest; | ||
} | ||
messengerStatus.enabled = true; | ||
if (messengerStatus.initialized) { | ||
messengerConnect(); | ||
status.enabled = true; | ||
if (status.initialized) { | ||
connect(); | ||
} | ||
}; | ||
/***************************************** | ||
* Messenger Disable | ||
*****************************************/ | ||
messenger.disable = function () { | ||
status.enabled = false; | ||
onGetRequestCallback = null; | ||
onSetRequestCallback = null; | ||
}; | ||
window.addEventListener('message', receiveMessage); | ||
@@ -170,0 +174,0 @@ return messenger; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
30742
745
90
0
7