Comparing version 3.2.0 to 3.2.1
@@ -0,1 +1,8 @@ | ||
# v3.2.1 (2023/09/23) | ||
## Bugfixes | ||
- Fix issue with name minifying causing problems with class name reflection (again, see v3.1.0 notes | ||
for the first round of this) | ||
# v3.2.0 (2023/09/23) | ||
@@ -2,0 +9,0 @@ |
@@ -46,2 +46,3 @@ /*! | ||
const eventemitter3_1 = require("eventemitter3"); | ||
const MessageUtils_1 = require("../core/MessageUtils"); | ||
/** | ||
@@ -107,3 +108,3 @@ * Represents an abstract device, capable of taking certain kinds of messages. | ||
const response = yield this.send(msg); | ||
switch (response.constructor) { | ||
switch ((0, MessageUtils_1.getMessageClassFromMessage)(response)) { | ||
case Messages.Ok: | ||
@@ -220,3 +221,3 @@ return; | ||
const response = yield this.send(new Messages.SensorReadCmd(this.index, sensorIndex, sensorType)); | ||
switch (response.constructor) { | ||
switch ((0, MessageUtils_1.getMessageClassFromMessage)(response)) { | ||
case Messages.SensorReading: | ||
@@ -274,3 +275,3 @@ return response.Data; | ||
const response = yield this.send(new Messages.RawReadCmd(this.index, endpoint, expectedLength, timeout)); | ||
switch (response.constructor) { | ||
switch ((0, MessageUtils_1.getMessageClassFromMessage)(response)) { | ||
case Messages.RawReading: | ||
@@ -277,0 +278,0 @@ return new Uint8Array(response.Data); |
@@ -50,2 +50,3 @@ /*! | ||
const ButtplugClientConnectorException_1 = require("./ButtplugClientConnectorException"); | ||
const MessageUtils_1 = require("../core/MessageUtils"); | ||
class ButtplugClient extends eventemitter3_1.EventEmitter { | ||
@@ -95,3 +96,3 @@ constructor(clientName = 'Generic Buttplug Client') { | ||
for (const x of leftoverMsgs) { | ||
switch (x.constructor) { | ||
switch ((0, MessageUtils_1.getMessageClassFromMessage)(x)) { | ||
case Messages.DeviceAdded: { | ||
@@ -124,3 +125,3 @@ const addedMsg = x; | ||
const msg = yield this.sendMessage(new Messages.RequestServerInfo(this._clientName, Messages.MESSAGE_SPEC_VERSION)); | ||
switch (msg.constructor) { | ||
switch ((0, MessageUtils_1.getMessageClassFromMessage)(msg)) { | ||
case Messages.ServerInfo: { | ||
@@ -187,3 +188,3 @@ const serverinfo = msg; | ||
const response = yield this.sendMessage(msg); | ||
switch (response.constructor) { | ||
switch ((0, MessageUtils_1.getMessageClassFromMessage)(response)) { | ||
case Messages.Ok: | ||
@@ -194,3 +195,3 @@ return; | ||
default: | ||
throw Exceptions_1.ButtplugError.LogAndError(Exceptions_1.ButtplugMessageError, this._logger, `Message type ${response.constructor} not handled by SendMsgExpectOk`); | ||
throw Exceptions_1.ButtplugError.LogAndError(Exceptions_1.ButtplugMessageError, this._logger, `Message type ${(0, MessageUtils_1.getMessageClassFromMessage)(response).constructor} not handled by SendMsgExpectOk`); | ||
} | ||
@@ -197,0 +198,0 @@ }); |
@@ -9,2 +9,3 @@ /*! | ||
import * as Messages from './Messages'; | ||
export declare function getMessageClassFromMessage(msg: Messages.ButtplugMessage): (new (...args: unknown[]) => Messages.ButtplugMessage) | null; | ||
export declare function fromJSON(str: any): Messages.ButtplugMessage[]; |
@@ -33,3 +33,3 @@ /*! | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fromJSON = void 0; | ||
exports.fromJSON = exports.getMessageClassFromMessage = void 0; | ||
const class_transformer_1 = require("class-transformer"); | ||
@@ -45,2 +45,8 @@ const Messages = __importStar(require("./Messages")); | ||
} | ||
function getMessageClassFromMessage(msg) { | ||
// Making the bold assumption all message classes have the Name static. Should define a | ||
// requirement for this in the abstract class. | ||
return getMessageClass(Object.getPrototypeOf(msg).constructor.Name); | ||
} | ||
exports.getMessageClassFromMessage = getMessageClassFromMessage; | ||
function fromJSON(str) { | ||
@@ -47,0 +53,0 @@ const msgarray = JSON.parse(str); |
@@ -1,2 +0,2 @@ | ||
(function(p,ie){typeof exports=="object"&&typeof module<"u"?ie(exports):typeof define=="function"&&define.amd?define(["exports"],ie):(p=typeof globalThis<"u"?globalThis:p||self,ie(p.buttplug={}))})(this,function(p){"use strict";var ie=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Lt(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var nt={exports:{}};(function(r){var e=Object.prototype.hasOwnProperty,t="~";function n(){}Object.create&&(n.prototype=Object.create(null),new n().__proto__||(t=!1));function i(g,w,l){this.fn=g,this.context=w,this.once=l||!1}function u(g,w,l,v,h){if(typeof l!="function")throw new TypeError("The listener must be a function");var T=new i(l,v||g,h),x=t?t+w:w;return g._events[x]?g._events[x].fn?g._events[x]=[g._events[x],T]:g._events[x].push(T):(g._events[x]=T,g._eventsCount++),g}function a(g,w){--g._eventsCount===0?g._events=new n:delete g._events[w]}function f(){this._events=new n,this._eventsCount=0}f.prototype.eventNames=function(){var w=[],l,v;if(this._eventsCount===0)return w;for(v in l=this._events)e.call(l,v)&&w.push(t?v.slice(1):v);return Object.getOwnPropertySymbols?w.concat(Object.getOwnPropertySymbols(l)):w},f.prototype.listeners=function(w){var l=t?t+w:w,v=this._events[l];if(!v)return[];if(v.fn)return[v.fn];for(var h=0,T=v.length,x=new Array(T);h<T;h++)x[h]=v[h].fn;return x},f.prototype.listenerCount=function(w){var l=t?t+w:w,v=this._events[l];return v?v.fn?1:v.length:0},f.prototype.emit=function(w,l,v,h,T,x){var G=t?t+w:w;if(!this._events[G])return!1;var m=this._events[G],D=arguments.length,L,M;if(m.fn){switch(m.once&&this.removeListener(w,m.fn,void 0,!0),D){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,l),!0;case 3:return m.fn.call(m.context,l,v),!0;case 4:return m.fn.call(m.context,l,v,h),!0;case 5:return m.fn.call(m.context,l,v,h,T),!0;case 6:return m.fn.call(m.context,l,v,h,T,x),!0}for(M=1,L=new Array(D-1);M<D;M++)L[M-1]=arguments[M];m.fn.apply(m.context,L)}else{var J=m.length,E;for(M=0;M<J;M++)switch(m[M].once&&this.removeListener(w,m[M].fn,void 0,!0),D){case 1:m[M].fn.call(m[M].context);break;case 2:m[M].fn.call(m[M].context,l);break;case 3:m[M].fn.call(m[M].context,l,v);break;case 4:m[M].fn.call(m[M].context,l,v,h);break;default:if(!L)for(E=1,L=new Array(D-1);E<D;E++)L[E-1]=arguments[E];m[M].fn.apply(m[M].context,L)}}return!0},f.prototype.on=function(w,l,v){return u(this,w,l,v,!1)},f.prototype.once=function(w,l,v){return u(this,w,l,v,!0)},f.prototype.removeListener=function(w,l,v,h){var T=t?t+w:w;if(!this._events[T])return this;if(!l)return a(this,T),this;var x=this._events[T];if(x.fn)x.fn===l&&(!h||x.once)&&(!v||x.context===v)&&a(this,T);else{for(var G=0,m=[],D=x.length;G<D;G++)(x[G].fn!==l||h&&!x[G].once||v&&x[G].context!==v)&&m.push(x[G]);m.length?this._events[T]=m.length===1?m[0]:m:a(this,T)}return this},f.prototype.removeAllListeners=function(w){var l;return w?(l=t?t+w:w,this._events[l]&&a(this,l)):(this._events=new n,this._eventsCount=0),this},f.prototype.off=f.prototype.removeListener,f.prototype.addListener=f.prototype.on,f.prefixed=t,f.EventEmitter=f,r.exports=f})(nt);var Rt=nt.exports;const we=Lt(Rt);/*! | ||
(function(l,oe){typeof exports=="object"&&typeof module<"u"?oe(exports):typeof define=="function"&&define.amd?define(["exports"],oe):(l=typeof globalThis<"u"?globalThis:l||self,oe(l.buttplug={}))})(this,function(l){"use strict";var oe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function It(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var rt={exports:{}};(function(r){var e=Object.prototype.hasOwnProperty,t="~";function n(){}Object.create&&(n.prototype=Object.create(null),new n().__proto__||(t=!1));function i(g,w,p){this.fn=g,this.context=w,this.once=p||!1}function u(g,w,p,v,h){if(typeof p!="function")throw new TypeError("The listener must be a function");var T=new i(p,v||g,h),x=t?t+w:w;return g._events[x]?g._events[x].fn?g._events[x]=[g._events[x],T]:g._events[x].push(T):(g._events[x]=T,g._eventsCount++),g}function a(g,w){--g._eventsCount===0?g._events=new n:delete g._events[w]}function f(){this._events=new n,this._eventsCount=0}f.prototype.eventNames=function(){var w=[],p,v;if(this._eventsCount===0)return w;for(v in p=this._events)e.call(p,v)&&w.push(t?v.slice(1):v);return Object.getOwnPropertySymbols?w.concat(Object.getOwnPropertySymbols(p)):w},f.prototype.listeners=function(w){var p=t?t+w:w,v=this._events[p];if(!v)return[];if(v.fn)return[v.fn];for(var h=0,T=v.length,x=new Array(T);h<T;h++)x[h]=v[h].fn;return x},f.prototype.listenerCount=function(w){var p=t?t+w:w,v=this._events[p];return v?v.fn?1:v.length:0},f.prototype.emit=function(w,p,v,h,T,x){var G=t?t+w:w;if(!this._events[G])return!1;var m=this._events[G],D=arguments.length,L,M;if(m.fn){switch(m.once&&this.removeListener(w,m.fn,void 0,!0),D){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,p),!0;case 3:return m.fn.call(m.context,p,v),!0;case 4:return m.fn.call(m.context,p,v,h),!0;case 5:return m.fn.call(m.context,p,v,h,T),!0;case 6:return m.fn.call(m.context,p,v,h,T,x),!0}for(M=1,L=new Array(D-1);M<D;M++)L[M-1]=arguments[M];m.fn.apply(m.context,L)}else{var J=m.length,E;for(M=0;M<J;M++)switch(m[M].once&&this.removeListener(w,m[M].fn,void 0,!0),D){case 1:m[M].fn.call(m[M].context);break;case 2:m[M].fn.call(m[M].context,p);break;case 3:m[M].fn.call(m[M].context,p,v);break;case 4:m[M].fn.call(m[M].context,p,v,h);break;default:if(!L)for(E=1,L=new Array(D-1);E<D;E++)L[E-1]=arguments[E];m[M].fn.apply(m[M].context,L)}}return!0},f.prototype.on=function(w,p,v){return u(this,w,p,v,!1)},f.prototype.once=function(w,p,v){return u(this,w,p,v,!0)},f.prototype.removeListener=function(w,p,v,h){var T=t?t+w:w;if(!this._events[T])return this;if(!p)return a(this,T),this;var x=this._events[T];if(x.fn)x.fn===p&&(!h||x.once)&&(!v||x.context===v)&&a(this,T);else{for(var G=0,m=[],D=x.length;G<D;G++)(x[G].fn!==p||h&&!x[G].once||v&&x[G].context!==v)&&m.push(x[G]);m.length?this._events[T]=m.length===1?m[0]:m:a(this,T)}return this},f.prototype.removeAllListeners=function(w){var p;return w?(p=t?t+w:w,this._events[p]&&a(this,p)):(this._events=new n,this._eventsCount=0),this},f.prototype.off=f.prototype.removeListener,f.prototype.addListener=f.prototype.on,f.prefixed=t,f.EventEmitter=f,r.exports=f})(rt);var Dt=rt.exports;const _e=It(Dt);/*! | ||
* Buttplug JS Source Code File - Visit https://buttplug.io for more info about | ||
@@ -7,3 +7,3 @@ * the project. Licensed under the BSD 3-Clause license. See LICENSE file in the | ||
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved. | ||
*/var ze=(r=>(r[r.Off=0]="Off",r[r.Error=1]="Error",r[r.Warn=2]="Warn",r[r.Info=3]="Info",r[r.Debug=4]="Debug",r[r.Trace=5]="Trace",r))(ze||{});class rt{constructor(e,t){const n=new Date,i=n.getHours(),u=n.getMinutes(),a=n.getSeconds();this.timestamp=`${i}:${u}:${a}`,this.logMessage=e,this.logLevel=t}get Message(){return this.logMessage}get LogLevel(){return this.logLevel}get Timestamp(){return this.timestamp}get FormattedMessage(){return`${ze[this.logLevel]} : ${this.timestamp} : ${this.logMessage}`}}const st=class Je extends we{constructor(){super(),this.maximumConsoleLogLevel=0,this.maximumEventLogLevel=0}static get Logger(){return Je.sLogger===void 0&&(Je.sLogger=new Je),this.sLogger}get MaximumConsoleLogLevel(){return this.maximumConsoleLogLevel}set MaximumConsoleLogLevel(e){this.maximumConsoleLogLevel=e}get MaximumEventLogLevel(){return this.maximumEventLogLevel}set MaximumEventLogLevel(e){this.maximumEventLogLevel=e}Error(e){this.AddLogMessage(e,1)}Warn(e){this.AddLogMessage(e,2)}Info(e){this.AddLogMessage(e,3)}Debug(e){this.AddLogMessage(e,4)}Trace(e){this.AddLogMessage(e,5)}AddLogMessage(e,t){if(t>this.maximumEventLogLevel&&t>this.maximumConsoleLogLevel)return;const n=new rt(e,t);t<=this.maximumConsoleLogLevel&&console.log(n.FormattedMessage),t<=this.maximumEventLogLevel&&this.emit("log",n)}};st.sLogger=void 0;let it=st;var b;(function(r){r[r.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",r[r.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",r[r.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(b||(b={}));var It=function(){function r(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return r.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},r.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},r.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},r.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},r.prototype.findTransformMetadatas=function(e,t,n){return this.findMetadatas(this._transformMetadatas,e,t).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?n===b.CLASS_TO_CLASS||n===b.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?n===b.CLASS_TO_PLAIN:!0})},r.prototype.findExcludeMetadata=function(e,t){return this.findMetadata(this._excludeMetadatas,e,t)},r.prototype.findExposeMetadata=function(e,t){return this.findMetadata(this._exposeMetadatas,e,t)},r.prototype.findExposeMetadataByCustomName=function(e,t){return this.getExposedMetadatas(e).find(function(n){return n.options&&n.options.name===t})},r.prototype.findTypeMetadata=function(e,t){return this.findMetadata(this._typeMetadatas,e,t)},r.prototype.getStrategy=function(e){var t=this._excludeMetadatas.get(e),n=t&&t.get(void 0),i=this._exposeMetadatas.get(e),u=i&&i.get(void 0);return n&&u||!n&&!u?"none":n?"excludeAll":"exposeAll"},r.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},r.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},r.prototype.getExposedProperties=function(e,t){return this.getExposedMetadatas(e).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?t===b.CLASS_TO_CLASS||t===b.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?t===b.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},r.prototype.getExcludedProperties=function(e,t){return this.getExcludedMetadatas(e).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?t===b.CLASS_TO_CLASS||t===b.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?t===b.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},r.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},r.prototype.getMetadata=function(e,t){var n=e.get(t),i;n&&(i=Array.from(n.values()).filter(function(v){return v.propertyName!==void 0}));for(var u=[],a=0,f=this.getAncestors(t);a<f.length;a++){var g=f[a],w=e.get(g);if(w){var l=Array.from(w.values()).filter(function(v){return v.propertyName!==void 0});u.push.apply(u,l)}}return u.concat(i||[])},r.prototype.findMetadata=function(e,t,n){var i=e.get(t);if(i){var u=i.get(n);if(u)return u}for(var a=0,f=this.getAncestors(t);a<f.length;a++){var g=f[a],w=e.get(g);if(w){var l=w.get(n);if(l)return l}}},r.prototype.findMetadatas=function(e,t,n){var i=e.get(t),u;i&&(u=i.get(n));for(var a=[],f=0,g=this.getAncestors(t);f<g.length;f++){var w=g[f],l=e.get(w);l&&l.has(n)&&a.push.apply(a,l.get(n))}return a.slice().reverse().concat((u||[]).slice().reverse())},r.prototype.getAncestors=function(e){if(!e)return[];if(!this._ancestorsMap.has(e)){for(var t=[],n=Object.getPrototypeOf(e.prototype.constructor);typeof n.prototype<"u";n=Object.getPrototypeOf(n.prototype.constructor))t.push(n);this._ancestorsMap.set(e,t)}return this._ancestorsMap.get(e)},r}(),U=new It;function Dt(){if(typeof globalThis<"u")return globalThis;if(typeof global<"u")return global;if(typeof window<"u")return window;if(typeof self<"u")return self}function Tt(r){return r!==null&&typeof r=="object"&&typeof r.then=="function"}var ot=globalThis&&globalThis.__spreadArray||function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,u;n<i;n++)(u||!(n in e))&&(u||(u=Array.prototype.slice.call(e,0,n)),u[n]=e[n]);return r.concat(u||Array.prototype.slice.call(e))};function Nt(r){var e=new r;return!(e instanceof Set)&&!("push"in e)?[]:e}var oe=function(){function r(e,t){this.transformationType=e,this.options=t,this.recursionStack=new Set}return r.prototype.transform=function(e,t,n,i,u,a){var f=this;if(a===void 0&&(a=0),Array.isArray(t)||t instanceof Set){var g=i&&this.transformationType===b.PLAIN_TO_CLASS?Nt(i):[];return t.forEach(function(m,D){var L=e?e[D]:void 0;if(!f.options.enableCircularCheck||!f.isCircular(m)){var M=void 0;if(typeof n!="function"&&n&&n.options&&n.options.discriminator&&n.options.discriminator.property&&n.options.discriminator.subTypes){if(f.transformationType===b.PLAIN_TO_CLASS){M=n.options.discriminator.subTypes.find(function(Q){return Q.name===m[n.options.discriminator.property]});var J={newObject:g,object:m,property:void 0},E=n.typeFunction(J);M===void 0?M=E:M=M.value,n.options.keepDiscriminatorProperty||delete m[n.options.discriminator.property]}f.transformationType===b.CLASS_TO_CLASS&&(M=m.constructor),f.transformationType===b.CLASS_TO_PLAIN&&(m[n.options.discriminator.property]=n.options.discriminator.subTypes.find(function(Q){return Q.value===m.constructor}).name)}else M=n;var B=f.transform(L,m,M,void 0,m instanceof Map,a+1);g instanceof Set?g.add(B):g.push(B)}else f.transformationType===b.CLASS_TO_CLASS&&(g instanceof Set?g.add(m):g.push(m))}),g}else{if(n===String&&!u)return t==null?t:String(t);if(n===Number&&!u)return t==null?t:Number(t);if(n===Boolean&&!u)return t==null?t:!!t;if((n===Date||t instanceof Date)&&!u)return t instanceof Date?new Date(t.valueOf()):t==null?t:new Date(t);if(Dt().Buffer&&(n===Buffer||t instanceof Buffer)&&!u)return t==null?t:Buffer.from(t);if(Tt(t)&&!u)return new Promise(function(m,D){t.then(function(L){return m(f.transform(void 0,L,n,void 0,void 0,a+1))},D)});if(!u&&t!==null&&typeof t=="object"&&typeof t.then=="function")return t;if(typeof t=="object"&&t!==null){!n&&t.constructor!==Object&&(!Array.isArray(t)&&t.constructor===Array||(n=t.constructor)),!n&&e&&(n=e.constructor),this.options.enableCircularCheck&&this.recursionStack.add(t);var w=this.getKeys(n,t,u),l=e||{};!e&&(this.transformationType===b.PLAIN_TO_CLASS||this.transformationType===b.CLASS_TO_CLASS)&&(u?l=new Map:n?l=new n:l={});for(var v=function(m){if(m==="__proto__"||m==="constructor")return"continue";var D=m,L=m,M=m;if(!h.options.ignoreDecorators&&n){if(h.transformationType===b.PLAIN_TO_CLASS){var J=U.findExposeMetadataByCustomName(n,m);J&&(M=J.propertyName,L=J.propertyName)}else if(h.transformationType===b.CLASS_TO_PLAIN||h.transformationType===b.CLASS_TO_CLASS){var J=U.findExposeMetadata(n,m);J&&J.options&&J.options.name&&(L=J.options.name)}}var E=void 0;h.transformationType===b.PLAIN_TO_CLASS?E=t[D]:t instanceof Map?E=t.get(D):t[D]instanceof Function?E=t[D]():E=t[D];var B=void 0,Q=E instanceof Map;if(n&&u)B=n;else if(n){var P=U.findTypeMetadata(n,M);if(P){var Ve={newObject:l,object:t,property:M},We=P.typeFunction?P.typeFunction(Ve):P.reflectedType;P.options&&P.options.discriminator&&P.options.discriminator.property&&P.options.discriminator.subTypes?t[D]instanceof Array?B=P:(h.transformationType===b.PLAIN_TO_CLASS&&(B=P.options.discriminator.subTypes.find(function(X){if(E&&E instanceof Object&&P.options.discriminator.property in E)return X.name===E[P.options.discriminator.property]}),B===void 0?B=We:B=B.value,P.options.keepDiscriminatorProperty||E&&E instanceof Object&&P.options.discriminator.property in E&&delete E[P.options.discriminator.property]),h.transformationType===b.CLASS_TO_CLASS&&(B=E.constructor),h.transformationType===b.CLASS_TO_PLAIN&&E&&(E[P.options.discriminator.property]=P.options.discriminator.subTypes.find(function(X){return X.value===E.constructor}).name)):B=We,Q=Q||P.reflectedType===Map}else if(h.options.targetMaps)h.options.targetMaps.filter(function(X){return X.target===n&&!!X.properties[M]}).forEach(function(X){return B=X.properties[M]});else if(h.options.enableImplicitConversion&&h.transformationType===b.PLAIN_TO_CLASS){var qe=Reflect.getMetadata("design:type",n.prototype,M);qe&&(B=qe)}}var ee=Array.isArray(t[D])?h.getReflectedType(n,M):void 0,ye=e?e[D]:void 0;if(l.constructor.prototype){var ue=Object.getOwnPropertyDescriptor(l.constructor.prototype,L);if((h.transformationType===b.PLAIN_TO_CLASS||h.transformationType===b.CLASS_TO_CLASS)&&(ue&&!ue.set||l[L]instanceof Function))return"continue"}if(!h.options.enableCircularCheck||!h.isCircular(E)){var se=h.transformationType===b.PLAIN_TO_CLASS?L:m,R=void 0;h.transformationType===b.CLASS_TO_PLAIN?(R=t[se],R=h.applyCustomTransformations(R,n,se,t,h.transformationType),R=t[se]===R?E:R,R=h.transform(ye,R,B,ee,Q,a+1)):E===void 0&&h.options.exposeDefaultValues?R=l[L]:(R=h.transform(ye,E,B,ee,Q,a+1),R=h.applyCustomTransformations(R,n,se,t,h.transformationType)),(R!==void 0||h.options.exposeUnsetFields)&&(l instanceof Map?l.set(L,R):l[L]=R)}else if(h.transformationType===b.CLASS_TO_CLASS){var R=E;R=h.applyCustomTransformations(R,n,m,t,h.transformationType),(R!==void 0||h.options.exposeUnsetFields)&&(l instanceof Map?l.set(L,R):l[L]=R)}},h=this,T=0,x=w;T<x.length;T++){var G=x[T];v(G)}return this.options.enableCircularCheck&&this.recursionStack.delete(t),l}else return t}},r.prototype.applyCustomTransformations=function(e,t,n,i,u){var a=this,f=U.findTransformMetadatas(t,n,this.transformationType);return this.options.version!==void 0&&(f=f.filter(function(g){return g.options?a.checkVersion(g.options.since,g.options.until):!0})),this.options.groups&&this.options.groups.length?f=f.filter(function(g){return g.options?a.checkGroups(g.options.groups):!0}):f=f.filter(function(g){return!g.options||!g.options.groups||!g.options.groups.length}),f.forEach(function(g){e=g.transformFn({value:e,key:n,obj:i,type:u,options:a.options})}),e},r.prototype.isCircular=function(e){return this.recursionStack.has(e)},r.prototype.getReflectedType=function(e,t){if(e){var n=U.findTypeMetadata(e,t);return n?n.reflectedType:void 0}},r.prototype.getKeys=function(e,t,n){var i=this,u=U.getStrategy(e);u==="none"&&(u=this.options.strategy||"exposeAll");var a=[];if((u==="exposeAll"||n)&&(t instanceof Map?a=Array.from(t.keys()):a=Object.keys(t)),n)return a;if(this.options.ignoreDecorators&&this.options.excludeExtraneousValues&&e){var f=U.getExposedProperties(e,this.transformationType),g=U.getExcludedProperties(e,this.transformationType);a=ot(ot([],f,!0),g,!0)}if(!this.options.ignoreDecorators&&e){var f=U.getExposedProperties(e,this.transformationType);this.transformationType===b.PLAIN_TO_CLASS&&(f=f.map(function(v){var h=U.findExposeMetadata(e,v);return h&&h.options&&h.options.name?h.options.name:v})),this.options.excludeExtraneousValues?a=f:a=a.concat(f);var w=U.getExcludedProperties(e,this.transformationType);w.length>0&&(a=a.filter(function(v){return!w.includes(v)})),this.options.version!==void 0&&(a=a.filter(function(v){var h=U.findExposeMetadata(e,v);return!h||!h.options?!0:i.checkVersion(h.options.since,h.options.until)})),this.options.groups&&this.options.groups.length?a=a.filter(function(v){var h=U.findExposeMetadata(e,v);return!h||!h.options?!0:i.checkGroups(h.options.groups)}):a=a.filter(function(v){var h=U.findExposeMetadata(e,v);return!h||!h.options||!h.options.groups||!h.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(a=a.filter(function(l){return i.options.excludePrefixes.every(function(v){return l.substr(0,v.length)!==v})})),a=a.filter(function(l,v,h){return h.indexOf(l)===v}),a},r.prototype.checkVersion=function(e,t){var n=!0;return n&&e&&(n=this.options.version>=e),n&&t&&(n=this.options.version<t),n},r.prototype.checkGroups=function(e){return e?this.options.groups.some(function(t){return e.includes(t)}):!0},r}(),ae={enableCircularCheck:!1,enableImplicitConversion:!1,excludeExtraneousValues:!1,excludePrefixes:void 0,exposeDefaultValues:!1,exposeUnsetFields:!0,groups:void 0,ignoreDecorators:!1,strategy:void 0,targetMaps:void 0,version:void 0},q=globalThis&&globalThis.__assign||function(){return q=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},q.apply(this,arguments)},Pt=function(){function r(){}return r.prototype.instanceToPlain=function(e,t){var n=new oe(b.CLASS_TO_PLAIN,q(q({},ae),t));return n.transform(void 0,e,void 0,void 0,void 0,void 0)},r.prototype.classToPlainFromExist=function(e,t,n){var i=new oe(b.CLASS_TO_PLAIN,q(q({},ae),n));return i.transform(t,e,void 0,void 0,void 0,void 0)},r.prototype.plainToInstance=function(e,t,n){var i=new oe(b.PLAIN_TO_CLASS,q(q({},ae),n));return i.transform(void 0,t,e,void 0,void 0,void 0)},r.prototype.plainToClassFromExist=function(e,t,n){var i=new oe(b.PLAIN_TO_CLASS,q(q({},ae),n));return i.transform(e,t,void 0,void 0,void 0,void 0)},r.prototype.instanceToInstance=function(e,t){var n=new oe(b.CLASS_TO_CLASS,q(q({},ae),t));return n.transform(void 0,e,void 0,void 0,void 0,void 0)},r.prototype.classToClassFromExist=function(e,t,n){var i=new oe(b.CLASS_TO_CLASS,q(q({},ae),n));return i.transform(t,e,void 0,void 0,void 0,void 0)},r.prototype.serialize=function(e,t){return JSON.stringify(this.instanceToPlain(e,t))},r.prototype.deserialize=function(e,t,n){var i=JSON.parse(t);return this.plainToInstance(e,i,n)},r.prototype.deserializeArray=function(e,t,n){var i=JSON.parse(t);return this.plainToInstance(e,i,n)},r}();function He(r,e){return e===void 0&&(e={}),function(t,n){var i=Reflect.getMetadata("design:type",t,n);U.addTypeMetadata({target:t.constructor,propertyName:n,reflectedType:i,typeFunction:r,options:e})}}var at=new Pt;function kt(r,e){return at.instanceToPlain(r,e)}function Bt(r,e,t){return at.plainToInstance(r,e,t)}/*! ***************************************************************************** | ||
*/var He=(r=>(r[r.Off=0]="Off",r[r.Error=1]="Error",r[r.Warn=2]="Warn",r[r.Info=3]="Info",r[r.Debug=4]="Debug",r[r.Trace=5]="Trace",r))(He||{});class st{constructor(e,t){const n=new Date,i=n.getHours(),u=n.getMinutes(),a=n.getSeconds();this.timestamp=`${i}:${u}:${a}`,this.logMessage=e,this.logLevel=t}get Message(){return this.logMessage}get LogLevel(){return this.logLevel}get Timestamp(){return this.timestamp}get FormattedMessage(){return`${He[this.logLevel]} : ${this.timestamp} : ${this.logMessage}`}}const it=class ze extends _e{constructor(){super(),this.maximumConsoleLogLevel=0,this.maximumEventLogLevel=0}static get Logger(){return ze.sLogger===void 0&&(ze.sLogger=new ze),this.sLogger}get MaximumConsoleLogLevel(){return this.maximumConsoleLogLevel}set MaximumConsoleLogLevel(e){this.maximumConsoleLogLevel=e}get MaximumEventLogLevel(){return this.maximumEventLogLevel}set MaximumEventLogLevel(e){this.maximumEventLogLevel=e}Error(e){this.AddLogMessage(e,1)}Warn(e){this.AddLogMessage(e,2)}Info(e){this.AddLogMessage(e,3)}Debug(e){this.AddLogMessage(e,4)}Trace(e){this.AddLogMessage(e,5)}AddLogMessage(e,t){if(t>this.maximumEventLogLevel&&t>this.maximumConsoleLogLevel)return;const n=new st(e,t);t<=this.maximumConsoleLogLevel&&console.log(n.FormattedMessage),t<=this.maximumEventLogLevel&&this.emit("log",n)}};it.sLogger=void 0;let ot=it;var C;(function(r){r[r.PLAIN_TO_CLASS=0]="PLAIN_TO_CLASS",r[r.CLASS_TO_PLAIN=1]="CLASS_TO_PLAIN",r[r.CLASS_TO_CLASS=2]="CLASS_TO_CLASS"})(C||(C={}));var Tt=function(){function r(){this._typeMetadatas=new Map,this._transformMetadatas=new Map,this._exposeMetadatas=new Map,this._excludeMetadatas=new Map,this._ancestorsMap=new Map}return r.prototype.addTypeMetadata=function(e){this._typeMetadatas.has(e.target)||this._typeMetadatas.set(e.target,new Map),this._typeMetadatas.get(e.target).set(e.propertyName,e)},r.prototype.addTransformMetadata=function(e){this._transformMetadatas.has(e.target)||this._transformMetadatas.set(e.target,new Map),this._transformMetadatas.get(e.target).has(e.propertyName)||this._transformMetadatas.get(e.target).set(e.propertyName,[]),this._transformMetadatas.get(e.target).get(e.propertyName).push(e)},r.prototype.addExposeMetadata=function(e){this._exposeMetadatas.has(e.target)||this._exposeMetadatas.set(e.target,new Map),this._exposeMetadatas.get(e.target).set(e.propertyName,e)},r.prototype.addExcludeMetadata=function(e){this._excludeMetadatas.has(e.target)||this._excludeMetadatas.set(e.target,new Map),this._excludeMetadatas.get(e.target).set(e.propertyName,e)},r.prototype.findTransformMetadatas=function(e,t,n){return this.findMetadatas(this._transformMetadatas,e,t).filter(function(i){return!i.options||i.options.toClassOnly===!0&&i.options.toPlainOnly===!0?!0:i.options.toClassOnly===!0?n===C.CLASS_TO_CLASS||n===C.PLAIN_TO_CLASS:i.options.toPlainOnly===!0?n===C.CLASS_TO_PLAIN:!0})},r.prototype.findExcludeMetadata=function(e,t){return this.findMetadata(this._excludeMetadatas,e,t)},r.prototype.findExposeMetadata=function(e,t){return this.findMetadata(this._exposeMetadatas,e,t)},r.prototype.findExposeMetadataByCustomName=function(e,t){return this.getExposedMetadatas(e).find(function(n){return n.options&&n.options.name===t})},r.prototype.findTypeMetadata=function(e,t){return this.findMetadata(this._typeMetadatas,e,t)},r.prototype.getStrategy=function(e){var t=this._excludeMetadatas.get(e),n=t&&t.get(void 0),i=this._exposeMetadatas.get(e),u=i&&i.get(void 0);return n&&u||!n&&!u?"none":n?"excludeAll":"exposeAll"},r.prototype.getExposedMetadatas=function(e){return this.getMetadata(this._exposeMetadatas,e)},r.prototype.getExcludedMetadatas=function(e){return this.getMetadata(this._excludeMetadatas,e)},r.prototype.getExposedProperties=function(e,t){return this.getExposedMetadatas(e).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?t===C.CLASS_TO_CLASS||t===C.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?t===C.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},r.prototype.getExcludedProperties=function(e,t){return this.getExcludedMetadatas(e).filter(function(n){return!n.options||n.options.toClassOnly===!0&&n.options.toPlainOnly===!0?!0:n.options.toClassOnly===!0?t===C.CLASS_TO_CLASS||t===C.PLAIN_TO_CLASS:n.options.toPlainOnly===!0?t===C.CLASS_TO_PLAIN:!0}).map(function(n){return n.propertyName})},r.prototype.clear=function(){this._typeMetadatas.clear(),this._exposeMetadatas.clear(),this._excludeMetadatas.clear(),this._ancestorsMap.clear()},r.prototype.getMetadata=function(e,t){var n=e.get(t),i;n&&(i=Array.from(n.values()).filter(function(v){return v.propertyName!==void 0}));for(var u=[],a=0,f=this.getAncestors(t);a<f.length;a++){var g=f[a],w=e.get(g);if(w){var p=Array.from(w.values()).filter(function(v){return v.propertyName!==void 0});u.push.apply(u,p)}}return u.concat(i||[])},r.prototype.findMetadata=function(e,t,n){var i=e.get(t);if(i){var u=i.get(n);if(u)return u}for(var a=0,f=this.getAncestors(t);a<f.length;a++){var g=f[a],w=e.get(g);if(w){var p=w.get(n);if(p)return p}}},r.prototype.findMetadatas=function(e,t,n){var i=e.get(t),u;i&&(u=i.get(n));for(var a=[],f=0,g=this.getAncestors(t);f<g.length;f++){var w=g[f],p=e.get(w);p&&p.has(n)&&a.push.apply(a,p.get(n))}return a.slice().reverse().concat((u||[]).slice().reverse())},r.prototype.getAncestors=function(e){if(!e)return[];if(!this._ancestorsMap.has(e)){for(var t=[],n=Object.getPrototypeOf(e.prototype.constructor);typeof n.prototype<"u";n=Object.getPrototypeOf(n.prototype.constructor))t.push(n);this._ancestorsMap.set(e,t)}return this._ancestorsMap.get(e)},r}(),U=new Tt;function Nt(){if(typeof globalThis<"u")return globalThis;if(typeof global<"u")return global;if(typeof window<"u")return window;if(typeof self<"u")return self}function Pt(r){return r!==null&&typeof r=="object"&&typeof r.then=="function"}var at=globalThis&&globalThis.__spreadArray||function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,u;n<i;n++)(u||!(n in e))&&(u||(u=Array.prototype.slice.call(e,0,n)),u[n]=e[n]);return r.concat(u||Array.prototype.slice.call(e))};function kt(r){var e=new r;return!(e instanceof Set)&&!("push"in e)?[]:e}var ae=function(){function r(e,t){this.transformationType=e,this.options=t,this.recursionStack=new Set}return r.prototype.transform=function(e,t,n,i,u,a){var f=this;if(a===void 0&&(a=0),Array.isArray(t)||t instanceof Set){var g=i&&this.transformationType===C.PLAIN_TO_CLASS?kt(i):[];return t.forEach(function(m,D){var L=e?e[D]:void 0;if(!f.options.enableCircularCheck||!f.isCircular(m)){var M=void 0;if(typeof n!="function"&&n&&n.options&&n.options.discriminator&&n.options.discriminator.property&&n.options.discriminator.subTypes){if(f.transformationType===C.PLAIN_TO_CLASS){M=n.options.discriminator.subTypes.find(function(Q){return Q.name===m[n.options.discriminator.property]});var J={newObject:g,object:m,property:void 0},E=n.typeFunction(J);M===void 0?M=E:M=M.value,n.options.keepDiscriminatorProperty||delete m[n.options.discriminator.property]}f.transformationType===C.CLASS_TO_CLASS&&(M=m.constructor),f.transformationType===C.CLASS_TO_PLAIN&&(m[n.options.discriminator.property]=n.options.discriminator.subTypes.find(function(Q){return Q.value===m.constructor}).name)}else M=n;var B=f.transform(L,m,M,void 0,m instanceof Map,a+1);g instanceof Set?g.add(B):g.push(B)}else f.transformationType===C.CLASS_TO_CLASS&&(g instanceof Set?g.add(m):g.push(m))}),g}else{if(n===String&&!u)return t==null?t:String(t);if(n===Number&&!u)return t==null?t:Number(t);if(n===Boolean&&!u)return t==null?t:!!t;if((n===Date||t instanceof Date)&&!u)return t instanceof Date?new Date(t.valueOf()):t==null?t:new Date(t);if(Nt().Buffer&&(n===Buffer||t instanceof Buffer)&&!u)return t==null?t:Buffer.from(t);if(Pt(t)&&!u)return new Promise(function(m,D){t.then(function(L){return m(f.transform(void 0,L,n,void 0,void 0,a+1))},D)});if(!u&&t!==null&&typeof t=="object"&&typeof t.then=="function")return t;if(typeof t=="object"&&t!==null){!n&&t.constructor!==Object&&(!Array.isArray(t)&&t.constructor===Array||(n=t.constructor)),!n&&e&&(n=e.constructor),this.options.enableCircularCheck&&this.recursionStack.add(t);var w=this.getKeys(n,t,u),p=e||{};!e&&(this.transformationType===C.PLAIN_TO_CLASS||this.transformationType===C.CLASS_TO_CLASS)&&(u?p=new Map:n?p=new n:p={});for(var v=function(m){if(m==="__proto__"||m==="constructor")return"continue";var D=m,L=m,M=m;if(!h.options.ignoreDecorators&&n){if(h.transformationType===C.PLAIN_TO_CLASS){var J=U.findExposeMetadataByCustomName(n,m);J&&(M=J.propertyName,L=J.propertyName)}else if(h.transformationType===C.CLASS_TO_PLAIN||h.transformationType===C.CLASS_TO_CLASS){var J=U.findExposeMetadata(n,m);J&&J.options&&J.options.name&&(L=J.options.name)}}var E=void 0;h.transformationType===C.PLAIN_TO_CLASS?E=t[D]:t instanceof Map?E=t.get(D):t[D]instanceof Function?E=t[D]():E=t[D];var B=void 0,Q=E instanceof Map;if(n&&u)B=n;else if(n){var P=U.findTypeMetadata(n,M);if(P){var et={newObject:p,object:t,property:M},qe=P.typeFunction?P.typeFunction(et):P.reflectedType;P.options&&P.options.discriminator&&P.options.discriminator.property&&P.options.discriminator.subTypes?t[D]instanceof Array?B=P:(h.transformationType===C.PLAIN_TO_CLASS&&(B=P.options.discriminator.subTypes.find(function(X){if(E&&E instanceof Object&&P.options.discriminator.property in E)return X.name===E[P.options.discriminator.property]}),B===void 0?B=qe:B=B.value,P.options.keepDiscriminatorProperty||E&&E instanceof Object&&P.options.discriminator.property in E&&delete E[P.options.discriminator.property]),h.transformationType===C.CLASS_TO_CLASS&&(B=E.constructor),h.transformationType===C.CLASS_TO_PLAIN&&E&&(E[P.options.discriminator.property]=P.options.discriminator.subTypes.find(function(X){return X.value===E.constructor}).name)):B=qe,Q=Q||P.reflectedType===Map}else if(h.options.targetMaps)h.options.targetMaps.filter(function(X){return X.target===n&&!!X.properties[M]}).forEach(function(X){return B=X.properties[M]});else if(h.options.enableImplicitConversion&&h.transformationType===C.PLAIN_TO_CLASS){var Je=Reflect.getMetadata("design:type",n.prototype,M);Je&&(B=Je)}}var te=Array.isArray(t[D])?h.getReflectedType(n,M):void 0,we=e?e[D]:void 0;if(p.constructor.prototype){var fe=Object.getOwnPropertyDescriptor(p.constructor.prototype,L);if((h.transformationType===C.PLAIN_TO_CLASS||h.transformationType===C.CLASS_TO_CLASS)&&(fe&&!fe.set||p[L]instanceof Function))return"continue"}if(!h.options.enableCircularCheck||!h.isCircular(E)){var ie=h.transformationType===C.PLAIN_TO_CLASS?L:m,R=void 0;h.transformationType===C.CLASS_TO_PLAIN?(R=t[ie],R=h.applyCustomTransformations(R,n,ie,t,h.transformationType),R=t[ie]===R?E:R,R=h.transform(we,R,B,te,Q,a+1)):E===void 0&&h.options.exposeDefaultValues?R=p[L]:(R=h.transform(we,E,B,te,Q,a+1),R=h.applyCustomTransformations(R,n,ie,t,h.transformationType)),(R!==void 0||h.options.exposeUnsetFields)&&(p instanceof Map?p.set(L,R):p[L]=R)}else if(h.transformationType===C.CLASS_TO_CLASS){var R=E;R=h.applyCustomTransformations(R,n,m,t,h.transformationType),(R!==void 0||h.options.exposeUnsetFields)&&(p instanceof Map?p.set(L,R):p[L]=R)}},h=this,T=0,x=w;T<x.length;T++){var G=x[T];v(G)}return this.options.enableCircularCheck&&this.recursionStack.delete(t),p}else return t}},r.prototype.applyCustomTransformations=function(e,t,n,i,u){var a=this,f=U.findTransformMetadatas(t,n,this.transformationType);return this.options.version!==void 0&&(f=f.filter(function(g){return g.options?a.checkVersion(g.options.since,g.options.until):!0})),this.options.groups&&this.options.groups.length?f=f.filter(function(g){return g.options?a.checkGroups(g.options.groups):!0}):f=f.filter(function(g){return!g.options||!g.options.groups||!g.options.groups.length}),f.forEach(function(g){e=g.transformFn({value:e,key:n,obj:i,type:u,options:a.options})}),e},r.prototype.isCircular=function(e){return this.recursionStack.has(e)},r.prototype.getReflectedType=function(e,t){if(e){var n=U.findTypeMetadata(e,t);return n?n.reflectedType:void 0}},r.prototype.getKeys=function(e,t,n){var i=this,u=U.getStrategy(e);u==="none"&&(u=this.options.strategy||"exposeAll");var a=[];if((u==="exposeAll"||n)&&(t instanceof Map?a=Array.from(t.keys()):a=Object.keys(t)),n)return a;if(this.options.ignoreDecorators&&this.options.excludeExtraneousValues&&e){var f=U.getExposedProperties(e,this.transformationType),g=U.getExcludedProperties(e,this.transformationType);a=at(at([],f,!0),g,!0)}if(!this.options.ignoreDecorators&&e){var f=U.getExposedProperties(e,this.transformationType);this.transformationType===C.PLAIN_TO_CLASS&&(f=f.map(function(v){var h=U.findExposeMetadata(e,v);return h&&h.options&&h.options.name?h.options.name:v})),this.options.excludeExtraneousValues?a=f:a=a.concat(f);var w=U.getExcludedProperties(e,this.transformationType);w.length>0&&(a=a.filter(function(v){return!w.includes(v)})),this.options.version!==void 0&&(a=a.filter(function(v){var h=U.findExposeMetadata(e,v);return!h||!h.options?!0:i.checkVersion(h.options.since,h.options.until)})),this.options.groups&&this.options.groups.length?a=a.filter(function(v){var h=U.findExposeMetadata(e,v);return!h||!h.options?!0:i.checkGroups(h.options.groups)}):a=a.filter(function(v){var h=U.findExposeMetadata(e,v);return!h||!h.options||!h.options.groups||!h.options.groups.length})}return this.options.excludePrefixes&&this.options.excludePrefixes.length&&(a=a.filter(function(p){return i.options.excludePrefixes.every(function(v){return p.substr(0,v.length)!==v})})),a=a.filter(function(p,v,h){return h.indexOf(p)===v}),a},r.prototype.checkVersion=function(e,t){var n=!0;return n&&e&&(n=this.options.version>=e),n&&t&&(n=this.options.version<t),n},r.prototype.checkGroups=function(e){return e?this.options.groups.some(function(t){return e.includes(t)}):!0},r}(),ce={enableCircularCheck:!1,enableImplicitConversion:!1,excludeExtraneousValues:!1,excludePrefixes:void 0,exposeDefaultValues:!1,exposeUnsetFields:!0,groups:void 0,ignoreDecorators:!1,strategy:void 0,targetMaps:void 0,version:void 0},q=globalThis&&globalThis.__assign||function(){return q=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},q.apply(this,arguments)},Bt=function(){function r(){}return r.prototype.instanceToPlain=function(e,t){var n=new ae(C.CLASS_TO_PLAIN,q(q({},ce),t));return n.transform(void 0,e,void 0,void 0,void 0,void 0)},r.prototype.classToPlainFromExist=function(e,t,n){var i=new ae(C.CLASS_TO_PLAIN,q(q({},ce),n));return i.transform(t,e,void 0,void 0,void 0,void 0)},r.prototype.plainToInstance=function(e,t,n){var i=new ae(C.PLAIN_TO_CLASS,q(q({},ce),n));return i.transform(void 0,t,e,void 0,void 0,void 0)},r.prototype.plainToClassFromExist=function(e,t,n){var i=new ae(C.PLAIN_TO_CLASS,q(q({},ce),n));return i.transform(e,t,void 0,void 0,void 0,void 0)},r.prototype.instanceToInstance=function(e,t){var n=new ae(C.CLASS_TO_CLASS,q(q({},ce),t));return n.transform(void 0,e,void 0,void 0,void 0,void 0)},r.prototype.classToClassFromExist=function(e,t,n){var i=new ae(C.CLASS_TO_CLASS,q(q({},ce),n));return i.transform(t,e,void 0,void 0,void 0,void 0)},r.prototype.serialize=function(e,t){return JSON.stringify(this.instanceToPlain(e,t))},r.prototype.deserialize=function(e,t,n){var i=JSON.parse(t);return this.plainToInstance(e,i,n)},r.prototype.deserializeArray=function(e,t,n){var i=JSON.parse(t);return this.plainToInstance(e,i,n)},r}();function Ye(r,e){return e===void 0&&(e={}),function(t,n){var i=Reflect.getMetadata("design:type",t,n);U.addTypeMetadata({target:t.constructor,propertyName:n,reflectedType:i,typeFunction:r,options:e})}}var ct=new Bt;function jt(r,e){return ct.instanceToPlain(r,e)}function $t(r,e,t){return ct.plainToInstance(r,e,t)}/*! ***************************************************************************** | ||
Copyright (C) Microsoft. All rights reserved. | ||
@@ -21,3 +21,3 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
and limitations under the License. | ||
***************************************************************************** */var ct;(function(r){(function(e){var t=typeof ie=="object"?ie:typeof self=="object"?self:typeof this=="object"?this:Function("return this;")(),n=i(r);typeof t.Reflect>"u"?t.Reflect=r:n=i(t.Reflect,n),e(n);function i(u,a){return function(f,g){typeof u[f]!="function"&&Object.defineProperty(u,f,{configurable:!0,writable:!0,value:g}),a&&a(f,g)}}})(function(e){var t=Object.prototype.hasOwnProperty,n=typeof Symbol=="function",i=n&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",u=n&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",f={__proto__:[]}instanceof Array,g=!a&&!f,w={create:a?function(){return tt(Object.create(null))}:f?function(){return tt({__proto__:null})}:function(){return tt({})},has:g?function(s,o){return t.call(s,o)}:function(s,o){return o in s},get:g?function(s,o){return t.call(s,o)?s[o]:void 0}:function(s,o){return s[o]}},l=Object.getPrototypeOf(Function),v=typeof process=="object"&&process.env&&process.env.REFLECT_METADATA_USE_MAP_POLYFILL==="true",h=!v&&typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:nn(),T=!v&&typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:rn(),x=!v&&typeof WeakMap=="function"?WeakMap:sn(),G=new x;function m(s,o,c,d){if(k(c)){if(!bt(s))throw new TypeError;if(!Ct(o))throw new TypeError;return We(s,o)}else{if(!bt(s))throw new TypeError;if(!j(o))throw new TypeError;if(!j(d)&&!k(d)&&!fe(d))throw new TypeError;return fe(d)&&(d=void 0),c=V(c),qe(s,o,c,d)}}e("decorate",m);function D(s,o){function c(d,y){if(!j(d))throw new TypeError;if(!k(y)&&!Qt(y))throw new TypeError;X(s,o,d,y)}return c}e("metadata",D);function L(s,o,c,d){if(!j(c))throw new TypeError;return k(d)||(d=V(d)),X(s,o,c,d)}e("defineMetadata",L);function M(s,o,c){if(!j(o))throw new TypeError;return k(c)||(c=V(c)),ye(s,o,c)}e("hasMetadata",M);function J(s,o,c){if(!j(o))throw new TypeError;return k(c)||(c=V(c)),ue(s,o,c)}e("hasOwnMetadata",J);function E(s,o,c){if(!j(o))throw new TypeError;return k(c)||(c=V(c)),se(s,o,c)}e("getMetadata",E);function B(s,o,c){if(!j(o))throw new TypeError;return k(c)||(c=V(c)),R(s,o,c)}e("getOwnMetadata",B);function Q(s,o){if(!j(s))throw new TypeError;return k(o)||(o=V(o)),_t(s,o)}e("getMetadataKeys",Q);function P(s,o){if(!j(s))throw new TypeError;return k(o)||(o=V(o)),St(s,o)}e("getOwnMetadataKeys",P);function Ve(s,o,c){if(!j(o))throw new TypeError;k(c)||(c=V(c));var d=ee(o,c,!1);if(k(d)||!d.delete(s))return!1;if(d.size>0)return!0;var y=G.get(o);return y.delete(c),y.size>0||G.delete(o),!0}e("deleteMetadata",Ve);function We(s,o){for(var c=s.length-1;c>=0;--c){var d=s[c],y=d(o);if(!k(y)&&!fe(y)){if(!Ct(y))throw new TypeError;o=y}}return o}function qe(s,o,c,d){for(var y=s.length-1;y>=0;--y){var $=s[y],S=$(o,c,d);if(!k(S)&&!fe(S)){if(!j(S))throw new TypeError;d=S}}return d}function ee(s,o,c){var d=G.get(s);if(k(d)){if(!c)return;d=new h,G.set(s,d)}var y=d.get(o);if(k(y)){if(!c)return;y=new h,d.set(o,y)}return y}function ye(s,o,c){var d=ue(s,o,c);if(d)return!0;var y=et(o);return fe(y)?!1:ye(s,y,c)}function ue(s,o,c){var d=ee(o,c,!1);return k(d)?!1:Xt(d.has(s))}function se(s,o,c){var d=ue(s,o,c);if(d)return R(s,o,c);var y=et(o);if(!fe(y))return se(s,y,c)}function R(s,o,c){var d=ee(o,c,!1);if(!k(d))return d.get(s)}function X(s,o,c,d){var y=ee(c,d,!0);y.set(s,o)}function _t(s,o){var c=St(s,o),d=et(s);if(d===null)return c;var y=_t(d,o);if(y.length<=0)return c;if(c.length<=0)return y;for(var $=new T,S=[],C=0,_=c;C<_.length;C++){var A=_[C],O=$.has(A);O||($.add(A),S.push(A))}for(var te=0,At=y;te<At.length;te++){var A=At[te],O=$.has(A);O||($.add(A),S.push(A))}return S}function St(s,o){var c=[],d=ee(s,o,!1);if(k(d))return c;for(var y=d.keys(),$=Kt(y),S=0;;){var C=en($);if(!C)return c.length=S,c;var _=Vt(C);try{c[S]=_}catch(A){try{tn($)}finally{throw A}}S++}}function Mt(s){if(s===null)return 1;switch(typeof s){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return s===null?1:6;default:return 6}}function k(s){return s===void 0}function fe(s){return s===null}function zt(s){return typeof s=="symbol"}function j(s){return typeof s=="object"?s!==null:typeof s=="function"}function Ht(s,o){switch(Mt(s)){case 0:return s;case 1:return s;case 2:return s;case 3:return s;case 4:return s;case 5:return s}var c=o===3?"string":o===5?"number":"default",d=Et(s,i);if(d!==void 0){var y=d.call(s,c);if(j(y))throw new TypeError;return y}return Yt(s,c==="default"?"number":c)}function Yt(s,o){if(o==="string"){var c=s.toString;if(de(c)){var d=c.call(s);if(!j(d))return d}var y=s.valueOf;if(de(y)){var d=y.call(s);if(!j(d))return d}}else{var y=s.valueOf;if(de(y)){var d=y.call(s);if(!j(d))return d}var $=s.toString;if(de($)){var d=$.call(s);if(!j(d))return d}}throw new TypeError}function Xt(s){return!!s}function Zt(s){return""+s}function V(s){var o=Ht(s,3);return zt(o)?o:Zt(o)}function bt(s){return Array.isArray?Array.isArray(s):s instanceof Object?s instanceof Array:Object.prototype.toString.call(s)==="[object Array]"}function de(s){return typeof s=="function"}function Ct(s){return typeof s=="function"}function Qt(s){switch(Mt(s)){case 3:return!0;case 4:return!0;default:return!1}}function Et(s,o){var c=s[o];if(c!=null){if(!de(c))throw new TypeError;return c}}function Kt(s){var o=Et(s,u);if(!de(o))throw new TypeError;var c=o.call(s);if(!j(c))throw new TypeError;return c}function Vt(s){return s.value}function en(s){var o=s.next();return o.done?!1:o}function tn(s){var o=s.return;o&&o.call(s)}function et(s){var o=Object.getPrototypeOf(s);if(typeof s!="function"||s===l||o!==l)return o;var c=s.prototype,d=c&&Object.getPrototypeOf(c);if(d==null||d===Object.prototype)return o;var y=d.constructor;return typeof y!="function"||y===s?o:y}function nn(){var s={},o=[],c=function(){function S(C,_,A){this._index=0,this._keys=C,this._values=_,this._selector=A}return S.prototype["@@iterator"]=function(){return this},S.prototype[u]=function(){return this},S.prototype.next=function(){var C=this._index;if(C>=0&&C<this._keys.length){var _=this._selector(this._keys[C],this._values[C]);return C+1>=this._keys.length?(this._index=-1,this._keys=o,this._values=o):this._index++,{value:_,done:!1}}return{value:void 0,done:!0}},S.prototype.throw=function(C){throw this._index>=0&&(this._index=-1,this._keys=o,this._values=o),C},S.prototype.return=function(C){return this._index>=0&&(this._index=-1,this._keys=o,this._values=o),{value:C,done:!0}},S}();return function(){function S(){this._keys=[],this._values=[],this._cacheKey=s,this._cacheIndex=-2}return Object.defineProperty(S.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),S.prototype.has=function(C){return this._find(C,!1)>=0},S.prototype.get=function(C){var _=this._find(C,!1);return _>=0?this._values[_]:void 0},S.prototype.set=function(C,_){var A=this._find(C,!0);return this._values[A]=_,this},S.prototype.delete=function(C){var _=this._find(C,!1);if(_>=0){for(var A=this._keys.length,O=_+1;O<A;O++)this._keys[O-1]=this._keys[O],this._values[O-1]=this._values[O];return this._keys.length--,this._values.length--,C===this._cacheKey&&(this._cacheKey=s,this._cacheIndex=-2),!0}return!1},S.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=s,this._cacheIndex=-2},S.prototype.keys=function(){return new c(this._keys,this._values,d)},S.prototype.values=function(){return new c(this._keys,this._values,y)},S.prototype.entries=function(){return new c(this._keys,this._values,$)},S.prototype["@@iterator"]=function(){return this.entries()},S.prototype[u]=function(){return this.entries()},S.prototype._find=function(C,_){return this._cacheKey!==C&&(this._cacheIndex=this._keys.indexOf(this._cacheKey=C)),this._cacheIndex<0&&_&&(this._cacheIndex=this._keys.length,this._keys.push(C),this._values.push(void 0)),this._cacheIndex},S}();function d(S,C){return S}function y(S,C){return C}function $(S,C){return[S,C]}}function rn(){return function(){function s(){this._map=new h}return Object.defineProperty(s.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),s.prototype.has=function(o){return this._map.has(o)},s.prototype.add=function(o){return this._map.set(o,o),this},s.prototype.delete=function(o){return this._map.delete(o)},s.prototype.clear=function(){this._map.clear()},s.prototype.keys=function(){return this._map.keys()},s.prototype.values=function(){return this._map.values()},s.prototype.entries=function(){return this._map.entries()},s.prototype["@@iterator"]=function(){return this.keys()},s.prototype[u]=function(){return this.keys()},s}()}function sn(){var s=16,o=w.create(),c=d();return function(){function _(){this._key=d()}return _.prototype.has=function(A){var O=y(A,!1);return O!==void 0?w.has(O,this._key):!1},_.prototype.get=function(A){var O=y(A,!1);return O!==void 0?w.get(O,this._key):void 0},_.prototype.set=function(A,O){var te=y(A,!0);return te[this._key]=O,this},_.prototype.delete=function(A){var O=y(A,!1);return O!==void 0?delete O[this._key]:!1},_.prototype.clear=function(){this._key=d()},_}();function d(){var _;do _="@@WeakMap@@"+C();while(w.has(o,_));return o[_]=!0,_}function y(_,A){if(!t.call(_,c)){if(!A)return;Object.defineProperty(_,c,{value:w.create()})}return _[c]}function $(_,A){for(var O=0;O<A;++O)_[O]=Math.random()*255|0;return _}function S(_){return typeof Uint8Array=="function"?typeof crypto<"u"?crypto.getRandomValues(new Uint8Array(_)):typeof msCrypto<"u"?msCrypto.getRandomValues(new Uint8Array(_)):$(new Uint8Array(_),_):$(new Array(_),_)}function C(){var _=S(s);_[6]=_[6]&79|64,_[8]=_[8]&191|128;for(var A="",O=0;O<s;++O){var te=_[O];(O===4||O===6||O===8)&&(A+="-"),te<16&&(A+="0"),A+=te.toString(16).toLowerCase()}return A}}function tt(s){return s.__=void 0,delete s.__,s}})})(ct||(ct={}));var jt=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Ye=(r,e,t,n)=>{for(var i=n>1?void 0:n?$t(e,t):e,u=r.length-1,a;u>=0;u--)(a=r[u])&&(i=(n?a(e,t,i):a(i))||i);return n&&i&&jt(e,t,i),i};const Y=0,I=1,ut=4294967295,he=3;class _e{constructor(e){Object.assign(this,e)}update(){var e,t,n,i,u;(e=this.ScalarCmd)==null||e.forEach((a,f)=>a.Index=f),(t=this.RotateCmd)==null||t.forEach((a,f)=>a.Index=f),(n=this.LinearCmd)==null||n.forEach((a,f)=>a.Index=f),(i=this.SensorReadCmd)==null||i.forEach((a,f)=>a.Index=f),(u=this.SensorSubscribeCmd)==null||u.forEach((a,f)=>a.Index=f)}}var ne=(r=>(r.Unknown="Unknown",r.Vibrate="Vibrate",r.Rotate="Rotate",r.Oscillate="Oscillate",r.Constrict="Constrict",r.Inflate="Inflate",r.Position="Position",r))(ne||{}),K=(r=>(r.Unknown="Unknown",r.Battery="Battery",r.RSSI="RSSI",r.Button="Button",r.Pressure="Pressure",r))(K||{});class ft{constructor(e){this.Index=0,Object.assign(this,e)}}class dt{constructor(e){this.Endpoints=e}}class ht{constructor(e){this.Index=0,Object.assign(this,e)}}class H{constructor(e){this.Id=e}get Type(){return this.constructor}toJSON(){return JSON.stringify(this.toProtocolFormat())}toProtocolFormat(){const e={};return e[this.constructor.Name]=kt(this),e}update(){}}class z extends H{constructor(e,t){super(t),this.DeviceIndex=e,this.Id=t}}class re extends H{constructor(e=Y){super(e),this.Id=e}}class le extends re{constructor(e=I){super(e),this.Id=e}}le.Name="Ok";class Xe extends H{constructor(e=I){super(e),this.Id=e}}Xe.Name="Ping";var W=(r=>(r[r.ERROR_UNKNOWN=0]="ERROR_UNKNOWN",r[r.ERROR_INIT=1]="ERROR_INIT",r[r.ERROR_PING=2]="ERROR_PING",r[r.ERROR_MSG=3]="ERROR_MSG",r[r.ERROR_DEVICE=4]="ERROR_DEVICE",r))(W||{});let Z=class extends H{constructor(e,t=0,n=I){super(n),this.ErrorMessage=e,this.ErrorCode=t,this.Id=n}get Schemversion(){return 0}};Z.Name="Error";class Se{constructor(e){Object.assign(this,e)}}Ye([He(()=>_e)],Se.prototype,"DeviceMessages",2);class Me extends H{constructor(e,t=I){super(t),this.Devices=e,this.Id=t}update(){for(const e of this.Devices)e.DeviceMessages.update()}}Me.Name="DeviceList",Ye([He(()=>Se)],Me.prototype,"Devices",2);class pe extends re{constructor(e){super(),Object.assign(this,e)}update(){this.DeviceMessages.update()}}pe.Name="DeviceAdded",Ye([He(()=>_e)],pe.prototype,"DeviceMessages",2);class be extends re{constructor(e){super(),this.DeviceIndex=e}}be.Name="DeviceRemoved";class Ce extends H{constructor(e=I){super(e),this.Id=e}}Ce.Name="RequestDeviceList";class Ee extends H{constructor(e=I){super(e),this.Id=e}}Ee.Name="StartScanning";class Ae extends H{constructor(e=I){super(e),this.Id=e}}Ae.Name="StopScanning";class Oe extends re{constructor(){super()}}Oe.Name="ScanningFinished";class xe extends H{constructor(e,t=0,n=I){super(n),this.ClientName=e,this.MessageVersion=t,this.Id=n}}xe.Name="RequestServerInfo";class Le extends re{constructor(e,t,n,i=I){super(),this.MessageVersion=e,this.MaxPingTime=t,this.ServerName=n,this.Id=i}}Le.Name="ServerInfo";class Re extends z{constructor(e=-1,t=I){super(e,t),this.DeviceIndex=e,this.Id=t}}Re.Name="StopDeviceCmd";class Ie extends H{constructor(e=I){super(e),this.Id=e}}Ie.Name="StopAllDevices";class ge{constructor(e){this.Index=e}}class De extends ge{constructor(e,t,n){super(e),this.Scalar=t,this.ActuatorType=n}}class me extends z{constructor(e,t=-1,n=I){super(t,n),this.Scalars=e,this.DeviceIndex=t,this.Id=n}}me.Name="ScalarCmd";class Ze extends ge{constructor(e,t,n){super(e),this.Speed=t,this.Clockwise=n}}const lt=class Ot extends z{constructor(e,t=-1,n=I){super(t,n),this.Rotations=e,this.DeviceIndex=t,this.Id=n}static Create(e,t){const n=new Array;let i=0;for(const[u,a]of t)n.push(new Ze(i,u,a)),++i;return new Ot(n,e)}};lt.Name="RotateCmd";let Te=lt;class Qe extends ge{constructor(e,t,n){super(e),this.Position=t,this.Duration=n}}const pt=class xt extends z{constructor(e,t=-1,n=I){super(t,n),this.Vectors=e,this.DeviceIndex=t,this.Id=n}static Create(e,t){const n=new Array;let i=0;for(const u of t)n.push(new Qe(i,u[0],u[1])),++i;return new xt(n,e)}};pt.Name="LinearCmd";let Ne=pt;class Pe extends z{constructor(e,t,n,i=I){super(e,i),this.DeviceIndex=e,this.SensorIndex=t,this.SensorType=n,this.Id=i}}Pe.Name="SensorReadCmd";class ke extends z{constructor(e,t,n,i,u=I){super(e,u),this.DeviceIndex=e,this.SensorIndex=t,this.SensorType=n,this.Data=i,this.Id=u}}ke.Name="SensorReading";class Be extends z{constructor(e,t,n,i,u=I){super(e,u),this.DeviceIndex=e,this.Endpoint=t,this.ExpectedLength=n,this.Timeout=i,this.Id=u}}Be.Name="RawReadCmd";class je extends z{constructor(e,t,n,i,u=I){super(e,u),this.DeviceIndex=e,this.Endpoint=t,this.Data=n,this.WriteWithResponse=i,this.Id=u}}je.Name="RawWriteCmd";class $e extends z{constructor(e,t,n=I){super(e,n),this.DeviceIndex=e,this.Endpoint=t,this.Id=n}}$e.Name="RawSubscribeCmd";class Fe extends z{constructor(e,t,n=I){super(e,n),this.DeviceIndex=e,this.Endpoint=t,this.Id=n}}Fe.Name="RawUnsubscribeCmd";class Ge extends z{constructor(e,t,n,i=I){super(e,i),this.DeviceIndex=e,this.Endpoint=t,this.Data=n,this.Id=i}}Ge.Name="RawReading";const Ft=Object.freeze(Object.defineProperty({__proto__:null,ActuatorType:ne,ButtplugDeviceMessage:z,ButtplugMessage:H,ButtplugSystemMessage:re,DEFAULT_MESSAGE_ID:I,DeviceAdded:pe,DeviceInfo:Se,DeviceList:Me,DeviceRemoved:be,Error:Z,ErrorClass:W,GenericDeviceMessageAttributes:ft,GenericMessageSubcommand:ge,LinearCmd:Ne,MAX_ID:ut,MESSAGE_SPEC_VERSION:he,MessageAttributes:_e,Ok:le,Ping:Xe,RawDeviceMessageAttributes:dt,RawReadCmd:Be,RawReading:Ge,RawSubscribeCmd:$e,RawUnsubscribeCmd:Fe,RawWriteCmd:je,RequestDeviceList:Ce,RequestServerInfo:xe,RotateCmd:Te,RotateSubcommand:Ze,SYSTEM_MESSAGE_ID:Y,ScalarCmd:me,ScalarSubcommand:De,ScanningFinished:Oe,SensorDeviceMessageAttributes:ht,SensorReadCmd:Pe,SensorReading:ke,SensorType:K,ServerInfo:Le,StartScanning:Ee,StopAllDevices:Ie,StopDeviceCmd:Re,StopScanning:Ae,VectorSubcommand:Qe},Symbol.toStringTag,{value:"Module"}));/*! | ||
***************************************************************************** */var ut;(function(r){(function(e){var t=typeof oe=="object"?oe:typeof self=="object"?self:typeof this=="object"?this:Function("return this;")(),n=i(r);typeof t.Reflect>"u"?t.Reflect=r:n=i(t.Reflect,n),e(n);function i(u,a){return function(f,g){typeof u[f]!="function"&&Object.defineProperty(u,f,{configurable:!0,writable:!0,value:g}),a&&a(f,g)}}})(function(e){var t=Object.prototype.hasOwnProperty,n=typeof Symbol=="function",i=n&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",u=n&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",f={__proto__:[]}instanceof Array,g=!a&&!f,w={create:a?function(){return nt(Object.create(null))}:f?function(){return nt({__proto__:null})}:function(){return nt({})},has:g?function(s,o){return t.call(s,o)}:function(s,o){return o in s},get:g?function(s,o){return t.call(s,o)?s[o]:void 0}:function(s,o){return s[o]}},p=Object.getPrototypeOf(Function),v=typeof process=="object"&&process.env&&process.env.REFLECT_METADATA_USE_MAP_POLYFILL==="true",h=!v&&typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:rn(),T=!v&&typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:sn(),x=!v&&typeof WeakMap=="function"?WeakMap:on(),G=new x;function m(s,o,c,d){if(k(c)){if(!Et(s))throw new TypeError;if(!At(o))throw new TypeError;return qe(s,o)}else{if(!Et(s))throw new TypeError;if(!j(o))throw new TypeError;if(!j(d)&&!k(d)&&!de(d))throw new TypeError;return de(d)&&(d=void 0),c=V(c),Je(s,o,c,d)}}e("decorate",m);function D(s,o){function c(d,y){if(!j(d))throw new TypeError;if(!k(y)&&!Kt(y))throw new TypeError;X(s,o,d,y)}return c}e("metadata",D);function L(s,o,c,d){if(!j(c))throw new TypeError;return k(d)||(d=V(d)),X(s,o,c,d)}e("defineMetadata",L);function M(s,o,c){if(!j(o))throw new TypeError;return k(c)||(c=V(c)),we(s,o,c)}e("hasMetadata",M);function J(s,o,c){if(!j(o))throw new TypeError;return k(c)||(c=V(c)),fe(s,o,c)}e("hasOwnMetadata",J);function E(s,o,c){if(!j(o))throw new TypeError;return k(c)||(c=V(c)),ie(s,o,c)}e("getMetadata",E);function B(s,o,c){if(!j(o))throw new TypeError;return k(c)||(c=V(c)),R(s,o,c)}e("getOwnMetadata",B);function Q(s,o){if(!j(s))throw new TypeError;return k(o)||(o=V(o)),Mt(s,o)}e("getMetadataKeys",Q);function P(s,o){if(!j(s))throw new TypeError;return k(o)||(o=V(o)),Ct(s,o)}e("getOwnMetadataKeys",P);function et(s,o,c){if(!j(o))throw new TypeError;k(c)||(c=V(c));var d=te(o,c,!1);if(k(d)||!d.delete(s))return!1;if(d.size>0)return!0;var y=G.get(o);return y.delete(c),y.size>0||G.delete(o),!0}e("deleteMetadata",et);function qe(s,o){for(var c=s.length-1;c>=0;--c){var d=s[c],y=d(o);if(!k(y)&&!de(y)){if(!At(y))throw new TypeError;o=y}}return o}function Je(s,o,c,d){for(var y=s.length-1;y>=0;--y){var $=s[y],S=$(o,c,d);if(!k(S)&&!de(S)){if(!j(S))throw new TypeError;d=S}}return d}function te(s,o,c){var d=G.get(s);if(k(d)){if(!c)return;d=new h,G.set(s,d)}var y=d.get(o);if(k(y)){if(!c)return;y=new h,d.set(o,y)}return y}function we(s,o,c){var d=fe(s,o,c);if(d)return!0;var y=tt(o);return de(y)?!1:we(s,y,c)}function fe(s,o,c){var d=te(o,c,!1);return k(d)?!1:Zt(d.has(s))}function ie(s,o,c){var d=fe(s,o,c);if(d)return R(s,o,c);var y=tt(o);if(!de(y))return ie(s,y,c)}function R(s,o,c){var d=te(o,c,!1);if(!k(d))return d.get(s)}function X(s,o,c,d){var y=te(c,d,!0);y.set(s,o)}function Mt(s,o){var c=Ct(s,o),d=tt(s);if(d===null)return c;var y=Mt(d,o);if(y.length<=0)return c;if(c.length<=0)return y;for(var $=new T,S=[],b=0,_=c;b<_.length;b++){var A=_[b],O=$.has(A);O||($.add(A),S.push(A))}for(var ne=0,xt=y;ne<xt.length;ne++){var A=xt[ne],O=$.has(A);O||($.add(A),S.push(A))}return S}function Ct(s,o){var c=[],d=te(s,o,!1);if(k(d))return c;for(var y=d.keys(),$=Vt(y),S=0;;){var b=tn($);if(!b)return c.length=S,c;var _=en(b);try{c[S]=_}catch(A){try{nn($)}finally{throw A}}S++}}function bt(s){if(s===null)return 1;switch(typeof s){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return s===null?1:6;default:return 6}}function k(s){return s===void 0}function de(s){return s===null}function Ht(s){return typeof s=="symbol"}function j(s){return typeof s=="object"?s!==null:typeof s=="function"}function Yt(s,o){switch(bt(s)){case 0:return s;case 1:return s;case 2:return s;case 3:return s;case 4:return s;case 5:return s}var c=o===3?"string":o===5?"number":"default",d=Ot(s,i);if(d!==void 0){var y=d.call(s,c);if(j(y))throw new TypeError;return y}return Xt(s,c==="default"?"number":c)}function Xt(s,o){if(o==="string"){var c=s.toString;if(he(c)){var d=c.call(s);if(!j(d))return d}var y=s.valueOf;if(he(y)){var d=y.call(s);if(!j(d))return d}}else{var y=s.valueOf;if(he(y)){var d=y.call(s);if(!j(d))return d}var $=s.toString;if(he($)){var d=$.call(s);if(!j(d))return d}}throw new TypeError}function Zt(s){return!!s}function Qt(s){return""+s}function V(s){var o=Yt(s,3);return Ht(o)?o:Qt(o)}function Et(s){return Array.isArray?Array.isArray(s):s instanceof Object?s instanceof Array:Object.prototype.toString.call(s)==="[object Array]"}function he(s){return typeof s=="function"}function At(s){return typeof s=="function"}function Kt(s){switch(bt(s)){case 3:return!0;case 4:return!0;default:return!1}}function Ot(s,o){var c=s[o];if(c!=null){if(!he(c))throw new TypeError;return c}}function Vt(s){var o=Ot(s,u);if(!he(o))throw new TypeError;var c=o.call(s);if(!j(c))throw new TypeError;return c}function en(s){return s.value}function tn(s){var o=s.next();return o.done?!1:o}function nn(s){var o=s.return;o&&o.call(s)}function tt(s){var o=Object.getPrototypeOf(s);if(typeof s!="function"||s===p||o!==p)return o;var c=s.prototype,d=c&&Object.getPrototypeOf(c);if(d==null||d===Object.prototype)return o;var y=d.constructor;return typeof y!="function"||y===s?o:y}function rn(){var s={},o=[],c=function(){function S(b,_,A){this._index=0,this._keys=b,this._values=_,this._selector=A}return S.prototype["@@iterator"]=function(){return this},S.prototype[u]=function(){return this},S.prototype.next=function(){var b=this._index;if(b>=0&&b<this._keys.length){var _=this._selector(this._keys[b],this._values[b]);return b+1>=this._keys.length?(this._index=-1,this._keys=o,this._values=o):this._index++,{value:_,done:!1}}return{value:void 0,done:!0}},S.prototype.throw=function(b){throw this._index>=0&&(this._index=-1,this._keys=o,this._values=o),b},S.prototype.return=function(b){return this._index>=0&&(this._index=-1,this._keys=o,this._values=o),{value:b,done:!0}},S}();return function(){function S(){this._keys=[],this._values=[],this._cacheKey=s,this._cacheIndex=-2}return Object.defineProperty(S.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),S.prototype.has=function(b){return this._find(b,!1)>=0},S.prototype.get=function(b){var _=this._find(b,!1);return _>=0?this._values[_]:void 0},S.prototype.set=function(b,_){var A=this._find(b,!0);return this._values[A]=_,this},S.prototype.delete=function(b){var _=this._find(b,!1);if(_>=0){for(var A=this._keys.length,O=_+1;O<A;O++)this._keys[O-1]=this._keys[O],this._values[O-1]=this._values[O];return this._keys.length--,this._values.length--,b===this._cacheKey&&(this._cacheKey=s,this._cacheIndex=-2),!0}return!1},S.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=s,this._cacheIndex=-2},S.prototype.keys=function(){return new c(this._keys,this._values,d)},S.prototype.values=function(){return new c(this._keys,this._values,y)},S.prototype.entries=function(){return new c(this._keys,this._values,$)},S.prototype["@@iterator"]=function(){return this.entries()},S.prototype[u]=function(){return this.entries()},S.prototype._find=function(b,_){return this._cacheKey!==b&&(this._cacheIndex=this._keys.indexOf(this._cacheKey=b)),this._cacheIndex<0&&_&&(this._cacheIndex=this._keys.length,this._keys.push(b),this._values.push(void 0)),this._cacheIndex},S}();function d(S,b){return S}function y(S,b){return b}function $(S,b){return[S,b]}}function sn(){return function(){function s(){this._map=new h}return Object.defineProperty(s.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),s.prototype.has=function(o){return this._map.has(o)},s.prototype.add=function(o){return this._map.set(o,o),this},s.prototype.delete=function(o){return this._map.delete(o)},s.prototype.clear=function(){this._map.clear()},s.prototype.keys=function(){return this._map.keys()},s.prototype.values=function(){return this._map.values()},s.prototype.entries=function(){return this._map.entries()},s.prototype["@@iterator"]=function(){return this.keys()},s.prototype[u]=function(){return this.keys()},s}()}function on(){var s=16,o=w.create(),c=d();return function(){function _(){this._key=d()}return _.prototype.has=function(A){var O=y(A,!1);return O!==void 0?w.has(O,this._key):!1},_.prototype.get=function(A){var O=y(A,!1);return O!==void 0?w.get(O,this._key):void 0},_.prototype.set=function(A,O){var ne=y(A,!0);return ne[this._key]=O,this},_.prototype.delete=function(A){var O=y(A,!1);return O!==void 0?delete O[this._key]:!1},_.prototype.clear=function(){this._key=d()},_}();function d(){var _;do _="@@WeakMap@@"+b();while(w.has(o,_));return o[_]=!0,_}function y(_,A){if(!t.call(_,c)){if(!A)return;Object.defineProperty(_,c,{value:w.create()})}return _[c]}function $(_,A){for(var O=0;O<A;++O)_[O]=Math.random()*255|0;return _}function S(_){return typeof Uint8Array=="function"?typeof crypto<"u"?crypto.getRandomValues(new Uint8Array(_)):typeof msCrypto<"u"?msCrypto.getRandomValues(new Uint8Array(_)):$(new Uint8Array(_),_):$(new Array(_),_)}function b(){var _=S(s);_[6]=_[6]&79|64,_[8]=_[8]&191|128;for(var A="",O=0;O<s;++O){var ne=_[O];(O===4||O===6||O===8)&&(A+="-"),ne<16&&(A+="0"),A+=ne.toString(16).toLowerCase()}return A}}function nt(s){return s.__=void 0,delete s.__,s}})})(ut||(ut={}));var Ft=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Xe=(r,e,t,n)=>{for(var i=n>1?void 0:n?Gt(e,t):e,u=r.length-1,a;u>=0;u--)(a=r[u])&&(i=(n?a(e,t,i):a(i))||i);return n&&i&&Ft(e,t,i),i};const Y=0,I=1,ft=4294967295,le=3;class Se{constructor(e){Object.assign(this,e)}update(){var e,t,n,i,u;(e=this.ScalarCmd)==null||e.forEach((a,f)=>a.Index=f),(t=this.RotateCmd)==null||t.forEach((a,f)=>a.Index=f),(n=this.LinearCmd)==null||n.forEach((a,f)=>a.Index=f),(i=this.SensorReadCmd)==null||i.forEach((a,f)=>a.Index=f),(u=this.SensorSubscribeCmd)==null||u.forEach((a,f)=>a.Index=f)}}var re=(r=>(r.Unknown="Unknown",r.Vibrate="Vibrate",r.Rotate="Rotate",r.Oscillate="Oscillate",r.Constrict="Constrict",r.Inflate="Inflate",r.Position="Position",r))(re||{}),K=(r=>(r.Unknown="Unknown",r.Battery="Battery",r.RSSI="RSSI",r.Button="Button",r.Pressure="Pressure",r))(K||{});class dt{constructor(e){this.Index=0,Object.assign(this,e)}}class ht{constructor(e){this.Endpoints=e}}class lt{constructor(e){this.Index=0,Object.assign(this,e)}}class H{constructor(e){this.Id=e}get Type(){return this.constructor}toJSON(){return JSON.stringify(this.toProtocolFormat())}toProtocolFormat(){const e={};return e[this.constructor.Name]=jt(this),e}update(){}}class z extends H{constructor(e,t){super(t),this.DeviceIndex=e,this.Id=t}}class se extends H{constructor(e=Y){super(e),this.Id=e}}class pe extends se{constructor(e=I){super(e),this.Id=e}}pe.Name="Ok";class Ze extends H{constructor(e=I){super(e),this.Id=e}}Ze.Name="Ping";var W=(r=>(r[r.ERROR_UNKNOWN=0]="ERROR_UNKNOWN",r[r.ERROR_INIT=1]="ERROR_INIT",r[r.ERROR_PING=2]="ERROR_PING",r[r.ERROR_MSG=3]="ERROR_MSG",r[r.ERROR_DEVICE=4]="ERROR_DEVICE",r))(W||{});let Z=class extends H{constructor(e,t=0,n=I){super(n),this.ErrorMessage=e,this.ErrorCode=t,this.Id=n}get Schemversion(){return 0}};Z.Name="Error";class Me{constructor(e){Object.assign(this,e)}}Xe([Ye(()=>Se)],Me.prototype,"DeviceMessages",2);class Ce extends H{constructor(e,t=I){super(t),this.Devices=e,this.Id=t}update(){for(const e of this.Devices)e.DeviceMessages.update()}}Ce.Name="DeviceList",Xe([Ye(()=>Me)],Ce.prototype,"Devices",2);class ge extends se{constructor(e){super(),Object.assign(this,e)}update(){this.DeviceMessages.update()}}ge.Name="DeviceAdded",Xe([Ye(()=>Se)],ge.prototype,"DeviceMessages",2);class be extends se{constructor(e){super(),this.DeviceIndex=e}}be.Name="DeviceRemoved";class Ee extends H{constructor(e=I){super(e),this.Id=e}}Ee.Name="RequestDeviceList";class Ae extends H{constructor(e=I){super(e),this.Id=e}}Ae.Name="StartScanning";class Oe extends H{constructor(e=I){super(e),this.Id=e}}Oe.Name="StopScanning";class xe extends se{constructor(){super()}}xe.Name="ScanningFinished";class Le extends H{constructor(e,t=0,n=I){super(n),this.ClientName=e,this.MessageVersion=t,this.Id=n}}Le.Name="RequestServerInfo";class Re extends se{constructor(e,t,n,i=I){super(),this.MessageVersion=e,this.MaxPingTime=t,this.ServerName=n,this.Id=i}}Re.Name="ServerInfo";class Ie extends z{constructor(e=-1,t=I){super(e,t),this.DeviceIndex=e,this.Id=t}}Ie.Name="StopDeviceCmd";class De extends H{constructor(e=I){super(e),this.Id=e}}De.Name="StopAllDevices";class me{constructor(e){this.Index=e}}class Te extends me{constructor(e,t,n){super(e),this.Scalar=t,this.ActuatorType=n}}class ve extends z{constructor(e,t=-1,n=I){super(t,n),this.Scalars=e,this.DeviceIndex=t,this.Id=n}}ve.Name="ScalarCmd";class Qe extends me{constructor(e,t,n){super(e),this.Speed=t,this.Clockwise=n}}const pt=class Lt extends z{constructor(e,t=-1,n=I){super(t,n),this.Rotations=e,this.DeviceIndex=t,this.Id=n}static Create(e,t){const n=new Array;let i=0;for(const[u,a]of t)n.push(new Qe(i,u,a)),++i;return new Lt(n,e)}};pt.Name="RotateCmd";let Ne=pt;class Ke extends me{constructor(e,t,n){super(e),this.Position=t,this.Duration=n}}const gt=class Rt extends z{constructor(e,t=-1,n=I){super(t,n),this.Vectors=e,this.DeviceIndex=t,this.Id=n}static Create(e,t){const n=new Array;let i=0;for(const u of t)n.push(new Ke(i,u[0],u[1])),++i;return new Rt(n,e)}};gt.Name="LinearCmd";let Pe=gt;class ke extends z{constructor(e,t,n,i=I){super(e,i),this.DeviceIndex=e,this.SensorIndex=t,this.SensorType=n,this.Id=i}}ke.Name="SensorReadCmd";class Be extends z{constructor(e,t,n,i,u=I){super(e,u),this.DeviceIndex=e,this.SensorIndex=t,this.SensorType=n,this.Data=i,this.Id=u}}Be.Name="SensorReading";class je extends z{constructor(e,t,n,i,u=I){super(e,u),this.DeviceIndex=e,this.Endpoint=t,this.ExpectedLength=n,this.Timeout=i,this.Id=u}}je.Name="RawReadCmd";class $e extends z{constructor(e,t,n,i,u=I){super(e,u),this.DeviceIndex=e,this.Endpoint=t,this.Data=n,this.WriteWithResponse=i,this.Id=u}}$e.Name="RawWriteCmd";class Fe extends z{constructor(e,t,n=I){super(e,n),this.DeviceIndex=e,this.Endpoint=t,this.Id=n}}Fe.Name="RawSubscribeCmd";class Ge extends z{constructor(e,t,n=I){super(e,n),this.DeviceIndex=e,this.Endpoint=t,this.Id=n}}Ge.Name="RawUnsubscribeCmd";class Ue extends z{constructor(e,t,n,i=I){super(e,i),this.DeviceIndex=e,this.Endpoint=t,this.Data=n,this.Id=i}}Ue.Name="RawReading";const Ut=Object.freeze(Object.defineProperty({__proto__:null,ActuatorType:re,ButtplugDeviceMessage:z,ButtplugMessage:H,ButtplugSystemMessage:se,DEFAULT_MESSAGE_ID:I,DeviceAdded:ge,DeviceInfo:Me,DeviceList:Ce,DeviceRemoved:be,Error:Z,ErrorClass:W,GenericDeviceMessageAttributes:dt,GenericMessageSubcommand:me,LinearCmd:Pe,MAX_ID:ft,MESSAGE_SPEC_VERSION:le,MessageAttributes:Se,Ok:pe,Ping:Ze,RawDeviceMessageAttributes:ht,RawReadCmd:je,RawReading:Ue,RawSubscribeCmd:Fe,RawUnsubscribeCmd:Ge,RawWriteCmd:$e,RequestDeviceList:Ee,RequestServerInfo:Le,RotateCmd:Ne,RotateSubcommand:Qe,SYSTEM_MESSAGE_ID:Y,ScalarCmd:ve,ScalarSubcommand:Te,ScanningFinished:xe,SensorDeviceMessageAttributes:lt,SensorReadCmd:ke,SensorReading:Be,SensorType:K,ServerInfo:Re,StartScanning:Ae,StopAllDevices:De,StopDeviceCmd:Ie,StopScanning:Oe,VectorSubcommand:Ke},Symbol.toStringTag,{value:"Module"}));/*! | ||
* Buttplug JS Source Code File - Visit https://buttplug.io for more info about | ||
@@ -28,3 +28,3 @@ * the project. Licensed under the BSD 3-Clause license. See LICENSE file in the | ||
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved. | ||
*/class F extends Error{constructor(e,t,n=Y,i){super(e),this.errorClass=W.ERROR_UNKNOWN,this.errorClass=t,this.innerError=i,this.messageId=n}get ErrorClass(){return this.errorClass}get InnerError(){return this.innerError}get Id(){return this.messageId}get ErrorMessage(){return new Z(this.message,this.ErrorClass,this.Id)}static LogAndError(e,t,n,i=Y){return t.Error(n),new e(n,i)}static FromError(e){switch(e.ErrorCode){case W.ERROR_DEVICE:return new N(e.ErrorMessage,e.Id);case W.ERROR_INIT:return new Ue(e.ErrorMessage,e.Id);case W.ERROR_UNKNOWN:return new mt(e.ErrorMessage,e.Id);case W.ERROR_PING:return new gt(e.ErrorMessage,e.Id);case W.ERROR_MSG:return new ce(e.ErrorMessage,e.Id);default:throw new Error(`Message type ${e.ErrorCode} not handled`)}}}class Ue extends F{constructor(e,t=Y){super(e,W.ERROR_INIT,t)}}class N extends F{constructor(e,t=Y){super(e,W.ERROR_DEVICE,t)}}class ce extends F{constructor(e,t=Y){super(e,W.ERROR_MSG,t)}}class gt extends F{constructor(e,t=Y){super(e,W.ERROR_PING,t)}}class mt extends F{constructor(e,t=Y){super(e,W.ERROR_UNKNOWN,t)}}class ve extends we{constructor(e,t){super(),this._deviceInfo=e,this._sendClosure=t,this.allowedMsgs=new Map,e.DeviceMessages.update()}get name(){return this._deviceInfo.DeviceName}get displayName(){return this._deviceInfo.DeviceDisplayName}get index(){return this._deviceInfo.DeviceIndex}get messageTimingGap(){return this._deviceInfo.DeviceMessageTimingGap}get messageAttributes(){return this._deviceInfo.DeviceMessages}static fromMsg(e,t){return new ve(e,t)}async send(e){return await this._sendClosure(this,e)}async sendExpectOk(e){const t=await this.send(e);switch(t.constructor){case le:return;case Z:throw F.FromError(t);default:throw new ce(`Message type ${t.constructor} not handled by SendMsgExpectOk`)}}async scalar(e){Array.isArray(e)?await this.sendExpectOk(new me(e,this.index)):await this.sendExpectOk(new me([e],this.index))}async scalarCommandBuilder(e,t){var u;const n=(u=this.messageAttributes.ScalarCmd)==null?void 0:u.filter(a=>a.ActuatorType===t);if(!n||n.length===0)throw new N(`Device ${this.name} has no ${t} capabilities`);const i=[];if(typeof e=="number")n.forEach(a=>i.push(new De(a.Index,e,t)));else if(Array.isArray(e)){if(e.length>n.length)throw new N(`${e.length} commands send to a device with ${n.length} vibrators`);n.forEach((a,f)=>{i.push(new De(a.Index,e[f],t))})}else throw new N(`${t} can only take numbers or arrays of numbers.`);await this.scalar(i)}get vibrateAttributes(){var e;return((e=this.messageAttributes.ScalarCmd)==null?void 0:e.filter(t=>t.ActuatorType===ne.Vibrate))??[]}async vibrate(e){await this.scalarCommandBuilder(e,ne.Vibrate)}get oscillateAttributes(){var e;return((e=this.messageAttributes.ScalarCmd)==null?void 0:e.filter(t=>t.ActuatorType===ne.Oscillate))??[]}async oscillate(e){await this.scalarCommandBuilder(e,ne.Oscillate)}get rotateAttributes(){return this.messageAttributes.RotateCmd??[]}async rotate(e,t){const n=this.messageAttributes.RotateCmd;if(!n||n.length===0)throw new N(`Device ${this.name} has no Rotate capabilities`);let i;if(typeof e=="number")i=Te.Create(this.index,new Array(n.length).fill([e,t]));else if(Array.isArray(e))i=Te.Create(this.index,e);else throw new N("SendRotateCmd can only take a number and boolean, or an array of number/boolean tuples");await this.sendExpectOk(i)}get linearAttributes(){return this.messageAttributes.LinearCmd??[]}async linear(e,t){const n=this.messageAttributes.LinearCmd;if(!n||n.length===0)throw new N(`Device ${this.name} has no Linear capabilities`);let i;if(typeof e=="number")i=Ne.Create(this.index,new Array(n.length).fill([e,t]));else if(Array.isArray(e))i=Ne.Create(this.index,e);else throw new N("SendLinearCmd can only take a number and number, or an array of number/number tuples");await this.sendExpectOk(i)}async sensorRead(e,t){const n=await this.send(new Pe(this.index,e,t));switch(n.constructor){case ke:return n.Data;case Z:throw F.FromError(n);default:throw new ce(`Message type ${n.constructor} not handled by sensorRead`)}}get hasBattery(){var t;const e=(t=this.messageAttributes.SensorReadCmd)==null?void 0:t.filter(n=>n.SensorType===K.Battery);return e!==void 0&&e.length>0}async battery(){var n;if(!this.hasBattery)throw new N(`Device ${this.name} has no Battery capabilities`);const e=(n=this.messageAttributes.SensorReadCmd)==null?void 0:n.filter(i=>i.SensorType===K.Battery);return(await this.sensorRead(e[0].Index,K.Battery))[0]/100}get hasRssi(){var t;const e=(t=this.messageAttributes.SensorReadCmd)==null?void 0:t.filter(n=>n.SensorType===K.RSSI);return e!==void 0&&e.length===0}async rssi(){var n;if(!this.hasRssi)throw new N(`Device ${this.name} has no RSSI capabilities`);const e=(n=this.messageAttributes.SensorReadCmd)==null?void 0:n.filter(i=>i.SensorType===K.RSSI);return(await this.sensorRead(e[0].Index,K.RSSI))[0]}async rawRead(e,t,n){if(!this.messageAttributes.RawReadCmd)throw new N(`Device ${this.name} has no raw read capabilities`);if(this.messageAttributes.RawReadCmd.Endpoints.indexOf(e)===-1)throw new N(`Device ${this.name} has no raw readable endpoint ${e}`);const i=await this.send(new Be(this.index,e,t,n));switch(i.constructor){case Ge:return new Uint8Array(i.Data);case Z:throw F.FromError(i);default:throw new ce(`Message type ${i.constructor} not handled by rawRead`)}}async rawWrite(e,t,n){if(!this.messageAttributes.RawWriteCmd)throw new N(`Device ${this.name} has no raw write capabilities`);if(this.messageAttributes.RawWriteCmd.Endpoints.indexOf(e)===-1)throw new N(`Device ${this.name} has no raw writable endpoint ${e}`);await this.sendExpectOk(new je(this.index,e,t,n))}async rawSubscribe(e){if(!this.messageAttributes.RawSubscribeCmd)throw new N(`Device ${this.name} has no raw subscribe capabilities`);if(this.messageAttributes.RawSubscribeCmd.Endpoints.indexOf(e)===-1)throw new N(`Device ${this.name} has no raw subscribable endpoint ${e}`);await this.sendExpectOk(new $e(this.index,e))}async rawUnsubscribe(e){if(!this.messageAttributes.RawSubscribeCmd)throw new N(`Device ${this.name} has no raw unsubscribe capabilities`);if(this.messageAttributes.RawSubscribeCmd.Endpoints.indexOf(e)===-1)throw new N(`Device ${this.name} has no raw unsubscribable endpoint ${e}`);await this.sendExpectOk(new Fe(this.index,e))}async stop(){await this.sendExpectOk(new Re(this.index))}emitDisconnected(){this.emit("deviceremoved")}}/*! | ||
*/class F extends Error{constructor(e,t,n=Y,i){super(e),this.errorClass=W.ERROR_UNKNOWN,this.errorClass=t,this.innerError=i,this.messageId=n}get ErrorClass(){return this.errorClass}get InnerError(){return this.innerError}get Id(){return this.messageId}get ErrorMessage(){return new Z(this.message,this.ErrorClass,this.Id)}static LogAndError(e,t,n,i=Y){return t.Error(n),new e(n,i)}static FromError(e){switch(e.ErrorCode){case W.ERROR_DEVICE:return new N(e.ErrorMessage,e.Id);case W.ERROR_INIT:return new We(e.ErrorMessage,e.Id);case W.ERROR_UNKNOWN:return new vt(e.ErrorMessage,e.Id);case W.ERROR_PING:return new mt(e.ErrorMessage,e.Id);case W.ERROR_MSG:return new ue(e.ErrorMessage,e.Id);default:throw new Error(`Message type ${e.ErrorCode} not handled`)}}}class We extends F{constructor(e,t=Y){super(e,W.ERROR_INIT,t)}}class N extends F{constructor(e,t=Y){super(e,W.ERROR_DEVICE,t)}}class ue extends F{constructor(e,t=Y){super(e,W.ERROR_MSG,t)}}class mt extends F{constructor(e,t=Y){super(e,W.ERROR_PING,t)}}class vt extends F{constructor(e,t=Y){super(e,W.ERROR_UNKNOWN,t)}}function yt(r){for(const e of Object.values(Ut))if(typeof e=="function"&&"Name"in e&&e.Name===r)return e;return null}function ee(r){return yt(Object.getPrototypeOf(r).constructor.Name)}function Ve(r){const e=JSON.parse(r),t=[];for(const n of Array.from(e)){const i=Object.getOwnPropertyNames(n)[0],u=yt(i);if(u){const a=$t(u,n[i]);a.update(),t.push(a)}}return t}class ye extends _e{constructor(e,t){super(),this._deviceInfo=e,this._sendClosure=t,this.allowedMsgs=new Map,e.DeviceMessages.update()}get name(){return this._deviceInfo.DeviceName}get displayName(){return this._deviceInfo.DeviceDisplayName}get index(){return this._deviceInfo.DeviceIndex}get messageTimingGap(){return this._deviceInfo.DeviceMessageTimingGap}get messageAttributes(){return this._deviceInfo.DeviceMessages}static fromMsg(e,t){return new ye(e,t)}async send(e){return await this._sendClosure(this,e)}async sendExpectOk(e){const t=await this.send(e);switch(ee(t)){case pe:return;case Z:throw F.FromError(t);default:throw new ue(`Message type ${t.constructor} not handled by SendMsgExpectOk`)}}async scalar(e){Array.isArray(e)?await this.sendExpectOk(new ve(e,this.index)):await this.sendExpectOk(new ve([e],this.index))}async scalarCommandBuilder(e,t){var u;const n=(u=this.messageAttributes.ScalarCmd)==null?void 0:u.filter(a=>a.ActuatorType===t);if(!n||n.length===0)throw new N(`Device ${this.name} has no ${t} capabilities`);const i=[];if(typeof e=="number")n.forEach(a=>i.push(new Te(a.Index,e,t)));else if(Array.isArray(e)){if(e.length>n.length)throw new N(`${e.length} commands send to a device with ${n.length} vibrators`);n.forEach((a,f)=>{i.push(new Te(a.Index,e[f],t))})}else throw new N(`${t} can only take numbers or arrays of numbers.`);await this.scalar(i)}get vibrateAttributes(){var e;return((e=this.messageAttributes.ScalarCmd)==null?void 0:e.filter(t=>t.ActuatorType===re.Vibrate))??[]}async vibrate(e){await this.scalarCommandBuilder(e,re.Vibrate)}get oscillateAttributes(){var e;return((e=this.messageAttributes.ScalarCmd)==null?void 0:e.filter(t=>t.ActuatorType===re.Oscillate))??[]}async oscillate(e){await this.scalarCommandBuilder(e,re.Oscillate)}get rotateAttributes(){return this.messageAttributes.RotateCmd??[]}async rotate(e,t){const n=this.messageAttributes.RotateCmd;if(!n||n.length===0)throw new N(`Device ${this.name} has no Rotate capabilities`);let i;if(typeof e=="number")i=Ne.Create(this.index,new Array(n.length).fill([e,t]));else if(Array.isArray(e))i=Ne.Create(this.index,e);else throw new N("SendRotateCmd can only take a number and boolean, or an array of number/boolean tuples");await this.sendExpectOk(i)}get linearAttributes(){return this.messageAttributes.LinearCmd??[]}async linear(e,t){const n=this.messageAttributes.LinearCmd;if(!n||n.length===0)throw new N(`Device ${this.name} has no Linear capabilities`);let i;if(typeof e=="number")i=Pe.Create(this.index,new Array(n.length).fill([e,t]));else if(Array.isArray(e))i=Pe.Create(this.index,e);else throw new N("SendLinearCmd can only take a number and number, or an array of number/number tuples");await this.sendExpectOk(i)}async sensorRead(e,t){const n=await this.send(new ke(this.index,e,t));switch(ee(n)){case Be:return n.Data;case Z:throw F.FromError(n);default:throw new ue(`Message type ${n.constructor} not handled by sensorRead`)}}get hasBattery(){var t;const e=(t=this.messageAttributes.SensorReadCmd)==null?void 0:t.filter(n=>n.SensorType===K.Battery);return e!==void 0&&e.length>0}async battery(){var n;if(!this.hasBattery)throw new N(`Device ${this.name} has no Battery capabilities`);const e=(n=this.messageAttributes.SensorReadCmd)==null?void 0:n.filter(i=>i.SensorType===K.Battery);return(await this.sensorRead(e[0].Index,K.Battery))[0]/100}get hasRssi(){var t;const e=(t=this.messageAttributes.SensorReadCmd)==null?void 0:t.filter(n=>n.SensorType===K.RSSI);return e!==void 0&&e.length===0}async rssi(){var n;if(!this.hasRssi)throw new N(`Device ${this.name} has no RSSI capabilities`);const e=(n=this.messageAttributes.SensorReadCmd)==null?void 0:n.filter(i=>i.SensorType===K.RSSI);return(await this.sensorRead(e[0].Index,K.RSSI))[0]}async rawRead(e,t,n){if(!this.messageAttributes.RawReadCmd)throw new N(`Device ${this.name} has no raw read capabilities`);if(this.messageAttributes.RawReadCmd.Endpoints.indexOf(e)===-1)throw new N(`Device ${this.name} has no raw readable endpoint ${e}`);const i=await this.send(new je(this.index,e,t,n));switch(ee(i)){case Ue:return new Uint8Array(i.Data);case Z:throw F.FromError(i);default:throw new ue(`Message type ${i.constructor} not handled by rawRead`)}}async rawWrite(e,t,n){if(!this.messageAttributes.RawWriteCmd)throw new N(`Device ${this.name} has no raw write capabilities`);if(this.messageAttributes.RawWriteCmd.Endpoints.indexOf(e)===-1)throw new N(`Device ${this.name} has no raw writable endpoint ${e}`);await this.sendExpectOk(new $e(this.index,e,t,n))}async rawSubscribe(e){if(!this.messageAttributes.RawSubscribeCmd)throw new N(`Device ${this.name} has no raw subscribe capabilities`);if(this.messageAttributes.RawSubscribeCmd.Endpoints.indexOf(e)===-1)throw new N(`Device ${this.name} has no raw subscribable endpoint ${e}`);await this.sendExpectOk(new Fe(this.index,e))}async rawUnsubscribe(e){if(!this.messageAttributes.RawSubscribeCmd)throw new N(`Device ${this.name} has no raw unsubscribe capabilities`);if(this.messageAttributes.RawSubscribeCmd.Endpoints.indexOf(e)===-1)throw new N(`Device ${this.name} has no raw unsubscribable endpoint ${e}`);await this.sendExpectOk(new Ge(this.index,e))}async stop(){await this.sendExpectOk(new Ie(this.index))}emitDisconnected(){this.emit("deviceremoved")}}/*! | ||
* Buttplug JS Source Code File - Visit https://buttplug.io for more info about | ||
@@ -35,3 +35,3 @@ * the project. Licensed under the BSD 3-Clause license. See LICENSE file in the | ||
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved. | ||
*/class vt{constructor(e){this._useCounter=e,this._counter=1,this._waitingMsgs=new Map}PrepareOutgoingMessage(e){this._useCounter&&(e.Id=this._counter,this._counter+=1);let t,n;const i=new Promise((u,a)=>{t=u,n=a});return this._waitingMsgs.set(e.Id,[t,n]),i}ParseIncomingMessages(e){const t=[];for(const n of e)if(n.Id!==Y&&this._waitingMsgs.has(n.Id)){const[i,u]=this._waitingMsgs.get(n.Id);if(n.Type===Z){u(F.FromError(n));continue}i(n);continue}else t.push(n);return t}}/*! | ||
*/class wt{constructor(e){this._useCounter=e,this._counter=1,this._waitingMsgs=new Map}PrepareOutgoingMessage(e){this._useCounter&&(e.Id=this._counter,this._counter+=1);let t,n;const i=new Promise((u,a)=>{t=u,n=a});return this._waitingMsgs.set(e.Id,[t,n]),i}ParseIncomingMessages(e){const t=[];for(const n of e)if(n.Id!==Y&&this._waitingMsgs.has(n.Id)){const[i,u]=this._waitingMsgs.get(n.Id);if(n.Type===Z){u(F.FromError(n));continue}i(n);continue}else t.push(n);return t}}/*! | ||
* Buttplug JS Source Code File - Visit https://buttplug.io for more info about | ||
@@ -42,2 +42,2 @@ * the project. Licensed under the BSD 3-Clause license. See LICENSE file in the | ||
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved. | ||
*/class yt extends F{constructor(e){super(e,W.ERROR_UNKNOWN)}}class Gt extends we{constructor(e="Generic Buttplug Client"){super(),this._pingTimer=null,this._connector=null,this._devices=new Map,this._logger=it.Logger,this._isScanning=!1,this._sorter=new vt(!0),this.connect=async t=>{this._logger.Info(`ButtplugClient: Connecting using ${t.constructor.name}`),await t.connect(),this._connector=t,this._connector.addListener("message",this.parseMessages),this._connector.addListener("disconnect",this.disconnectHandler),await this.initializeConnection()},this.disconnect=async()=>{this._logger.Debug("ButtplugClient: Disconnect called"),this.checkConnector(),await this.shutdownConnection(),await this._connector.disconnect()},this.startScanning=async()=>{this._logger.Debug("ButtplugClient: StartScanning called"),this._isScanning=!0,await this.sendMsgExpectOk(new Ee)},this.stopScanning=async()=>{this._logger.Debug("ButtplugClient: StopScanning called"),this._isScanning=!1,await this.sendMsgExpectOk(new Ae)},this.stopAllDevices=async()=>{this._logger.Debug("ButtplugClient: StopAllDevices"),await this.sendMsgExpectOk(new Ie)},this.disconnectHandler=()=>{this._logger.Info("ButtplugClient: Disconnect event receieved."),this.emit("disconnect")},this.parseMessages=t=>{const n=this._sorter.ParseIncomingMessages(t);for(const i of n)switch(i.constructor){case pe:{const u=i,a=ve.fromMsg(u,this.sendDeviceMessageClosure);this._devices.set(u.DeviceIndex,a),this.emit("deviceadded",a);break}case be:{const u=i;if(this._devices.has(u.DeviceIndex)){const a=this._devices.get(u.DeviceIndex);a==null||a.emitDisconnected(),this._devices.delete(u.DeviceIndex),this.emit("deviceremoved",a)}break}case Oe:this._isScanning=!1,this.emit("scanningfinished",i);break}},this.initializeConnection=async()=>{this.checkConnector();const t=await this.sendMessage(new xe(this._clientName,he));switch(t.constructor){case Le:{const n=t;if(this._logger.Info(`ButtplugClient: Connected to Server ${n.ServerName}`),n.MaxPingTime,n.MessageVersion<he)throw await this._connector.disconnect(),F.LogAndError(Ue,this._logger,`Server protocol version ${n.MessageVersion} is older than client protocol version ${he}. Please update server.`);return await this.requestDeviceList(),!0}case Z:{await this._connector.disconnect();const n=t;throw F.LogAndError(Ue,this._logger,`Cannot connect to server. ${n.ErrorMessage}`)}}return!1},this.requestDeviceList=async()=>{this.checkConnector(),this._logger.Debug("ButtplugClient: ReceiveDeviceList called"),(await this.sendMessage(new Ce)).Devices.forEach(n=>{if(this._devices.has(n.DeviceIndex))this._logger.Debug(`ButtplugClient: Device already added: ${n}`);else{const i=ve.fromMsg(n,this.sendDeviceMessageClosure);this._logger.Debug(`ButtplugClient: Adding Device: ${i}`),this._devices.set(n.DeviceIndex,i),this.emit("deviceadded",i)}})},this.shutdownConnection=async()=>{await this.stopAllDevices(),this._pingTimer!==null&&(clearInterval(this._pingTimer),this._pingTimer=null)},this.sendMsgExpectOk=async t=>{const n=await this.sendMessage(t);switch(n.constructor){case le:return;case Z:throw F.FromError(n);default:throw F.LogAndError(ce,this._logger,`Message type ${n.constructor} not handled by SendMsgExpectOk`)}},this.sendDeviceMessageClosure=async(t,n)=>await this.sendDeviceMessage(t,n),this._clientName=e,this._logger.Debug(`ButtplugClient: Client ${e} created.`)}get connected(){return this._connector!==null&&this._connector.Connected}get devices(){this.checkConnector();const e=[];return this._devices.forEach(t=>{e.push(t)}),e}get isScanning(){return this._isScanning}async sendDeviceMessage(e,t){if(this.checkConnector(),this._devices.get(e.index)===void 0)throw F.LogAndError(N,this._logger,`Device ${e.index} not available.`);return t.DeviceIndex=e.index,await this.sendMessage(t)}async sendMessage(e){this.checkConnector();const t=this._sorter.PrepareOutgoingMessage(e);return await this._connector.send(e),await t}checkConnector(){if(!this.connected)throw new yt("ButtplugClient not connected")}}function Ut(r){for(const e of Object.values(Ft))if(typeof e=="function"&&"Name"in e&&e.Name===r)return e;return null}function Ke(r){const e=JSON.parse(r),t=[];for(const n of Array.from(e)){const i=Object.getOwnPropertyNames(n)[0],u=Ut(i);if(u){const a=Bt(u,n[i]);a.update(),t.push(a)}}return t}class Wt extends we{constructor(e){super(),this._url=e,this._websocketConstructor=null,this.connect=async()=>{const t=new(this._websocketConstructor??WebSocket)(this._url);let n,i;const u=new Promise((f,g)=>{n=f,i=g}),a=()=>i();return t.addEventListener("open",async()=>{this._ws=t;try{await this.initialize(),this._ws.addEventListener("message",f=>{this.parseIncomingMessage(f)}),this._ws.removeEventListener("close",a),this._ws.addEventListener("close",this.disconnect),n()}catch(f){console.log(f),i()}}),t.addEventListener("close",a),u},this.disconnect=async()=>{this.Connected&&(this._ws.close(),this._ws=void 0,this.emit("disconnect"))},this.initialize=async()=>Promise.resolve()}get Connected(){return this._ws!==void 0}sendMessage(e){if(!this.Connected)throw new Error("ButtplugBrowserWebsocketConnector not connected");this._ws.send("["+e.toJSON()+"]")}parseIncomingMessage(e){if(typeof e.data=="string"){const t=Ke(e.data);this.emit("message",t)}else e.data instanceof Blob}onReaderLoad(e){const t=Ke(e.target.result);this.emit("message",t)}}class wt extends Wt{constructor(){super(...arguments),this.send=e=>{if(!this.Connected)throw new Error("ButtplugClient not connected");this.sendMessage(e)}}}var qt=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")};class Jt extends wt{constructor(){super(...arguments),this._websocketConstructor=qt.WebSocket}}p.ActuatorType=ne,p.ButtplugBrowserWebsocketClientConnector=wt,p.ButtplugClient=Gt,p.ButtplugClientConnectorException=yt,p.ButtplugClientDevice=ve,p.ButtplugDeviceError=N,p.ButtplugDeviceMessage=z,p.ButtplugError=F,p.ButtplugInitError=Ue,p.ButtplugLogLevel=ze,p.ButtplugLogger=it,p.ButtplugMessage=H,p.ButtplugMessageError=ce,p.ButtplugMessageSorter=vt,p.ButtplugNodeWebsocketClientConnector=Jt,p.ButtplugPingError=gt,p.ButtplugSystemMessage=re,p.ButtplugUnknownError=mt,p.DEFAULT_MESSAGE_ID=I,p.DeviceAdded=pe,p.DeviceInfo=Se,p.DeviceList=Me,p.DeviceRemoved=be,p.Error=Z,p.ErrorClass=W,p.GenericDeviceMessageAttributes=ft,p.GenericMessageSubcommand=ge,p.LinearCmd=Ne,p.LogMessage=rt,p.MAX_ID=ut,p.MESSAGE_SPEC_VERSION=he,p.MessageAttributes=_e,p.Ok=le,p.Ping=Xe,p.RawDeviceMessageAttributes=dt,p.RawReadCmd=Be,p.RawReading=Ge,p.RawSubscribeCmd=$e,p.RawUnsubscribeCmd=Fe,p.RawWriteCmd=je,p.RequestDeviceList=Ce,p.RequestServerInfo=xe,p.RotateCmd=Te,p.RotateSubcommand=Ze,p.SYSTEM_MESSAGE_ID=Y,p.ScalarCmd=me,p.ScalarSubcommand=De,p.ScanningFinished=Oe,p.SensorDeviceMessageAttributes=ht,p.SensorReadCmd=Pe,p.SensorReading=ke,p.SensorType=K,p.ServerInfo=Le,p.StartScanning=Ee,p.StopAllDevices=Ie,p.StopDeviceCmd=Re,p.StopScanning=Ae,p.VectorSubcommand=Qe,p.fromJSON=Ke,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}); | ||
*/class _t extends F{constructor(e){super(e,W.ERROR_UNKNOWN)}}class Wt extends _e{constructor(e="Generic Buttplug Client"){super(),this._pingTimer=null,this._connector=null,this._devices=new Map,this._logger=ot.Logger,this._isScanning=!1,this._sorter=new wt(!0),this.connect=async t=>{this._logger.Info(`ButtplugClient: Connecting using ${t.constructor.name}`),await t.connect(),this._connector=t,this._connector.addListener("message",this.parseMessages),this._connector.addListener("disconnect",this.disconnectHandler),await this.initializeConnection()},this.disconnect=async()=>{this._logger.Debug("ButtplugClient: Disconnect called"),this.checkConnector(),await this.shutdownConnection(),await this._connector.disconnect()},this.startScanning=async()=>{this._logger.Debug("ButtplugClient: StartScanning called"),this._isScanning=!0,await this.sendMsgExpectOk(new Ae)},this.stopScanning=async()=>{this._logger.Debug("ButtplugClient: StopScanning called"),this._isScanning=!1,await this.sendMsgExpectOk(new Oe)},this.stopAllDevices=async()=>{this._logger.Debug("ButtplugClient: StopAllDevices"),await this.sendMsgExpectOk(new De)},this.disconnectHandler=()=>{this._logger.Info("ButtplugClient: Disconnect event receieved."),this.emit("disconnect")},this.parseMessages=t=>{const n=this._sorter.ParseIncomingMessages(t);for(const i of n)switch(ee(i)){case ge:{const u=i,a=ye.fromMsg(u,this.sendDeviceMessageClosure);this._devices.set(u.DeviceIndex,a),this.emit("deviceadded",a);break}case be:{const u=i;if(this._devices.has(u.DeviceIndex)){const a=this._devices.get(u.DeviceIndex);a==null||a.emitDisconnected(),this._devices.delete(u.DeviceIndex),this.emit("deviceremoved",a)}break}case xe:this._isScanning=!1,this.emit("scanningfinished",i);break}},this.initializeConnection=async()=>{this.checkConnector();const t=await this.sendMessage(new Le(this._clientName,le));switch(ee(t)){case Re:{const n=t;if(this._logger.Info(`ButtplugClient: Connected to Server ${n.ServerName}`),n.MaxPingTime,n.MessageVersion<le)throw await this._connector.disconnect(),F.LogAndError(We,this._logger,`Server protocol version ${n.MessageVersion} is older than client protocol version ${le}. Please update server.`);return await this.requestDeviceList(),!0}case Z:{await this._connector.disconnect();const n=t;throw F.LogAndError(We,this._logger,`Cannot connect to server. ${n.ErrorMessage}`)}}return!1},this.requestDeviceList=async()=>{this.checkConnector(),this._logger.Debug("ButtplugClient: ReceiveDeviceList called"),(await this.sendMessage(new Ee)).Devices.forEach(n=>{if(this._devices.has(n.DeviceIndex))this._logger.Debug(`ButtplugClient: Device already added: ${n}`);else{const i=ye.fromMsg(n,this.sendDeviceMessageClosure);this._logger.Debug(`ButtplugClient: Adding Device: ${i}`),this._devices.set(n.DeviceIndex,i),this.emit("deviceadded",i)}})},this.shutdownConnection=async()=>{await this.stopAllDevices(),this._pingTimer!==null&&(clearInterval(this._pingTimer),this._pingTimer=null)},this.sendMsgExpectOk=async t=>{const n=await this.sendMessage(t);switch(ee(n)){case pe:return;case Z:throw F.FromError(n);default:throw F.LogAndError(ue,this._logger,`Message type ${ee(n).constructor} not handled by SendMsgExpectOk`)}},this.sendDeviceMessageClosure=async(t,n)=>await this.sendDeviceMessage(t,n),this._clientName=e,this._logger.Debug(`ButtplugClient: Client ${e} created.`)}get connected(){return this._connector!==null&&this._connector.Connected}get devices(){this.checkConnector();const e=[];return this._devices.forEach(t=>{e.push(t)}),e}get isScanning(){return this._isScanning}async sendDeviceMessage(e,t){if(this.checkConnector(),this._devices.get(e.index)===void 0)throw F.LogAndError(N,this._logger,`Device ${e.index} not available.`);return t.DeviceIndex=e.index,await this.sendMessage(t)}async sendMessage(e){this.checkConnector();const t=this._sorter.PrepareOutgoingMessage(e);return await this._connector.send(e),await t}checkConnector(){if(!this.connected)throw new _t("ButtplugClient not connected")}}class qt extends _e{constructor(e){super(),this._url=e,this._websocketConstructor=null,this.connect=async()=>{const t=new(this._websocketConstructor??WebSocket)(this._url);let n,i;const u=new Promise((f,g)=>{n=f,i=g}),a=()=>i();return t.addEventListener("open",async()=>{this._ws=t;try{await this.initialize(),this._ws.addEventListener("message",f=>{this.parseIncomingMessage(f)}),this._ws.removeEventListener("close",a),this._ws.addEventListener("close",this.disconnect),n()}catch(f){console.log(f),i()}}),t.addEventListener("close",a),u},this.disconnect=async()=>{this.Connected&&(this._ws.close(),this._ws=void 0,this.emit("disconnect"))},this.initialize=async()=>Promise.resolve()}get Connected(){return this._ws!==void 0}sendMessage(e){if(!this.Connected)throw new Error("ButtplugBrowserWebsocketConnector not connected");this._ws.send("["+e.toJSON()+"]")}parseIncomingMessage(e){if(typeof e.data=="string"){const t=Ve(e.data);this.emit("message",t)}else e.data instanceof Blob}onReaderLoad(e){const t=Ve(e.target.result);this.emit("message",t)}}class St extends qt{constructor(){super(...arguments),this.send=e=>{if(!this.Connected)throw new Error("ButtplugClient not connected");this.sendMessage(e)}}}var Jt=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")};class zt extends St{constructor(){super(...arguments),this._websocketConstructor=Jt.WebSocket}}l.ActuatorType=re,l.ButtplugBrowserWebsocketClientConnector=St,l.ButtplugClient=Wt,l.ButtplugClientConnectorException=_t,l.ButtplugClientDevice=ye,l.ButtplugDeviceError=N,l.ButtplugDeviceMessage=z,l.ButtplugError=F,l.ButtplugInitError=We,l.ButtplugLogLevel=He,l.ButtplugLogger=ot,l.ButtplugMessage=H,l.ButtplugMessageError=ue,l.ButtplugMessageSorter=wt,l.ButtplugNodeWebsocketClientConnector=zt,l.ButtplugPingError=mt,l.ButtplugSystemMessage=se,l.ButtplugUnknownError=vt,l.DEFAULT_MESSAGE_ID=I,l.DeviceAdded=ge,l.DeviceInfo=Me,l.DeviceList=Ce,l.DeviceRemoved=be,l.Error=Z,l.ErrorClass=W,l.GenericDeviceMessageAttributes=dt,l.GenericMessageSubcommand=me,l.LinearCmd=Pe,l.LogMessage=st,l.MAX_ID=ft,l.MESSAGE_SPEC_VERSION=le,l.MessageAttributes=Se,l.Ok=pe,l.Ping=Ze,l.RawDeviceMessageAttributes=ht,l.RawReadCmd=je,l.RawReading=Ue,l.RawSubscribeCmd=Fe,l.RawUnsubscribeCmd=Ge,l.RawWriteCmd=$e,l.RequestDeviceList=Ee,l.RequestServerInfo=Le,l.RotateCmd=Ne,l.RotateSubcommand=Qe,l.SYSTEM_MESSAGE_ID=Y,l.ScalarCmd=ve,l.ScalarSubcommand=Te,l.ScanningFinished=xe,l.SensorDeviceMessageAttributes=lt,l.SensorReadCmd=ke,l.SensorReading=Be,l.SensorType=K,l.ServerInfo=Re,l.StartScanning=Ae,l.StopAllDevices=De,l.StopDeviceCmd=Ie,l.StopScanning=Oe,l.VectorSubcommand=Ke,l.fromJSON=Ve,l.getMessageClassFromMessage=ee,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}); |
@@ -9,2 +9,3 @@ /*! | ||
import * as Messages from './Messages'; | ||
export declare function getMessageClassFromMessage(msg: Messages.ButtplugMessage): (new (...args: unknown[]) => Messages.ButtplugMessage) | null; | ||
export declare function fromJSON(str: any): Messages.ButtplugMessage[]; |
{ | ||
"name": "buttplug", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Buttplug Client Implementation for Typescript/Javascript", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/buttplugio/buttplug-js/", |
@@ -24,3 +24,3 @@ # Buttplug Typescript/JS Client Implementation | ||
For inclusion in web projects, the UMD project can be found at dist/web/buttplug.js, and the es6 module at dist/web/buttplug.mjs. | ||
For inclusion in web projects, the UMD project can be found at `dist/web/buttplug.js` (Note that the namespace is `buttplug`, so you'll access types like `buttplug.ButtplugClient`, etc...), and the es6 module at `dist/web/buttplug.mjs`. | ||
@@ -27,0 +27,0 @@ ## Using buttplug-js with Node |
@@ -17,2 +17,3 @@ /*! | ||
import { EventEmitter } from 'eventemitter3'; | ||
import { getMessageClassFromMessage } from '../core/MessageUtils'; | ||
@@ -102,3 +103,3 @@ /** | ||
const response = await this.send(msg); | ||
switch (response.constructor) { | ||
switch (getMessageClassFromMessage(response)) { | ||
case Messages.Ok: | ||
@@ -250,3 +251,3 @@ return; | ||
); | ||
switch (response.constructor) { | ||
switch (getMessageClassFromMessage(response)) { | ||
case Messages.SensorReading: | ||
@@ -329,3 +330,3 @@ return (response as Messages.SensorReading).Data; | ||
); | ||
switch (response.constructor) { | ||
switch (getMessageClassFromMessage(response)) { | ||
case Messages.RawReading: | ||
@@ -332,0 +333,0 @@ return new Uint8Array((response as Messages.RawReading).Data); |
@@ -25,2 +25,3 @@ /*! | ||
import { ButtplugClientConnectorException } from './ButtplugClientConnectorException'; | ||
import { getMessageClassFromMessage } from '../core/MessageUtils'; | ||
@@ -121,3 +122,3 @@ export class ButtplugClient extends EventEmitter { | ||
for (const x of leftoverMsgs) { | ||
switch (x.constructor) { | ||
switch (getMessageClassFromMessage(x)) { | ||
case Messages.DeviceAdded: { | ||
@@ -159,3 +160,3 @@ const addedMsg = x as Messages.DeviceAdded; | ||
); | ||
switch (msg.constructor) { | ||
switch (getMessageClassFromMessage(msg)) { | ||
case Messages.ServerInfo: { | ||
@@ -258,3 +259,3 @@ const serverinfo = msg as Messages.ServerInfo; | ||
const response = await this.sendMessage(msg); | ||
switch (response.constructor) { | ||
switch (getMessageClassFromMessage(response)) { | ||
case Messages.Ok: | ||
@@ -268,3 +269,3 @@ return; | ||
this._logger, | ||
`Message type ${response.constructor} not handled by SendMsgExpectOk` | ||
`Message type ${getMessageClassFromMessage(response)!.constructor} not handled by SendMsgExpectOk` | ||
); | ||
@@ -271,0 +272,0 @@ } |
@@ -24,2 +24,10 @@ /*! | ||
export function getMessageClassFromMessage( | ||
msg: Messages.ButtplugMessage | ||
): (new (...args: unknown[]) => Messages.ButtplugMessage) | null { | ||
// Making the bold assumption all message classes have the Name static. Should define a | ||
// requirement for this in the abstract class. | ||
return getMessageClass(Object.getPrototypeOf(msg).constructor.Name); | ||
} | ||
export function fromJSON(str): Messages.ButtplugMessage[] { | ||
@@ -26,0 +34,0 @@ const msgarray: object[] = JSON.parse(str); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2374795
8561
0
155