diff --git a/packages/buttplug/dist/index.js b/packages/buttplug/dist/index.js new file mode 100644 index 0000000..5618078 --- /dev/null +++ b/packages/buttplug/dist/index.js @@ -0,0 +1,1394 @@ +function getDefaultExportFromCjs (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; +} + +var eventemitter3 = {exports: {}}; + +var hasRequiredEventemitter3; + +function requireEventemitter3 () { + if (hasRequiredEventemitter3) return eventemitter3.exports; + hasRequiredEventemitter3 = 1; + (function (module) { + + var has = Object.prototype.hasOwnProperty + , prefix = '~'; + + /** + * Constructor to create a storage for our `EE` objects. + * An `Events` instance is a plain object whose properties are event names. + * + * @constructor + * @private + */ + function Events() {} + + // + // We try to not inherit from `Object.prototype`. In some engines creating an + // instance in this way is faster than calling `Object.create(null)` directly. + // If `Object.create(null)` is not supported we prefix the event names with a + // character to make sure that the built-in object properties are not + // overridden or used as an attack vector. + // + if (Object.create) { + Events.prototype = Object.create(null); + + // + // This hack is needed because the `__proto__` property is still inherited in + // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5. + // + if (!new Events().__proto__) prefix = false; + } + + /** + * Representation of a single event listener. + * + * @param {Function} fn The listener function. + * @param {*} context The context to invoke the listener with. + * @param {Boolean} [once=false] Specify if the listener is a one-time listener. + * @constructor + * @private + */ + function EE(fn, context, once) { + this.fn = fn; + this.context = context; + this.once = once || false; + } + + /** + * Add a listener for a given event. + * + * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. + * @param {(String|Symbol)} event The event name. + * @param {Function} fn The listener function. + * @param {*} context The context to invoke the listener with. + * @param {Boolean} once Specify if the listener is a one-time listener. + * @returns {EventEmitter} + * @private + */ + function addListener(emitter, event, fn, context, once) { + if (typeof fn !== 'function') { + throw new TypeError('The listener must be a function'); + } + + var listener = new EE(fn, context || emitter, once) + , evt = prefix ? prefix + event : event; + + if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++; + else if (!emitter._events[evt].fn) emitter._events[evt].push(listener); + else emitter._events[evt] = [emitter._events[evt], listener]; + + return emitter; + } + + /** + * Clear event by name. + * + * @param {EventEmitter} emitter Reference to the `EventEmitter` instance. + * @param {(String|Symbol)} evt The Event name. + * @private + */ + function clearEvent(emitter, evt) { + if (--emitter._eventsCount === 0) emitter._events = new Events(); + else delete emitter._events[evt]; + } + + /** + * Minimal `EventEmitter` interface that is molded against the Node.js + * `EventEmitter` interface. + * + * @constructor + * @public + */ + function EventEmitter() { + this._events = new Events(); + this._eventsCount = 0; + } + + /** + * Return an array listing the events for which the emitter has registered + * listeners. + * + * @returns {Array} + * @public + */ + EventEmitter.prototype.eventNames = function eventNames() { + var names = [] + , events + , name; + + if (this._eventsCount === 0) return names; + + for (name in (events = this._events)) { + if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); + } + + if (Object.getOwnPropertySymbols) { + return names.concat(Object.getOwnPropertySymbols(events)); + } + + return names; + }; + + /** + * Return the listeners registered for a given event. + * + * @param {(String|Symbol)} event The event name. + * @returns {Array} The registered listeners. + * @public + */ + EventEmitter.prototype.listeners = function listeners(event) { + var evt = prefix ? prefix + event : event + , handlers = this._events[evt]; + + if (!handlers) return []; + if (handlers.fn) return [handlers.fn]; + + for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { + ee[i] = handlers[i].fn; + } + + return ee; + }; + + /** + * Return the number of listeners listening to a given event. + * + * @param {(String|Symbol)} event The event name. + * @returns {Number} The number of listeners. + * @public + */ + EventEmitter.prototype.listenerCount = function listenerCount(event) { + var evt = prefix ? prefix + event : event + , listeners = this._events[evt]; + + if (!listeners) return 0; + if (listeners.fn) return 1; + return listeners.length; + }; + + /** + * Calls each of the listeners registered for a given event. + * + * @param {(String|Symbol)} event The event name. + * @returns {Boolean} `true` if the event had listeners, else `false`. + * @public + */ + EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { + var evt = prefix ? prefix + event : event; + + if (!this._events[evt]) return false; + + var listeners = this._events[evt] + , len = arguments.length + , args + , i; + + if (listeners.fn) { + if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); + + switch (len) { + case 1: return listeners.fn.call(listeners.context), true; + case 2: return listeners.fn.call(listeners.context, a1), true; + case 3: return listeners.fn.call(listeners.context, a1, a2), true; + case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; + case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; + case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; + } + + for (i = 1, args = new Array(len -1); i < len; i++) { + args[i - 1] = arguments[i]; + } + + listeners.fn.apply(listeners.context, args); + } else { + var length = listeners.length + , j; + + for (i = 0; i < length; i++) { + if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); + + switch (len) { + case 1: listeners[i].fn.call(listeners[i].context); break; + case 2: listeners[i].fn.call(listeners[i].context, a1); break; + case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; + case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; + default: + if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { + args[j - 1] = arguments[j]; + } + + listeners[i].fn.apply(listeners[i].context, args); + } + } + } + + return true; + }; + + /** + * Add a listener for a given event. + * + * @param {(String|Symbol)} event The event name. + * @param {Function} fn The listener function. + * @param {*} [context=this] The context to invoke the listener with. + * @returns {EventEmitter} `this`. + * @public + */ + EventEmitter.prototype.on = function on(event, fn, context) { + return addListener(this, event, fn, context, false); + }; + + /** + * Add a one-time listener for a given event. + * + * @param {(String|Symbol)} event The event name. + * @param {Function} fn The listener function. + * @param {*} [context=this] The context to invoke the listener with. + * @returns {EventEmitter} `this`. + * @public + */ + EventEmitter.prototype.once = function once(event, fn, context) { + return addListener(this, event, fn, context, true); + }; + + /** + * Remove the listeners of a given event. + * + * @param {(String|Symbol)} event The event name. + * @param {Function} fn Only remove the listeners that match this function. + * @param {*} context Only remove the listeners that have this context. + * @param {Boolean} once Only remove one-time listeners. + * @returns {EventEmitter} `this`. + * @public + */ + EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { + var evt = prefix ? prefix + event : event; + + if (!this._events[evt]) return this; + if (!fn) { + clearEvent(this, evt); + return this; + } + + var listeners = this._events[evt]; + + if (listeners.fn) { + if ( + listeners.fn === fn && + (!once || listeners.once) && + (!context || listeners.context === context) + ) { + clearEvent(this, evt); + } + } else { + for (var i = 0, events = [], length = listeners.length; i < length; i++) { + if ( + listeners[i].fn !== fn || + (once && !listeners[i].once) || + (context && listeners[i].context !== context) + ) { + events.push(listeners[i]); + } + } + + // + // Reset the array, or remove it completely if we have no more listeners. + // + if (events.length) this._events[evt] = events.length === 1 ? events[0] : events; + else clearEvent(this, evt); + } + + return this; + }; + + /** + * Remove all listeners, or those of the specified event. + * + * @param {(String|Symbol)} [event] The event name. + * @returns {EventEmitter} `this`. + * @public + */ + EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { + var evt; + + if (event) { + evt = prefix ? prefix + event : event; + if (this._events[evt]) clearEvent(this, evt); + } else { + this._events = new Events(); + this._eventsCount = 0; + } + + return this; + }; + + // + // Alias methods names because people roll like that. + // + EventEmitter.prototype.off = EventEmitter.prototype.removeListener; + EventEmitter.prototype.addListener = EventEmitter.prototype.on; + + // + // Expose the prefix. + // + EventEmitter.prefixed = prefix; + + // + // Allow `EventEmitter` to be imported as module namespace. + // + EventEmitter.EventEmitter = EventEmitter; + + // + // Expose the module. + // + { + module.exports = EventEmitter; + } + } (eventemitter3)); + return eventemitter3.exports; +} + +var eventemitter3Exports = requireEventemitter3(); +const EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports); + +var ButtplugLogLevel = /* @__PURE__ */ ((ButtplugLogLevel2) => { + ButtplugLogLevel2[ButtplugLogLevel2["Off"] = 0] = "Off"; + ButtplugLogLevel2[ButtplugLogLevel2["Error"] = 1] = "Error"; + ButtplugLogLevel2[ButtplugLogLevel2["Warn"] = 2] = "Warn"; + ButtplugLogLevel2[ButtplugLogLevel2["Info"] = 3] = "Info"; + ButtplugLogLevel2[ButtplugLogLevel2["Debug"] = 4] = "Debug"; + ButtplugLogLevel2[ButtplugLogLevel2["Trace"] = 5] = "Trace"; + return ButtplugLogLevel2; +})(ButtplugLogLevel || {}); +class LogMessage { + /** Timestamp for the log message */ + timestamp; + /** Log Message */ + logMessage; + /** Log Level */ + logLevel; + /** + * @param logMessage Log message. + * @param logLevel: Log severity level. + */ + constructor(logMessage, logLevel) { + const a = /* @__PURE__ */ new Date(); + const hour = a.getHours(); + const min = a.getMinutes(); + const sec = a.getSeconds(); + this.timestamp = `${hour}:${min}:${sec}`; + this.logMessage = logMessage; + this.logLevel = logLevel; + } + /** + * Returns the log message. + */ + get Message() { + return this.logMessage; + } + /** + * Returns the log message level. + */ + get LogLevel() { + return this.logLevel; + } + /** + * Returns the log message timestamp. + */ + get Timestamp() { + return this.timestamp; + } + /** + * Returns a formatted string with timestamp, level, and message. + */ + get FormattedMessage() { + return `${ButtplugLogLevel[this.logLevel]} : ${this.timestamp} : ${this.logMessage}`; + } +} +class ButtplugLogger extends EventEmitter { + /** Singleton instance for the logger */ + static sLogger = void 0; + /** Sets maximum log level to log to console */ + maximumConsoleLogLevel = 0 /* Off */; + /** Sets maximum log level for all log messages */ + maximumEventLogLevel = 0 /* Off */; + /** + * Returns the stored static instance of the logger, creating one if it + * doesn't currently exist. + */ + static get Logger() { + if (ButtplugLogger.sLogger === void 0) { + ButtplugLogger.sLogger = new ButtplugLogger(); + } + return this.sLogger; + } + /** + * Constructor. Can only be called internally since we regulate ButtplugLogger + * ownership. + */ + constructor() { + super(); + } + /** + * Set the maximum log level to output to console. + */ + get MaximumConsoleLogLevel() { + return this.maximumConsoleLogLevel; + } + /** + * Get the maximum log level to output to console. + */ + set MaximumConsoleLogLevel(buttplugLogLevel) { + this.maximumConsoleLogLevel = buttplugLogLevel; + } + /** + * Set the global maximum log level + */ + get MaximumEventLogLevel() { + return this.maximumEventLogLevel; + } + /** + * Get the global maximum log level + */ + set MaximumEventLogLevel(logLevel) { + this.maximumEventLogLevel = logLevel; + } + /** + * Log new message at Error level. + */ + Error(msg) { + this.AddLogMessage(msg, 1 /* Error */); + } + /** + * Log new message at Warn level. + */ + Warn(msg) { + this.AddLogMessage(msg, 2 /* Warn */); + } + /** + * Log new message at Info level. + */ + Info(msg) { + this.AddLogMessage(msg, 3 /* Info */); + } + /** + * Log new message at Debug level. + */ + Debug(msg) { + this.AddLogMessage(msg, 4 /* Debug */); + } + /** + * Log new message at Trace level. + */ + Trace(msg) { + this.AddLogMessage(msg, 5 /* Trace */); + } + /** + * Checks to see if message should be logged, and if so, adds message to the + * log buffer. May also print message and emit event. + */ + AddLogMessage(msg, level) { + if (level > this.maximumEventLogLevel && level > this.maximumConsoleLogLevel) { + return; + } + const logMsg = new LogMessage(msg, level); + if (level <= this.maximumConsoleLogLevel) { + console.log(logMsg.FormattedMessage); + } + if (level <= this.maximumEventLogLevel) { + this.emit("log", logMsg); + } + } +} + +class ButtplugError extends Error { + get ErrorClass() { + return this.errorClass; + } + get InnerError() { + return this.innerError; + } + get Id() { + return this.messageId; + } + get ErrorMessage() { + return { + Error: { + Id: this.Id, + ErrorCode: this.ErrorClass, + ErrorMessage: this.message + } + }; + } + static LogAndError(constructor, logger, message, id = SYSTEM_MESSAGE_ID) { + logger.Error(message); + return new constructor(message, id); + } + static FromError(error) { + switch (error.ErrorCode) { + case ErrorClass.ERROR_DEVICE: + return new ButtplugDeviceError(error.ErrorMessage, error.Id); + case ErrorClass.ERROR_INIT: + return new ButtplugInitError(error.ErrorMessage, error.Id); + case ErrorClass.ERROR_UNKNOWN: + return new ButtplugUnknownError(error.ErrorMessage, error.Id); + case ErrorClass.ERROR_PING: + return new ButtplugPingError(error.ErrorMessage, error.Id); + case ErrorClass.ERROR_MSG: + return new ButtplugMessageError(error.ErrorMessage, error.Id); + default: + throw new Error(`Message type ${error.ErrorCode} not handled`); + } + } + errorClass = ErrorClass.ERROR_UNKNOWN; + innerError; + messageId; + constructor(message, errorClass, id = SYSTEM_MESSAGE_ID, inner) { + super(message); + this.errorClass = errorClass; + this.innerError = inner; + this.messageId = id; + } +} +class ButtplugInitError extends ButtplugError { + constructor(message, id = SYSTEM_MESSAGE_ID) { + super(message, ErrorClass.ERROR_INIT, id); + } +} +class ButtplugDeviceError extends ButtplugError { + constructor(message, id = SYSTEM_MESSAGE_ID) { + super(message, ErrorClass.ERROR_DEVICE, id); + } +} +class ButtplugMessageError extends ButtplugError { + constructor(message, id = SYSTEM_MESSAGE_ID) { + super(message, ErrorClass.ERROR_MSG, id); + } +} +class ButtplugPingError extends ButtplugError { + constructor(message, id = SYSTEM_MESSAGE_ID) { + super(message, ErrorClass.ERROR_PING, id); + } +} +class ButtplugUnknownError extends ButtplugError { + constructor(message, id = SYSTEM_MESSAGE_ID) { + super(message, ErrorClass.ERROR_UNKNOWN, id); + } +} + +const SYSTEM_MESSAGE_ID = 0; +const DEFAULT_MESSAGE_ID = 1; +const MAX_ID = 4294967295; +const MESSAGE_SPEC_VERSION_MAJOR = 4; +const MESSAGE_SPEC_VERSION_MINOR = 0; +function msgId(msg) { + for (const [_, entry] of Object.entries(msg)) { + if (entry != void 0) { + return entry.Id; + } + } + throw new ButtplugMessageError(`Message ${msg} does not have an ID.`); +} +function setMsgId(msg, id) { + for (const [_, entry] of Object.entries(msg)) { + if (entry != void 0) { + entry.Id = id; + return; + } + } + throw new ButtplugMessageError(`Message ${msg} does not have an ID.`); +} +var ErrorClass = /* @__PURE__ */ ((ErrorClass2) => { + ErrorClass2[ErrorClass2["ERROR_UNKNOWN"] = 0] = "ERROR_UNKNOWN"; + ErrorClass2[ErrorClass2["ERROR_INIT"] = 1] = "ERROR_INIT"; + ErrorClass2[ErrorClass2["ERROR_PING"] = 2] = "ERROR_PING"; + ErrorClass2[ErrorClass2["ERROR_MSG"] = 3] = "ERROR_MSG"; + ErrorClass2[ErrorClass2["ERROR_DEVICE"] = 4] = "ERROR_DEVICE"; + return ErrorClass2; +})(ErrorClass || {}); +var OutputType = /* @__PURE__ */ ((OutputType2) => { + OutputType2["Unknown"] = "Unknown"; + OutputType2["Vibrate"] = "Vibrate"; + OutputType2["Rotate"] = "Rotate"; + OutputType2["Oscillate"] = "Oscillate"; + OutputType2["Constrict"] = "Constrict"; + OutputType2["Inflate"] = "Inflate"; + OutputType2["Position"] = "Position"; + OutputType2["HwPositionWithDuration"] = "HwPositionWithDuration"; + OutputType2["Temperature"] = "Temperature"; + OutputType2["Spray"] = "Spray"; + OutputType2["Led"] = "Led"; + return OutputType2; +})(OutputType || {}); +var InputType = /* @__PURE__ */ ((InputType2) => { + InputType2["Unknown"] = "Unknown"; + InputType2["Battery"] = "Battery"; + InputType2["RSSI"] = "RSSI"; + InputType2["Button"] = "Button"; + InputType2["Pressure"] = "Pressure"; + return InputType2; +})(InputType || {}); +var InputCommandType = /* @__PURE__ */ ((InputCommandType2) => { + InputCommandType2["Read"] = "Read"; + InputCommandType2["Subscribe"] = "Subscribe"; + InputCommandType2["Unsubscribe"] = "Unsubscribe"; + return InputCommandType2; +})(InputCommandType || {}); + +class ButtplugClientDeviceFeature { + constructor(_deviceIndex, _deviceName, _feature, _sendClosure) { + this._deviceIndex = _deviceIndex; + this._deviceName = _deviceName; + this._feature = _feature; + this._sendClosure = _sendClosure; + } + send = async (msg) => { + return await this._sendClosure(msg); + }; + sendMsgExpectOk = async (msg) => { + const response = await this.send(msg); + if (response.Ok !== void 0) { + return; + } else if (response.Error !== void 0) { + throw ButtplugError.FromError(response); + } else { + throw new ButtplugMessageError("Expected Ok or Error, and didn't get either!"); + } + }; + isOutputValid(type) { + if (this._feature.Output !== void 0 && !Object.prototype.hasOwnProperty.call(this._feature.Output, type)) { + throw new ButtplugDeviceError( + `Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}` + ); + } + } + isInputValid(type) { + if (this._feature.Input !== void 0 && !Object.prototype.hasOwnProperty.call(this._feature.Input, type)) { + throw new ButtplugDeviceError( + `Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}` + ); + } + } + async sendOutputCmd(command) { + this.isOutputValid(command.outputType); + if (command.value === void 0) { + throw new ButtplugDeviceError(`${command.outputType} requires value defined`); + } + const type = command.outputType; + let duration = void 0; + if (type == OutputType.HwPositionWithDuration) { + if (command.duration === void 0) { + throw new ButtplugDeviceError("PositionWithDuration requires duration defined"); + } + duration = command.duration; + } + let value; + const p = command.value; + if (p.percent === void 0) { + value = command.value.steps; + } else { + value = Math.ceil(this._feature.Output[type].Value[1] * p.percent); + } + const newCommand = { Value: value, Duration: duration }; + const outCommand = {}; + outCommand[type.toString()] = newCommand; + const cmd = { + OutputCmd: { + Id: 1, + DeviceIndex: this._deviceIndex, + FeatureIndex: this._feature.FeatureIndex, + Command: outCommand + } + }; + await this.sendMsgExpectOk(cmd); + } + get featureDescriptor() { + return this._feature.FeatureDescription; + } + get featureIndex() { + return this._feature.FeatureIndex; + } + get outputTypes() { + if (this._feature.Output === void 0) return []; + return Object.keys(this._feature.Output); + } + get inputTypes() { + if (this._feature.Input === void 0) return []; + return Object.keys(this._feature.Input); + } + outputMaxValue(type) { + if (this._feature.Output === void 0 || this._feature.Output[type] === void 0) { + return 0; + } + const val = this._feature.Output[type].Value; + if (Array.isArray(val)) { + return val[val.length - 1]; + } + return val; + } + hasOutput(type) { + if (this._feature.Output !== void 0) { + return Object.prototype.hasOwnProperty.call(this._feature.Output, type.toString()); + } + return false; + } + hasInput(type) { + if (this._feature.Input !== void 0) { + return Object.prototype.hasOwnProperty.call(this._feature.Input, type.toString()); + } + return false; + } + async runOutput(cmd) { + if (this._feature.Output !== void 0 && Object.prototype.hasOwnProperty.call(this._feature.Output, cmd.outputType.toString())) { + return this.sendOutputCmd(cmd); + } + throw new ButtplugDeviceError(`Output type ${cmd.outputType} not supported by feature.`); + } + async runInput(inputType, inputCommand) { + this.isInputValid(inputType); + const inputAttributes = this._feature.Input[inputType]; + console.log(this._feature.Input); + if (inputCommand === InputCommandType.Unsubscribe && !inputAttributes.Command.includes(InputCommandType.Subscribe) && !inputAttributes.Command.includes(inputCommand)) { + throw new ButtplugDeviceError(`${inputType} does not support command ${inputCommand}`); + } + const cmd = { + InputCmd: { + Id: 1, + DeviceIndex: this._deviceIndex, + FeatureIndex: this._feature.FeatureIndex, + Type: inputType, + Command: inputCommand + } + }; + if (inputCommand == InputCommandType.Read) { + const response = await this.send(cmd); + if (response.InputReading !== void 0) { + return response.InputReading; + } else if (response.Error !== void 0) { + throw ButtplugError.FromError(response); + } else { + throw new ButtplugMessageError("Expected InputReading or Error, and didn't get either!"); + } + } else { + console.log(`Sending subscribe message: ${JSON.stringify(cmd)}`); + await this.sendMsgExpectOk(cmd); + console.log("Got back ok?"); + } + } +} + +class ButtplugClientDevice extends EventEmitter { + /** + * @param _index Index of the device, as created by the device manager. + * @param _name Name of the device. + * @param allowedMsgs Buttplug messages the device can receive. + */ + constructor(_deviceInfo, _sendClosure) { + super(); + this._deviceInfo = _deviceInfo; + this._sendClosure = _sendClosure; + this._features = new Map( + Object.entries(_deviceInfo.DeviceFeatures).map(([index, v]) => [ + parseInt(index), + new ButtplugClientDeviceFeature( + _deviceInfo.DeviceIndex, + _deviceInfo.DeviceName, + v, + _sendClosure + ) + ]) + ); + } + _features; + /** + * Return the name of the device. + */ + get name() { + return this._deviceInfo.DeviceName; + } + /** + * Return the user set name of the device. + */ + get displayName() { + return this._deviceInfo.DeviceDisplayName; + } + /** + * Return the index of the device. + */ + get index() { + return this._deviceInfo.DeviceIndex; + } + /** + * Return the index of the device. + */ + get messageTimingGap() { + return this._deviceInfo.DeviceMessageTimingGap; + } + get features() { + return this._features; + } + static fromMsg(msg, sendClosure) { + return new ButtplugClientDevice(msg, sendClosure); + } + async send(msg) { + return await this._sendClosure(msg); + } + sendMsgExpectOk = async (msg) => { + const response = await this.send(msg); + if (response.Ok !== void 0) { + return; + } else if (response.Error !== void 0) { + throw ButtplugError.FromError(response); + } else ; + }; + isOutputValid(featureIndex, type) { + if (!Object.prototype.hasOwnProperty.call( + this._deviceInfo.DeviceFeatures, + featureIndex.toString() + )) { + throw new ButtplugDeviceError( + `Feature index ${featureIndex} does not exist for device ${this.name}` + ); + } + if (this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs !== void 0 && !Object.prototype.hasOwnProperty.call( + this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs, + type + )) { + throw new ButtplugDeviceError( + `Feature index ${featureIndex} does not support type ${type} for device ${this.name}` + ); + } + } + hasOutput(type) { + return this._features.values().filter((f) => f.hasOutput(type)).toArray().length > 0; + } + hasInput(type) { + return this._features.values().filter((f) => f.hasInput(type)).toArray().length > 0; + } + async runOutput(cmd) { + const p = []; + for (const f of this._features.values()) { + if (f.hasOutput(cmd.outputType)) { + p.push(f.runOutput(cmd)); + } + } + if (p.length == 0) { + return Promise.reject(`No features with output type ${cmd.outputType}`); + } + await Promise.all(p); + } + async stop() { + await this.sendMsgExpectOk({ + StopCmd: { + Id: 1, + DeviceIndex: this.index, + FeatureIndex: void 0, + Inputs: true, + Outputs: true + } + }); + } + async battery() { + for (const f of this._features.values()) { + if (f.hasInput(InputType.Battery)) { + const response = await f.runInput( + InputType.Battery, + InputCommandType.Read + ); + if (response === void 0) { + throw new ButtplugMessageError("Got incorrect message back."); + } + if (response.Reading[InputType.Battery] === void 0) { + throw new ButtplugMessageError("Got reading with no Battery info."); + } + return response.Reading[InputType.Battery].Value; + } + } + throw new ButtplugDeviceError(`No battery present on this device.`); + } + emitDisconnected() { + this.emit("deviceremoved"); + } +} + +class ButtplugMessageSorter { + constructor(_useCounter) { + this._useCounter = _useCounter; + } + _counter = 1; + _waitingMsgs = /* @__PURE__ */ new Map(); + // One of the places we should actually return a promise, as we need to store + // them while waiting for them to return across the line. + // tslint:disable:promise-function-async + PrepareOutgoingMessage(msg) { + if (this._useCounter) { + setMsgId(msg, this._counter); + this._counter += 1; + } + let res; + let rej; + const msgPromise = new Promise((resolve, reject) => { + res = resolve; + rej = reject; + }); + this._waitingMsgs.set(msgId(msg), [res, rej]); + return msgPromise; + } + ParseIncomingMessages(msgs) { + const noMatch = []; + for (const x of msgs) { + const id = msgId(x); + if (id !== SYSTEM_MESSAGE_ID && this._waitingMsgs.has(id)) { + const [res, rej] = this._waitingMsgs.get(id); + this._waitingMsgs.delete(id); + if (x.Error !== void 0) { + rej(ButtplugError.FromError(x.Error)); + continue; + } + res(x); + continue; + } else { + noMatch.push(x); + } + } + return noMatch; + } +} + +class ButtplugClientConnectorException extends ButtplugError { + constructor(message) { + super(message, ErrorClass.ERROR_UNKNOWN); + } +} + +class ButtplugClient extends EventEmitter { + _pingTimer = null; + _connector = null; + _devices = /* @__PURE__ */ new Map(); + _clientName; + _logger = ButtplugLogger.Logger; + _isScanning = false; + _sorter = new ButtplugMessageSorter(true); + constructor(clientName = "Generic Buttplug Client") { + super(); + this._clientName = clientName; + this._logger.Debug(`ButtplugClient: Client ${clientName} created.`); + } + get connected() { + return this._connector !== null && this._connector.Connected; + } + get devices() { + this.checkConnector(); + return this._devices; + } + get isScanning() { + return this._isScanning; + } + connect = async (connector) => { + this._logger.Info(`ButtplugClient: Connecting using ${connector.constructor.name}`); + await connector.connect(); + this._connector = connector; + this._connector.addListener("message", this.parseMessages); + this._connector.addListener("disconnect", this.disconnectHandler); + await this.initializeConnection(); + }; + disconnect = async () => { + this._logger.Debug("ButtplugClient: Disconnect called"); + this._devices.clear(); + this.checkConnector(); + await this.shutdownConnection(); + await this._connector.disconnect(); + }; + startScanning = async () => { + this._logger.Debug("ButtplugClient: StartScanning called"); + this._isScanning = true; + await this.sendMsgExpectOk({ StartScanning: { Id: 1 } }); + }; + stopScanning = async () => { + this._logger.Debug("ButtplugClient: StopScanning called"); + this._isScanning = false; + await this.sendMsgExpectOk({ StopScanning: { Id: 1 } }); + }; + stopAllDevices = async () => { + this._logger.Debug("ButtplugClient: StopAllDevices"); + await this.sendMsgExpectOk({ + StopCmd: { + Id: 1, + DeviceIndex: void 0, + FeatureIndex: void 0, + Inputs: true, + Outputs: true + } + }); + }; + disconnectHandler = () => { + this._logger.Info("ButtplugClient: Disconnect event receieved."); + this.emit("disconnect"); + }; + parseMessages = (msgs) => { + const leftoverMsgs = this._sorter.ParseIncomingMessages(msgs); + for (const x of leftoverMsgs) { + if (x.DeviceList !== void 0) { + this.parseDeviceList(x.DeviceList); + break; + } else if (x.ScanningFinished !== void 0) { + this._isScanning = false; + this.emit("scanningfinished", x); + } else if (x.InputReading !== void 0) { + this.emit("inputreading", x); + } else { + console.log(`Unhandled message: ${x}`); + } + } + }; + initializeConnection = async () => { + this.checkConnector(); + const msg = await this.sendMessage({ + RequestServerInfo: { + ClientName: this._clientName, + Id: 1, + ProtocolVersionMajor: MESSAGE_SPEC_VERSION_MAJOR, + ProtocolVersionMinor: MESSAGE_SPEC_VERSION_MINOR + } + }); + if (msg.ServerInfo !== void 0) { + const serverinfo = msg; + this._logger.Info(`ButtplugClient: Connected to Server ${serverinfo.ServerName}`); + serverinfo.MaxPingTime; + await this.requestDeviceList(); + return true; + } else if (msg.Error !== void 0) { + await this._connector.disconnect(); + const err = msg.Error; + throw ButtplugError.LogAndError( + ButtplugInitError, + this._logger, + `Cannot connect to server. ${err.ErrorMessage}` + ); + } + return false; + }; + parseDeviceList = (list) => { + for (const [_, d] of Object.entries(list.Devices)) { + if (!this._devices.has(d.DeviceIndex)) { + const device = ButtplugClientDevice.fromMsg(d, this.sendMessageClosure); + this._logger.Debug(`ButtplugClient: Adding Device: ${device}`); + this._devices.set(d.DeviceIndex, device); + this.emit("deviceadded", device); + } else { + this._logger.Debug(`ButtplugClient: Device already added: ${d}`); + } + } + for (const [index, device] of this._devices.entries()) { + if (!Object.prototype.hasOwnProperty.call(list.Devices, index.toString())) { + this._devices.delete(index); + this.emit("deviceremoved", device); + } + } + }; + requestDeviceList = async () => { + this.checkConnector(); + this._logger.Debug("ButtplugClient: ReceiveDeviceList called"); + const response = await this.sendMessage({ + RequestDeviceList: { Id: 1 } + }); + this.parseDeviceList(response.DeviceList); + }; + shutdownConnection = async () => { + await this.stopAllDevices(); + if (this._pingTimer !== null) { + clearInterval(this._pingTimer); + this._pingTimer = null; + } + }; + async sendMessage(msg) { + this.checkConnector(); + const p = this._sorter.PrepareOutgoingMessage(msg); + await this._connector.send(msg); + return await p; + } + checkConnector() { + if (!this.connected) { + throw new ButtplugClientConnectorException("ButtplugClient not connected"); + } + } + sendMsgExpectOk = async (msg) => { + const response = await this.sendMessage(msg); + if (response.Ok !== void 0) { + return; + } else if (response.Error !== void 0) { + throw ButtplugError.FromError(response); + } else { + throw ButtplugError.LogAndError( + ButtplugMessageError, + this._logger, + `Message ${response} not handled by SendMsgExpectOk` + ); + } + }; + sendMessageClosure = async (msg) => { + return await this.sendMessage(msg); + }; +} + +class ButtplugBrowserWebsocketConnector extends EventEmitter { + constructor(_url) { + super(); + this._url = _url; + } + _ws; + _websocketConstructor = null; + get Connected() { + return this._ws !== void 0; + } + connect = async () => { + return new Promise((resolve, reject) => { + const ws = new (this._websocketConstructor ?? WebSocket)(this._url); + const onErrorCallback = (event) => { + reject(event); + }; + const onCloseCallback = (event) => reject(event.reason); + ws.addEventListener("open", async () => { + this._ws = ws; + try { + await this.initialize(); + this._ws.addEventListener("message", (msg) => { + this.parseIncomingMessage(msg); + }); + this._ws.removeEventListener("close", onCloseCallback); + this._ws.removeEventListener("error", onErrorCallback); + this._ws.addEventListener("close", this.disconnect); + resolve(); + } catch (e) { + reject(e); + } + }); + ws.addEventListener("error", onErrorCallback); + ws.addEventListener("close", onCloseCallback); + }); + }; + disconnect = async () => { + if (!this.Connected) { + return; + } + this._ws.close(); + this._ws = void 0; + this.emit("disconnect"); + }; + sendMessage(msg) { + if (!this.Connected) { + throw new Error("ButtplugBrowserWebsocketConnector not connected"); + } + this._ws.send("[" + JSON.stringify(msg) + "]"); + } + initialize = async () => { + return Promise.resolve(); + }; + parseIncomingMessage(event) { + if (typeof event.data === "string") { + const msgs = JSON.parse(event.data); + this.emit("message", msgs); + } else if (event.data instanceof Blob) ; + } + onReaderLoad(event) { + const msgs = JSON.parse(event.target.result); + this.emit("message", msgs); + } +} + +class ButtplugBrowserWebsocketClientConnector extends ButtplugBrowserWebsocketConnector { + send = (msg) => { + if (!this.Connected) { + throw new Error("ButtplugClient not connected"); + } + this.sendMessage(msg); + }; +} + +var browser; +var hasRequiredBrowser; + +function requireBrowser () { + if (hasRequiredBrowser) return browser; + hasRequiredBrowser = 1; + + browser = function () { + throw new Error( + 'ws does not work in the browser. Browser clients must use the native ' + + 'WebSocket object' + ); + }; + return browser; +} + +var browserExports = requireBrowser(); + +class ButtplugNodeWebsocketClientConnector extends ButtplugBrowserWebsocketClientConnector { + _websocketConstructor = browserExports.WebSocket; +} + +class PercentOrSteps { + _percent; + _steps; + get percent() { + return this._percent; + } + get steps() { + return this._steps; + } + static createSteps(s) { + const v = new PercentOrSteps(); + v._steps = s; + return v; + } + static createPercent(p) { + if (p < 0 || p > 1) { + throw new ButtplugDeviceError(`Percent value ${p} is not in the range 0.0 <= x <= 1.0`); + } + const v = new PercentOrSteps(); + v._percent = p; + return v; + } +} +class DeviceOutputCommand { + constructor(_outputType, _value, _duration) { + this._outputType = _outputType; + this._value = _value; + this._duration = _duration; + } + get outputType() { + return this._outputType; + } + get value() { + return this._value; + } + get duration() { + return this._duration; + } +} +class DeviceOutputValueConstructor { + constructor(_outputType) { + this._outputType = _outputType; + } + steps(steps) { + return new DeviceOutputCommand(this._outputType, PercentOrSteps.createSteps(steps), void 0); + } + percent(percent) { + return new DeviceOutputCommand( + this._outputType, + PercentOrSteps.createPercent(percent), + void 0 + ); + } +} +class DeviceOutputPositionWithDurationConstructor { + steps(steps, duration) { + return new DeviceOutputCommand( + OutputType.Position, + PercentOrSteps.createSteps(steps), + duration + ); + } + percent(percent, duration) { + return new DeviceOutputCommand( + OutputType.HwPositionWithDuration, + PercentOrSteps.createPercent(percent), + duration + ); + } +} +class DeviceOutput { + constructor() { + } + static get Vibrate() { + return new DeviceOutputValueConstructor(OutputType.Vibrate); + } + static get Rotate() { + return new DeviceOutputValueConstructor(OutputType.Rotate); + } + static get Oscillate() { + return new DeviceOutputValueConstructor(OutputType.Oscillate); + } + static get Constrict() { + return new DeviceOutputValueConstructor(OutputType.Constrict); + } + static get Inflate() { + return new DeviceOutputValueConstructor(OutputType.Inflate); + } + static get Temperature() { + return new DeviceOutputValueConstructor(OutputType.Temperature); + } + static get Led() { + return new DeviceOutputValueConstructor(OutputType.Led); + } + static get Spray() { + return new DeviceOutputValueConstructor(OutputType.Spray); + } + static get Position() { + return new DeviceOutputValueConstructor(OutputType.Position); + } + static get PositionWithDuration() { + return new DeviceOutputPositionWithDurationConstructor(); + } +} + +class ButtplugWasmClientConnector extends EventEmitter { + static _loggingActivated = false; + static wasmInstance; + _connected = false; + client; + serverPtr; + constructor() { + super(); + } + get Connected() { + return this._connected; + } + static maybeLoadWasm = async () => { + if (ButtplugWasmClientConnector.wasmInstance == void 0) { + const wasmModule = await import('../wasm/index.js'); + await wasmModule.default(); + ButtplugWasmClientConnector.wasmInstance = wasmModule; + } + }; + static activateLogging = async (logLevel = "debug") => { + await ButtplugWasmClientConnector.maybeLoadWasm(); + if (this._loggingActivated) { + console.log("Logging already activated, ignoring."); + return; + } + console.log("Turning on logging."); + ButtplugWasmClientConnector.wasmInstance.buttplug_activate_env_logger(logLevel); + }; + initialize = async () => { + }; + connect = async () => { + await ButtplugWasmClientConnector.maybeLoadWasm(); + this.client = ButtplugWasmClientConnector.wasmInstance.buttplug_create_embedded_wasm_server( + (msgs) => { + this.emitMessage(msgs); + }, + this.serverPtr + ); + this._connected = true; + }; + disconnect = async () => { + }; + send = (msg) => { + ButtplugWasmClientConnector.wasmInstance.buttplug_client_send_json_message( + this.client, + new TextEncoder().encode("[" + JSON.stringify(msg) + "]"), + (output) => { + this.emitMessage(output); + } + ); + }; + emitMessage = (msg) => { + const str = new TextDecoder().decode(msg); + const msgs = JSON.parse(str); + this.emit("message", msgs); + }; +} + +export { ButtplugBrowserWebsocketClientConnector, ButtplugClient, ButtplugClientConnectorException, ButtplugClientDevice, ButtplugClientDeviceFeature, ButtplugDeviceError, ButtplugError, ButtplugInitError, ButtplugLogLevel, ButtplugLogger, ButtplugMessageError, ButtplugMessageSorter, ButtplugNodeWebsocketClientConnector, ButtplugPingError, ButtplugUnknownError, ButtplugWasmClientConnector, DEFAULT_MESSAGE_ID, DeviceOutput, DeviceOutputCommand, DeviceOutputPositionWithDurationConstructor, DeviceOutputValueConstructor, ErrorClass, InputCommandType, InputType, LogMessage, MAX_ID, MESSAGE_SPEC_VERSION_MAJOR, MESSAGE_SPEC_VERSION_MINOR, OutputType, SYSTEM_MESSAGE_ID, msgId, setMsgId }; diff --git a/packages/buttplug/package.json b/packages/buttplug/package.json index bea7a5f..6dfde32 100644 --- a/packages/buttplug/package.json +++ b/packages/buttplug/package.json @@ -10,7 +10,7 @@ ], "scripts": { "build": "vite build", - "build:wasm": "wasm-pack build --out-dir wasm --out-name index --target bundler --release", + "build:wasm": "wasm-pack build --out-dir wasm --out-name index --target web --release", "serve": "node serve.mjs" }, "dependencies": { diff --git a/packages/buttplug/src/index.ts b/packages/buttplug/src/index.ts index 81e3f54..18a83bd 100644 --- a/packages/buttplug/src/index.ts +++ b/packages/buttplug/src/index.ts @@ -40,7 +40,9 @@ export class ButtplugWasmClientConnector extends EventEmitter implements IButtpl private static maybeLoadWasm = async () => { if (ButtplugWasmClientConnector.wasmInstance == undefined) { - ButtplugWasmClientConnector.wasmInstance = await import("../wasm/index.js"); + const wasmModule = await import("../wasm/index.js"); + await wasmModule.default(); // --target web requires calling init() before using exports + ButtplugWasmClientConnector.wasmInstance = wasmModule; } }; diff --git a/packages/buttplug/wasm/.gitignore b/packages/buttplug/wasm/.gitignore new file mode 100644 index 0000000..f59ec20 --- /dev/null +++ b/packages/buttplug/wasm/.gitignore @@ -0,0 +1 @@ +* \ No newline at end of file diff --git a/packages/buttplug/wasm/index.d.ts b/packages/buttplug/wasm/index.d.ts new file mode 100644 index 0000000..586b77f --- /dev/null +++ b/packages/buttplug/wasm/index.d.ts @@ -0,0 +1,64 @@ +/* tslint:disable */ +/* eslint-disable */ + +export function buttplug_activate_env_logger(_max_level: string): void; + +export function buttplug_client_send_json_message(server_ptr: number, buf: Uint8Array, callback: Function): void; + +export function buttplug_create_embedded_wasm_server(callback: Function): number; + +export function buttplug_free_embedded_wasm_server(ptr: number): void; + +export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; + +export interface InitOutput { + readonly memory: WebAssembly.Memory; + readonly create_test_dcm: (a: number, b: number) => void; + readonly buttplug_activate_env_logger: (a: number, b: number) => void; + readonly buttplug_client_send_json_message: (a: number, b: number, c: number, d: any) => void; + readonly buttplug_create_embedded_wasm_server: (a: any) => number; + readonly buttplug_free_embedded_wasm_server: (a: number) => void; + readonly wasm_bindgen__closure__destroy__h72b504abf7ea70fd: (a: number, b: number) => void; + readonly wasm_bindgen__closure__destroy__ha3c8e2c9b0cf79cd: (a: number, b: number) => void; + readonly wasm_bindgen__closure__destroy__h0f95d90d24796def: (a: number, b: number) => void; + readonly wasm_bindgen__convert__closures_____invoke__hcd253b168dd40e38: (a: number, b: number, c: any) => [number, number]; + readonly wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1: (a: number, b: number, c: any) => [number, number]; + readonly wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_3: (a: number, b: number, c: any) => [number, number]; + readonly wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_4: (a: number, b: number, c: any) => [number, number]; + readonly wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_5: (a: number, b: number, c: any) => [number, number]; + readonly wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_6: (a: number, b: number, c: any) => [number, number]; + readonly wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_9: (a: number, b: number, c: any) => [number, number]; + readonly wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243: (a: number, b: number, c: any) => void; + readonly wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243_8: (a: number, b: number, c: any) => void; + readonly wasm_bindgen__convert__closures_____invoke__h20343c2d1e7cb4cd: (a: number, b: number) => void; + readonly __wbindgen_malloc: (a: number, b: number) => number; + readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; + readonly __externref_table_alloc: () => number; + readonly __wbindgen_externrefs: WebAssembly.Table; + readonly __wbindgen_exn_store: (a: number) => void; + readonly __wbindgen_free: (a: number, b: number, c: number) => void; + readonly __externref_table_dealloc: (a: number) => void; + readonly __wbindgen_start: () => void; +} + +export type SyncInitInput = BufferSource | WebAssembly.Module; + +/** + * Instantiates the given `module`, which can either be bytes or + * a precompiled `WebAssembly.Module`. + * + * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated. + * + * @returns {InitOutput} + */ +export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput; + +/** + * If `module_or_path` is {RequestInfo} or {URL}, makes a request and + * for everything else, calls `WebAssembly.instantiate` directly. + * + * @param {{ module_or_path: InitInput | Promise }} module_or_path - Passing `InitInput` directly is deprecated. + * + * @returns {Promise} + */ +export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise } | InitInput | Promise): Promise; diff --git a/packages/buttplug/wasm/index.js b/packages/buttplug/wasm/index.js new file mode 100644 index 0000000..e6ffc06 --- /dev/null +++ b/packages/buttplug/wasm/index.js @@ -0,0 +1,814 @@ +/* @ts-self-types="./index.d.ts" */ + +/** + * @param {string} _max_level + */ +export function buttplug_activate_env_logger(_max_level) { + const ptr0 = passStringToWasm0(_max_level, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.buttplug_activate_env_logger(ptr0, len0); +} + +/** + * @param {number} server_ptr + * @param {Uint8Array} buf + * @param {Function} callback + */ +export function buttplug_client_send_json_message(server_ptr, buf, callback) { + const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.buttplug_client_send_json_message(server_ptr, ptr0, len0, callback); +} + +/** + * @param {Function} callback + * @returns {number} + */ +export function buttplug_create_embedded_wasm_server(callback) { + const ret = wasm.buttplug_create_embedded_wasm_server(callback); + return ret >>> 0; +} + +/** + * @param {number} ptr + */ +export function buttplug_free_embedded_wasm_server(ptr) { + wasm.buttplug_free_embedded_wasm_server(ptr); +} + +function __wbg_get_imports() { + const import0 = { + __proto__: null, + __wbg___wbindgen_debug_string_a1b3fd0656850da8: function(arg0, arg1) { + const ret = debugString(arg1); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }, + __wbg___wbindgen_is_function_82aa5b8e9371b250: function(arg0) { + const ret = typeof(arg0) === 'function'; + return ret; + }, + __wbg___wbindgen_is_object_61452b678ecf7ecf: function(arg0) { + const val = arg0; + const ret = typeof(val) === 'object' && val !== null; + return ret; + }, + __wbg___wbindgen_is_string_91960b7ba9d4d76b: function(arg0) { + const ret = typeof(arg0) === 'string'; + return ret; + }, + __wbg___wbindgen_is_undefined_7b12045c262a3121: function(arg0) { + const ret = arg0 === undefined; + return ret; + }, + __wbg___wbindgen_throw_83ebd457a191bc2a: function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }, + __wbg__wbg_cb_unref_4fc42a417bb095f4: function(arg0) { + arg0._wbg_cb_unref(); + }, + __wbg_bluetooth_5967024a158f671e: function(arg0) { + const ret = arg0.bluetooth; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }, + __wbg_buffer_bfae6dde33a7e5a0: function(arg0) { + const ret = arg0.buffer; + return ret; + }, + __wbg_byteLength_5fbecf2b9f6cc625: function(arg0) { + const ret = arg0.byteLength; + return ret; + }, + __wbg_call_72a54043615c73e3: function() { return handleError(function (arg0, arg1, arg2) { + const ret = arg0.call(arg1, arg2); + return ret; + }, arguments); }, + __wbg_connect_61050e3a8e3f5f1c: function(arg0) { + const ret = arg0.connect(); + return ret; + }, + __wbg_crypto_38df2bab126b63dc: function(arg0) { + const ret = arg0.crypto; + return ret; + }, + __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.error(getStringFromWasm0(arg0, arg1)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } + }, + __wbg_gatt_aeca65a254a75f07: function(arg0) { + const ret = arg0.gatt; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }, + __wbg_getCharacteristic_4daa5211272f941c: function(arg0, arg1, arg2) { + const ret = arg0.getCharacteristic(getStringFromWasm0(arg1, arg2)); + return ret; + }, + __wbg_getPrimaryService_8b6197119664f448: function(arg0, arg1, arg2) { + const ret = arg0.getPrimaryService(getStringFromWasm0(arg1, arg2)); + return ret; + }, + __wbg_getRandomValues_3f44b700395062e5: function() { return handleError(function (arg0, arg1) { + globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1)); + }, arguments); }, + __wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) { + arg0.getRandomValues(arg1); + }, arguments); }, + __wbg_getRandomValues_ef8a9e8b447216e2: function() { return handleError(function (arg0, arg1) { + globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1)); + }, arguments); }, + __wbg_get_bda2de250e7f67d3: function() { return handleError(function (arg0, arg1) { + const ret = Reflect.get(arg0, arg1); + return ret; + }, arguments); }, + __wbg_id_c3a9ae039584e9f6: function(arg0, arg1) { + const ret = arg1.id; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }, + __wbg_instanceof_Window_3bc43738919f4587: function(arg0) { + let result; + try { + result = arg0 instanceof Window; + } catch (_) { + result = false; + } + const ret = result; + return ret; + }, + __wbg_length_684e7f4ac265724c: function(arg0) { + const ret = arg0.length; + return ret; + }, + __wbg_log_0c201ade58bb55e1: function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.log(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } + }, + __wbg_log_ce2c4456b290c5e7: function(arg0, arg1) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.log(getStringFromWasm0(arg0, arg1)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } + }, + __wbg_mark_b4d943f3bc2d2404: function(arg0, arg1) { + performance.mark(getStringFromWasm0(arg0, arg1)); + }, + __wbg_measure_84362959e621a2c1: function() { return handleError(function (arg0, arg1, arg2, arg3) { + let deferred0_0; + let deferred0_1; + let deferred1_0; + let deferred1_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + deferred1_0 = arg2; + deferred1_1 = arg3; + performance.measure(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + }, arguments); }, + __wbg_msCrypto_bd5a034af96bcba6: function(arg0) { + const ret = arg0.msCrypto; + return ret; + }, + __wbg_name_0a4944b9b89a9be1: function(arg0, arg1) { + const ret = arg1.name; + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }, + __wbg_navigator_91b141c3f3b6b96b: function(arg0) { + const ret = arg0.navigator; + return ret; + }, + __wbg_new_18cda2e4779f118c: function(arg0) { + const ret = new Uint8Array(arg0); + return ret; + }, + __wbg_new_227d7c05414eb861: function() { + const ret = new Error(); + return ret; + }, + __wbg_new_5c365a7570baea64: function() { + const ret = new Object(); + return ret; + }, + __wbg_new_with_byte_offset_ba99c41da925551a: function(arg0, arg1) { + const ret = new Uint8Array(arg0, arg1 >>> 0); + return ret; + }, + __wbg_new_with_length_875a3f1ab82a1a1f: function(arg0) { + const ret = new Uint8Array(arg0 >>> 0); + return ret; + }, + __wbg_node_84ea875411254db1: function(arg0) { + const ret = arg0.node; + return ret; + }, + __wbg_now_55c5352b4b61d145: function(arg0) { + const ret = arg0.now(); + return ret; + }, + __wbg_now_7627eff456aa5959: function(arg0) { + const ret = arg0.now(); + return ret; + }, + __wbg_performance_aa4d78060a5b8a2f: function(arg0) { + const ret = arg0.performance; + return ret; + }, + __wbg_process_44c7a14e11e9f69e: function(arg0) { + const ret = arg0.process; + return ret; + }, + __wbg_prototypesetcall_7c3092bff32833dc: function(arg0, arg1, arg2) { + Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2); + }, + __wbg_queueMicrotask_17a58d631cc9ab4b: function(arg0) { + queueMicrotask(arg0); + }, + __wbg_queueMicrotask_4114767fcf2790b9: function(arg0) { + const ret = arg0.queueMicrotask; + return ret; + }, + __wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) { + arg0.randomFillSync(arg1); + }, arguments); }, + __wbg_readValue_c83601164f2a0105: function(arg0) { + const ret = arg0.readValue(); + return ret; + }, + __wbg_requestDevice_26b08548120ca1d9: function(arg0, arg1) { + const ret = arg0.requestDevice(arg1); + return ret; + }, + __wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () { + const ret = module.require; + return ret; + }, arguments); }, + __wbg_resolve_67a1b1ca24efbc5c: function(arg0) { + const ret = Promise.resolve(arg0); + return ret; + }, + __wbg_setTimeout_05a790c35d76ff25: function() { return handleError(function (arg0, arg1, arg2) { + const ret = arg0.setTimeout(arg1, arg2); + return ret; + }, arguments); }, + __wbg_set_filters_7e7f78143ddef831: function(arg0, arg1, arg2) { + arg0.filters = getArrayJsValueViewFromWasm0(arg1, arg2); + }, + __wbg_set_name_be5429dc123f1dd9: function(arg0, arg1, arg2) { + arg0.name = getStringFromWasm0(arg1, arg2); + }, + __wbg_set_name_prefix_41b281c72726c519: function(arg0, arg1, arg2) { + arg0.namePrefix = getStringFromWasm0(arg1, arg2); + }, + __wbg_set_oncharacteristicvaluechanged_d54b71ecfbe76b96: function(arg0, arg1) { + arg0.oncharacteristicvaluechanged = arg1; + }, + __wbg_set_ongattserverdisconnected_960815a2e872d5a0: function(arg0, arg1) { + arg0.ongattserverdisconnected = arg1; + }, + __wbg_set_optional_services_e183aa24417dc7cb: function(arg0, arg1, arg2) { + arg0.optionalServices = getArrayJsValueViewFromWasm0(arg1, arg2); + }, + __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) { + const ret = arg1.stack; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }, + __wbg_startNotifications_acc2fc1198e7dd6f: function(arg0) { + const ret = arg0.startNotifications(); + return ret; + }, + __wbg_static_accessor_GLOBAL_833a66cb4996dbd8: function() { + const ret = typeof global === 'undefined' ? null : global; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }, + __wbg_static_accessor_GLOBAL_THIS_fc74cdbdccd80770: function() { + const ret = typeof globalThis === 'undefined' ? null : globalThis; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }, + __wbg_static_accessor_SELF_066699022f35d48b: function() { + const ret = typeof self === 'undefined' ? null : self; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }, + __wbg_static_accessor_WINDOW_f821c7eb05393790: function() { + const ret = typeof window === 'undefined' ? null : window; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }, + __wbg_subarray_22ac454570db4e4f: function(arg0, arg1, arg2) { + const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0); + return ret; + }, + __wbg_target_188bf8368fa5f001: function(arg0) { + const ret = arg0.target; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }, + __wbg_then_420f698ab0b99678: function(arg0, arg1) { + const ret = arg0.then(arg1); + return ret; + }, + __wbg_then_95c29fbd346ee84e: function(arg0, arg1, arg2) { + const ret = arg0.then(arg1, arg2); + return ret; + }, + __wbg_value_d1ef9362b7bf7a47: function(arg0) { + const ret = arg0.value; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }, + __wbg_versions_276b2795b1c6a219: function(arg0) { + const ret = arg0.versions; + return ret; + }, + __wbg_writeValue_99570c64ee612498: function() { return handleError(function (arg0, arg1) { + const ret = arg0.writeValue(arg1); + return ret; + }, arguments); }, + __wbindgen_cast_0000000000000001: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 3402, function: Function { arguments: [Externref], shim_idx: 3403, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h72b504abf7ea70fd, wasm_bindgen__convert__closures_____invoke__hcd253b168dd40e38); + return ret; + }, + __wbindgen_cast_0000000000000002: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 3413, function: Function { arguments: [], shim_idx: 3414, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__ha3c8e2c9b0cf79cd, wasm_bindgen__convert__closures_____invoke__h20343c2d1e7cb4cd); + return ret; + }, + __wbindgen_cast_0000000000000003: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 80, function: Function { arguments: [NamedExternref("BluetoothDevice")], shim_idx: 81, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0f95d90d24796def, wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1); + return ret; + }, + __wbindgen_cast_0000000000000004: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 80, function: Function { arguments: [NamedExternref("BluetoothRemoteGATTCharacteristic")], shim_idx: 81, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0f95d90d24796def, wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_3); + return ret; + }, + __wbindgen_cast_0000000000000005: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 80, function: Function { arguments: [NamedExternref("BluetoothRemoteGATTServer")], shim_idx: 81, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0f95d90d24796def, wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_4); + return ret; + }, + __wbindgen_cast_0000000000000006: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 80, function: Function { arguments: [NamedExternref("BluetoothRemoteGATTService")], shim_idx: 81, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0f95d90d24796def, wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_5); + return ret; + }, + __wbindgen_cast_0000000000000007: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 80, function: Function { arguments: [NamedExternref("DataView")], shim_idx: 81, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0f95d90d24796def, wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_6); + return ret; + }, + __wbindgen_cast_0000000000000008: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 80, function: Function { arguments: [NamedExternref("Event")], shim_idx: 86, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0f95d90d24796def, wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243); + return ret; + }, + __wbindgen_cast_0000000000000009: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 80, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 86, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0f95d90d24796def, wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243_8); + return ret; + }, + __wbindgen_cast_000000000000000a: function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 80, function: Function { arguments: [NamedExternref("undefined")], shim_idx: 81, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h0f95d90d24796def, wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_9); + return ret; + }, + __wbindgen_cast_000000000000000b: function(arg0, arg1) { + // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`. + const ret = getArrayU8FromWasm0(arg0, arg1); + return ret; + }, + __wbindgen_cast_000000000000000c: function(arg0, arg1) { + // Cast intrinsic for `Ref(String) -> Externref`. + const ret = getStringFromWasm0(arg0, arg1); + return ret; + }, + __wbindgen_init_externref_table: function() { + const table = wasm.__wbindgen_externrefs; + const offset = table.grow(4); + table.set(0, undefined); + table.set(offset + 0, undefined); + table.set(offset + 1, null); + table.set(offset + 2, true); + table.set(offset + 3, false); + }, + }; + return { + __proto__: null, + "./index_bg.js": import0, + }; +} + +function wasm_bindgen__convert__closures_____invoke__h20343c2d1e7cb4cd(arg0, arg1) { + wasm.wasm_bindgen__convert__closures_____invoke__h20343c2d1e7cb4cd(arg0, arg1); +} + +function wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243(arg0, arg1, arg2) { + wasm.wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243(arg0, arg1, arg2); +} + +function wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243_8(arg0, arg1, arg2) { + wasm.wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243_8(arg0, arg1, arg2); +} + +function wasm_bindgen__convert__closures_____invoke__hcd253b168dd40e38(arg0, arg1, arg2) { + const ret = wasm.wasm_bindgen__convert__closures_____invoke__hcd253b168dd40e38(arg0, arg1, arg2); + if (ret[1]) { + throw takeFromExternrefTable0(ret[0]); + } +} + +function wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1(arg0, arg1, arg2) { + const ret = wasm.wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1(arg0, arg1, arg2); + if (ret[1]) { + throw takeFromExternrefTable0(ret[0]); + } +} + +function wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_3(arg0, arg1, arg2) { + const ret = wasm.wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_3(arg0, arg1, arg2); + if (ret[1]) { + throw takeFromExternrefTable0(ret[0]); + } +} + +function wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_4(arg0, arg1, arg2) { + const ret = wasm.wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_4(arg0, arg1, arg2); + if (ret[1]) { + throw takeFromExternrefTable0(ret[0]); + } +} + +function wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_5(arg0, arg1, arg2) { + const ret = wasm.wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_5(arg0, arg1, arg2); + if (ret[1]) { + throw takeFromExternrefTable0(ret[0]); + } +} + +function wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_6(arg0, arg1, arg2) { + const ret = wasm.wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_6(arg0, arg1, arg2); + if (ret[1]) { + throw takeFromExternrefTable0(ret[0]); + } +} + +function wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_9(arg0, arg1, arg2) { + const ret = wasm.wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_9(arg0, arg1, arg2); + if (ret[1]) { + throw takeFromExternrefTable0(ret[0]); + } +} + +function addToExternrefTable0(obj) { + const idx = wasm.__externref_table_alloc(); + wasm.__wbindgen_externrefs.set(idx, obj); + return idx; +} + +const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(state => state.dtor(state.a, state.b)); + +function debugString(val) { + // primitive types + const type = typeof val; + if (type == 'number' || type == 'boolean' || val == null) { + return `${val}`; + } + if (type == 'string') { + return `"${val}"`; + } + if (type == 'symbol') { + const description = val.description; + if (description == null) { + return 'Symbol'; + } else { + return `Symbol(${description})`; + } + } + if (type == 'function') { + const name = val.name; + if (typeof name == 'string' && name.length > 0) { + return `Function(${name})`; + } else { + return 'Function'; + } + } + // objects + if (Array.isArray(val)) { + const length = val.length; + let debug = '['; + if (length > 0) { + debug += debugString(val[0]); + } + for(let i = 1; i < length; i++) { + debug += ', ' + debugString(val[i]); + } + debug += ']'; + return debug; + } + // Test for built-in + const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); + let className; + if (builtInMatches && builtInMatches.length > 1) { + className = builtInMatches[1]; + } else { + // Failed to match the standard '[object ClassName]' + return toString.call(val); + } + if (className == 'Object') { + // we're a user defined class or Object + // JSON.stringify avoids problems with cycles, and is generally much + // easier than looping through ownProperties of `val`. + try { + return 'Object(' + JSON.stringify(val) + ')'; + } catch (_) { + return 'Object'; + } + } + // errors + if (val instanceof Error) { + return `${val.name}: ${val.message}\n${val.stack}`; + } + // TODO we could test for more things here, like `Set`s and `Map`s. + return className; +} + +function getArrayJsValueViewFromWasm0(ptr, len) { + ptr = ptr >>> 0; + const mem = getDataViewMemory0(); + const result = []; + for (let i = ptr; i < ptr + 4 * len; i += 4) { + result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true))); + } + return result; +} + +function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); +} + +let cachedDataViewMemory0 = null; +function getDataViewMemory0() { + if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { + cachedDataViewMemory0 = new DataView(wasm.memory.buffer); + } + return cachedDataViewMemory0; +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return decodeText(ptr, len); +} + +let cachedUint8ArrayMemory0 = null; +function getUint8ArrayMemory0() { + if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { + cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8ArrayMemory0; +} + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + const idx = addToExternrefTable0(e); + wasm.__wbindgen_exn_store(idx); + } +} + +function isLikeNone(x) { + return x === undefined || x === null; +} + +function makeMutClosure(arg0, arg1, dtor, f) { + const state = { a: arg0, b: arg1, cnt: 1, dtor }; + const real = (...args) => { + + // First up with a closure we increment the internal reference + // count. This ensures that the Rust closure environment won't + // be deallocated while we're invoking it. + state.cnt++; + const a = state.a; + state.a = 0; + try { + return f(a, state.b, ...args); + } finally { + state.a = a; + real._wbg_cb_unref(); + } + }; + real._wbg_cb_unref = () => { + if (--state.cnt === 0) { + state.dtor(state.a, state.b); + state.a = 0; + CLOSURE_DTORS.unregister(state); + } + }; + CLOSURE_DTORS.register(real, state, state); + return real; +} + +function passArray8ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 1, 1) >>> 0; + getUint8ArrayMemory0().set(arg, ptr / 1); + WASM_VECTOR_LEN = arg.length; + return ptr; +} + +function passStringToWasm0(arg, malloc, realloc) { + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + + const mem = getUint8ArrayMemory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; + const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); + const ret = cachedTextEncoder.encodeInto(arg, view); + + offset += ret.written; + ptr = realloc(ptr, len, offset, 1) >>> 0; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +function takeFromExternrefTable0(idx) { + const value = wasm.__wbindgen_externrefs.get(idx); + wasm.__externref_table_dealloc(idx); + return value; +} + +let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +cachedTextDecoder.decode(); +const MAX_SAFARI_DECODE_BYTES = 2146435072; +let numBytesDecoded = 0; +function decodeText(ptr, len) { + numBytesDecoded += len; + if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) { + cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); + cachedTextDecoder.decode(); + numBytesDecoded = len; + } + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); +} + +const cachedTextEncoder = new TextEncoder(); + +if (!('encodeInto' in cachedTextEncoder)) { + cachedTextEncoder.encodeInto = function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; + }; +} + +let WASM_VECTOR_LEN = 0; + +let wasmModule, wasm; +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + wasmModule = module; + cachedDataViewMemory0 = null; + cachedUint8ArrayMemory0 = null; + wasm.__wbindgen_start(); + return wasm; +} + +async function __wbg_load(module, imports) { + if (typeof Response === 'function' && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === 'function') { + try { + return await WebAssembly.instantiateStreaming(module, imports); + } catch (e) { + const validResponse = module.ok && expectedResponseType(module.type); + + if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') { + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + + } else { throw e; } + } + } + + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + } else { + const instance = await WebAssembly.instantiate(module, imports); + + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + } else { + return instance; + } + } + + function expectedResponseType(type) { + switch (type) { + case 'basic': case 'cors': case 'default': return true; + } + return false; + } +} + +function initSync(module) { + if (wasm !== undefined) return wasm; + + + if (module !== undefined) { + if (Object.getPrototypeOf(module) === Object.prototype) { + ({module} = module) + } else { + console.warn('using deprecated parameters for `initSync()`; pass a single object instead') + } + } + + const imports = __wbg_get_imports(); + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + const instance = new WebAssembly.Instance(module, imports); + return __wbg_finalize_init(instance, module); +} + +async function __wbg_init(module_or_path) { + if (wasm !== undefined) return wasm; + + + if (module_or_path !== undefined) { + if (Object.getPrototypeOf(module_or_path) === Object.prototype) { + ({module_or_path} = module_or_path) + } else { + console.warn('using deprecated parameters for the initialization function; pass a single object instead') + } + } + + if (module_or_path === undefined) { + module_or_path = new URL('index_bg.wasm', import.meta.url); + } + const imports = __wbg_get_imports(); + + if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { + module_or_path = fetch(module_or_path); + } + + const { instance, module } = await __wbg_load(await module_or_path, imports); + + return __wbg_finalize_init(instance, module); +} + +export { initSync, __wbg_init as default }; diff --git a/packages/buttplug/wasm/index_bg.js b/packages/buttplug/wasm/index_bg.js new file mode 100644 index 0000000..a1534b6 --- /dev/null +++ b/packages/buttplug/wasm/index_bg.js @@ -0,0 +1,770 @@ +let wasm; +export function __wbg_set_wasm(val) { + wasm = val; +} + +function isLikeNone(x) { + return x === undefined || x === null; +} + +function addToExternrefTable0(obj) { + const idx = wasm.__externref_table_alloc(); + wasm.__wbindgen_export_1.set(idx, obj); + return idx; +} + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + const idx = addToExternrefTable0(e); + wasm.__wbindgen_exn_store(idx); + } +} + +let cachedUint8ArrayMemory0 = null; + +function getUint8ArrayMemory0() { + if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { + cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8ArrayMemory0; +} + +const lTextDecoder = + typeof TextDecoder === "undefined" ? (0, module.require)("util").TextDecoder : TextDecoder; + +let cachedTextDecoder = new lTextDecoder("utf-8", { ignoreBOM: true, fatal: true }); + +cachedTextDecoder.decode(); + +const MAX_SAFARI_DECODE_BYTES = 2146435072; +let numBytesDecoded = 0; +function decodeText(ptr, len) { + numBytesDecoded += len; + if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) { + cachedTextDecoder = new lTextDecoder("utf-8", { ignoreBOM: true, fatal: true }); + cachedTextDecoder.decode(); + numBytesDecoded = len; + } + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return decodeText(ptr, len); +} + +function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); +} + +let WASM_VECTOR_LEN = 0; + +const lTextEncoder = + typeof TextEncoder === "undefined" ? (0, module.require)("util").TextEncoder : TextEncoder; + +const cachedTextEncoder = new lTextEncoder("utf-8"); + +const encodeString = + typeof cachedTextEncoder.encodeInto === "function" + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); + } + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length, + }; + }; + +function passStringToWasm0(arg, malloc, realloc) { + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8ArrayMemory0() + .subarray(ptr, ptr + buf.length) + .set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + + const mem = getUint8ArrayMemory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7f) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0; + const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + ptr = realloc(ptr, len, offset, 1) >>> 0; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +let cachedDataViewMemory0 = null; + +function getDataViewMemory0() { + if ( + cachedDataViewMemory0 === null || + cachedDataViewMemory0.buffer.detached === true || + (cachedDataViewMemory0.buffer.detached === undefined && + cachedDataViewMemory0.buffer !== wasm.memory.buffer) + ) { + cachedDataViewMemory0 = new DataView(wasm.memory.buffer); + } + return cachedDataViewMemory0; +} + +function debugString(val) { + // primitive types + const type = typeof val; + if (type == "number" || type == "boolean" || val == null) { + return `${val}`; + } + if (type == "string") { + return `"${val}"`; + } + if (type == "symbol") { + const description = val.description; + if (description == null) { + return "Symbol"; + } else { + return `Symbol(${description})`; + } + } + if (type == "function") { + const name = val.name; + if (typeof name == "string" && name.length > 0) { + return `Function(${name})`; + } else { + return "Function"; + } + } + // objects + if (Array.isArray(val)) { + const length = val.length; + let debug = "["; + if (length > 0) { + debug += debugString(val[0]); + } + for (let i = 1; i < length; i++) { + debug += ", " + debugString(val[i]); + } + debug += "]"; + return debug; + } + // Test for built-in + const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); + let className; + if (builtInMatches && builtInMatches.length > 1) { + className = builtInMatches[1]; + } else { + // Failed to match the standard '[object ClassName]' + return toString.call(val); + } + if (className == "Object") { + // we're a user defined class or Object + // JSON.stringify avoids problems with cycles, and is generally much + // easier than looping through ownProperties of `val`. + try { + return "Object(" + JSON.stringify(val) + ")"; + } catch (_) { + return "Object"; + } + } + // errors + if (val instanceof Error) { + return `${val.name}: ${val.message}\n${val.stack}`; + } + // TODO we could test for more things here, like `Set`s and `Map`s. + return className; +} + +const CLOSURE_DTORS = + typeof FinalizationRegistry === "undefined" + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((state) => { + wasm.__wbindgen_export_6.get(state.dtor)(state.a, state.b); + }); + +function makeMutClosure(arg0, arg1, dtor, f) { + const state = { a: arg0, b: arg1, cnt: 1, dtor }; + const real = (...args) => { + // First up with a closure we increment the internal reference + // count. This ensures that the Rust closure environment won't + // be deallocated while we're invoking it. + state.cnt++; + const a = state.a; + state.a = 0; + try { + return f(a, state.b, ...args); + } finally { + if (--state.cnt === 0) { + wasm.__wbindgen_export_6.get(state.dtor)(a, state.b); + CLOSURE_DTORS.unregister(state); + } else { + state.a = a; + } + } + }; + real.original = state; + CLOSURE_DTORS.register(real, state, state); + return real; +} + +function passArray8ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 1, 1) >>> 0; + getUint8ArrayMemory0().set(arg, ptr / 1); + WASM_VECTOR_LEN = arg.length; + return ptr; +} +/** + * @param {number} server_ptr + * @param {Uint8Array} buf + * @param {Function} callback + */ +export function buttplug_client_send_json_message(server_ptr, buf, callback) { + const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.buttplug_client_send_json_message(server_ptr, ptr0, len0, callback); +} + +/** + * @param {number} ptr + */ +export function buttplug_free_embedded_wasm_server(ptr) { + wasm.buttplug_free_embedded_wasm_server(ptr); +} + +/** + * @param {string} _max_level + */ +export function buttplug_activate_env_logger(_max_level) { + const ptr0 = passStringToWasm0(_max_level, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.buttplug_activate_env_logger(ptr0, len0); +} + +/** + * @param {Function} callback + * @returns {number} + */ +export function buttplug_create_embedded_wasm_server(callback) { + const ret = wasm.buttplug_create_embedded_wasm_server(callback); + return ret >>> 0; +} + +function __wbg_adapter_8(arg0, arg1, arg2) { + wasm.closure3251_externref_shim(arg0, arg1, arg2); +} + +function __wbg_adapter_11(arg0, arg1, arg2) { + wasm.closure202_externref_shim(arg0, arg1, arg2); +} + +function __wbg_adapter_16(arg0, arg1) { + wasm.wasm_bindgen__convert__closures_____invoke__h239e120689ecd2a1(arg0, arg1); +} + +export function __wbg_bluetooth_b95c3b6935c8a51a(arg0) { + const ret = arg0.bluetooth; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); +} + +export function __wbg_buffer_068eb5b0fbad96d8(arg0) { + const ret = arg0.buffer; + return ret; +} + +export function __wbg_byteLength_59ab6482fa6cb38b(arg0) { + const ret = arg0.byteLength; + return ret; +} + +export function __wbg_call_2f8d426a20a307fe() { + return handleError(function (arg0, arg1) { + const ret = arg0.call(arg1); + return ret; + }, arguments); +} + +export function __wbg_call_f53f0647ceb9c567() { + return handleError(function (arg0, arg1, arg2) { + const ret = arg0.call(arg1, arg2); + return ret; + }, arguments); +} + +export function __wbg_connect_b91d2ba90a1ff675(arg0) { + const ret = arg0.connect(); + return ret; +} + +export function __wbg_crypto_86f2631e91b51511(arg0) { + const ret = arg0.crypto; + return ret; +} + +export function __wbg_error_7534b8e9a36f1ab4(arg0, arg1) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.error(getStringFromWasm0(arg0, arg1)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } +} + +export function __wbg_gatt_06b2bdb9e7f8fb84(arg0) { + const ret = arg0.gatt; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); +} + +export function __wbg_getCharacteristic_1cb1de10f54aa049(arg0, arg1, arg2) { + const ret = arg0.getCharacteristic(getStringFromWasm0(arg1, arg2)); + return ret; +} + +export function __wbg_getPrimaryService_f8c0b8be4fded7fd(arg0, arg1, arg2) { + const ret = arg0.getPrimaryService(getStringFromWasm0(arg1, arg2)); + return ret; +} + +export function __wbg_getRandomValues_1c61fac11405ffdc() { + return handleError(function (arg0, arg1) { + globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1)); + }, arguments); +} + +export function __wbg_getRandomValues_9c5c1b115e142bb8() { + return handleError(function (arg0, arg1) { + globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1)); + }, arguments); +} + +export function __wbg_getRandomValues_b3f15fcbfabb0f8b() { + return handleError(function (arg0, arg1) { + arg0.getRandomValues(arg1); + }, arguments); +} + +export function __wbg_get_27b4bcbec57323ca() { + return handleError(function (arg0, arg1) { + const ret = Reflect.get(arg0, arg1); + return ret; + }, arguments); +} + +export function __wbg_id_d769eab9a0939b42(arg0, arg1) { + const ret = arg1.id; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); +} + +export function __wbg_instanceof_Window_7f29e5c72acbfd60(arg0) { + let result; + try { + result = arg0 instanceof Window; + } catch (_) { + result = false; + } + const ret = result; + return ret; +} + +export function __wbg_length_904c0910ed998bf3(arg0) { + const ret = arg0.length; + return ret; +} + +export function __wbg_log_0cc1b7768397bcfe(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.log( + getStringFromWasm0(arg0, arg1), + getStringFromWasm0(arg2, arg3), + getStringFromWasm0(arg4, arg5), + getStringFromWasm0(arg6, arg7), + ); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } +} + +export function __wbg_log_cb9e190acc5753fb(arg0, arg1) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.log(getStringFromWasm0(arg0, arg1)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } +} + +export function __wbg_mark_7438147ce31e9d4b(arg0, arg1) { + performance.mark(getStringFromWasm0(arg0, arg1)); +} + +export function __wbg_measure_fb7825c11612c823() { + return handleError(function (arg0, arg1, arg2, arg3) { + let deferred0_0; + let deferred0_1; + let deferred1_0; + let deferred1_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + deferred1_0 = arg2; + deferred1_1 = arg3; + performance.measure(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + }, arguments); +} + +export function __wbg_msCrypto_d562bbe83e0d4b91(arg0) { + const ret = arg0.msCrypto; + return ret; +} + +export function __wbg_name_cf5d973f5e1d9b1e(arg0, arg1) { + const ret = arg1.name; + var ptr1 = isLikeNone(ret) + ? 0 + : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); +} + +export function __wbg_navigator_b6d1cae68d750613(arg0) { + const ret = arg0.navigator; + return ret; +} + +export function __wbg_new_1930cbb8d9ffc31b() { + const ret = new Object(); + return ret; +} + +export function __wbg_new_8a6f238a6ece86ea() { + const ret = new Error(); + return ret; +} + +export function __wbg_new_9190433fb67ed635(arg0) { + const ret = new Uint8Array(arg0); + return ret; +} + +export function __wbg_new_e969dc3f68d25093() { + const ret = []; + return ret; +} + +export function __wbg_newnoargs_a81330f6e05d8aca(arg0, arg1) { + const ret = new Function(getStringFromWasm0(arg0, arg1)); + return ret; +} + +export function __wbg_newwithbyteoffset_b204dc995f2352f4(arg0, arg1) { + const ret = new Uint8Array(arg0, arg1 >>> 0); + return ret; +} + +export function __wbg_newwithlength_ed0ee6c1edca86fc(arg0) { + const ret = new Uint8Array(arg0 >>> 0); + return ret; +} + +export function __wbg_node_e1f24f89a7336c2e(arg0) { + const ret = arg0.node; + return ret; +} + +export function __wbg_now_0dc4920a47cf7280(arg0) { + const ret = arg0.now(); + return ret; +} + +export function __wbg_now_1f875e5cd673bc3c(arg0) { + const ret = arg0.now(); + return ret; +} + +export function __wbg_performance_6adc3b899e448a23(arg0) { + const ret = arg0.performance; + return ret; +} + +export function __wbg_process_3975fd6c72f520aa(arg0) { + const ret = arg0.process; + return ret; +} + +export function __wbg_prototypesetcall_c5f74efd31aea86b(arg0, arg1, arg2) { + Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2); +} + +export function __wbg_push_cd3ac7d5b094565d(arg0, arg1) { + const ret = arg0.push(arg1); + return ret; +} + +export function __wbg_queueMicrotask_bcc6e26d899696db(arg0) { + const ret = arg0.queueMicrotask; + return ret; +} + +export function __wbg_queueMicrotask_f24a794d09c42640(arg0) { + queueMicrotask(arg0); +} + +export function __wbg_randomFillSync_f8c153b79f285817() { + return handleError(function (arg0, arg1) { + arg0.randomFillSync(arg1); + }, arguments); +} + +export function __wbg_readValue_9d41d1a73a07165f(arg0) { + const ret = arg0.readValue(); + return ret; +} + +export function __wbg_requestDevice_17840c36162ed342(arg0, arg1) { + const ret = arg0.requestDevice(arg1); + return ret; +} + +export function __wbg_require_b74f47fc2d022fd6() { + return handleError(function () { + const ret = module.require; + return ret; + }, arguments); +} + +export function __wbg_resolve_5775c0ef9222f556(arg0) { + const ret = Promise.resolve(arg0); + return ret; +} + +export function __wbg_setTimeout_63008613644b07af() { + return handleError(function (arg0, arg1, arg2) { + const ret = arg0.setTimeout(arg1, arg2); + return ret; + }, arguments); +} + +export function __wbg_setfilters_b142ba75a84ace1a(arg0, arg1) { + arg0.filters = arg1; +} + +export function __wbg_setname_decc08ea308195a6(arg0, arg1, arg2) { + arg0.name = getStringFromWasm0(arg1, arg2); +} + +export function __wbg_setnameprefix_3c1f973506cd8f08(arg0, arg1, arg2) { + arg0.namePrefix = getStringFromWasm0(arg1, arg2); +} + +export function __wbg_setoncharacteristicvaluechanged_a126981aa4e69da5(arg0, arg1) { + arg0.oncharacteristicvaluechanged = arg1; +} + +export function __wbg_setongattserverdisconnected_d43d7f3a48a58fa4(arg0, arg1) { + arg0.ongattserverdisconnected = arg1; +} + +export function __wbg_setoptionalservices_b6c19589e7aa503e(arg0, arg1) { + arg0.optionalServices = arg1; +} + +export function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) { + const ret = arg1.stack; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); +} + +export function __wbg_startNotifications_e1edb2183f9289f5(arg0) { + const ret = arg0.startNotifications(); + return ret; +} + +export function __wbg_static_accessor_GLOBAL_1f13249cc3acc96d() { + const ret = typeof global === "undefined" ? null : global; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); +} + +export function __wbg_static_accessor_GLOBAL_THIS_df7ae94b1e0ed6a3() { + const ret = typeof globalThis === "undefined" ? null : globalThis; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); +} + +export function __wbg_static_accessor_SELF_6265471db3b3c228() { + const ret = typeof self === "undefined" ? null : self; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); +} + +export function __wbg_static_accessor_WINDOW_16fb482f8ec52863() { + const ret = typeof window === "undefined" ? null : window; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); +} + +export function __wbg_subarray_a219824899e59712(arg0, arg1, arg2) { + const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0); + return ret; +} + +export function __wbg_target_bfb4281bfa013115(arg0) { + const ret = arg0.target; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); +} + +export function __wbg_then_8d2fcccde5380a03(arg0, arg1, arg2) { + const ret = arg0.then(arg1, arg2); + return ret; +} + +export function __wbg_then_9cc266be2bf537b6(arg0, arg1) { + const ret = arg0.then(arg1); + return ret; +} + +export function __wbg_value_5e240e44f81872c5(arg0) { + const ret = arg0.value; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); +} + +export function __wbg_versions_4e31226f5e8dc909(arg0) { + const ret = arg0.versions; + return ret; +} + +export function __wbg_wbindgencbdrop_a85ed476c6a370b9(arg0) { + const obj = arg0.original; + if (obj.cnt-- == 1) { + obj.a = 0; + return true; + } + const ret = false; + return ret; +} + +export function __wbg_wbindgendebugstring_bb652b1bc2061b6d(arg0, arg1) { + const ret = debugString(arg1); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); +} + +export function __wbg_wbindgenisfunction_ea72b9d66a0e1705(arg0) { + const ret = typeof arg0 === "function"; + return ret; +} + +export function __wbg_wbindgenisobject_dfe064a121d87553(arg0) { + const val = arg0; + const ret = typeof val === "object" && val !== null; + return ret; +} + +export function __wbg_wbindgenisstring_4b74e4111ba029e6(arg0) { + const ret = typeof arg0 === "string"; + return ret; +} + +export function __wbg_wbindgenisundefined_71f08a6ade4354e7(arg0) { + const ret = arg0 === undefined; + return ret; +} + +export function __wbg_wbindgenthrow_4c11a24fca429ccf(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); +} + +export function __wbg_writeValue_586734e0fc6e7c73() { + return handleError(function (arg0, arg1) { + const ret = arg0.writeValue(arg1); + return ret; + }, arguments); +} + +export function __wbindgen_cast_0f76fca626397b3d(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 201, function: Function { arguments: [NamedExternref("Event")], shim_idx: 202, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, 201, __wbg_adapter_11); + return ret; +} + +export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) { + // Cast intrinsic for `Ref(String) -> Externref`. + const ret = getStringFromWasm0(arg0, arg1); + return ret; +} + +export function __wbindgen_cast_30a893855537e77b(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 201, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 202, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, 201, __wbg_adapter_11); + return ret; +} + +export function __wbindgen_cast_76c05e7c8d82d9b7(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 3269, function: Function { arguments: [], shim_idx: 3270, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, 3269, __wbg_adapter_16); + return ret; +} + +export function __wbindgen_cast_cb3d47e2c086b274(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 3250, function: Function { arguments: [Externref], shim_idx: 3251, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, 3250, __wbg_adapter_8); + return ret; +} + +export function __wbindgen_cast_cb9088102bce6b30(arg0, arg1) { + // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`. + const ret = getArrayU8FromWasm0(arg0, arg1); + return ret; +} + +export function __wbindgen_init_externref_table() { + const table = wasm.__wbindgen_export_1; + const offset = table.grow(4); + table.set(0, undefined); + table.set(offset + 0, undefined); + table.set(offset + 1, null); + table.set(offset + 2, true); + table.set(offset + 3, false); +} diff --git a/packages/buttplug/wasm/index_bg.wasm b/packages/buttplug/wasm/index_bg.wasm new file mode 100644 index 0000000..26f5b1f Binary files /dev/null and b/packages/buttplug/wasm/index_bg.wasm differ diff --git a/packages/buttplug/wasm/index_bg.wasm.d.ts b/packages/buttplug/wasm/index_bg.wasm.d.ts new file mode 100644 index 0000000..2d740ee --- /dev/null +++ b/packages/buttplug/wasm/index_bg.wasm.d.ts @@ -0,0 +1,29 @@ +/* tslint:disable */ +/* eslint-disable */ +export const memory: WebAssembly.Memory; +export const create_test_dcm: (a: number, b: number) => void; +export const buttplug_activate_env_logger: (a: number, b: number) => void; +export const buttplug_client_send_json_message: (a: number, b: number, c: number, d: any) => void; +export const buttplug_create_embedded_wasm_server: (a: any) => number; +export const buttplug_free_embedded_wasm_server: (a: number) => void; +export const wasm_bindgen__closure__destroy__h72b504abf7ea70fd: (a: number, b: number) => void; +export const wasm_bindgen__closure__destroy__ha3c8e2c9b0cf79cd: (a: number, b: number) => void; +export const wasm_bindgen__closure__destroy__h0f95d90d24796def: (a: number, b: number) => void; +export const wasm_bindgen__convert__closures_____invoke__hcd253b168dd40e38: (a: number, b: number, c: any) => [number, number]; +export const wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1: (a: number, b: number, c: any) => [number, number]; +export const wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_3: (a: number, b: number, c: any) => [number, number]; +export const wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_4: (a: number, b: number, c: any) => [number, number]; +export const wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_5: (a: number, b: number, c: any) => [number, number]; +export const wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_6: (a: number, b: number, c: any) => [number, number]; +export const wasm_bindgen__convert__closures_____invoke__h0628356d4885b6d1_9: (a: number, b: number, c: any) => [number, number]; +export const wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243: (a: number, b: number, c: any) => void; +export const wasm_bindgen__convert__closures_____invoke__h996ec8878d3e4243_8: (a: number, b: number, c: any) => void; +export const wasm_bindgen__convert__closures_____invoke__h20343c2d1e7cb4cd: (a: number, b: number) => void; +export const __wbindgen_malloc: (a: number, b: number) => number; +export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; +export const __externref_table_alloc: () => number; +export const __wbindgen_externrefs: WebAssembly.Table; +export const __wbindgen_exn_store: (a: number) => void; +export const __wbindgen_free: (a: number, b: number, c: number) => void; +export const __externref_table_dealloc: (a: number) => void; +export const __wbindgen_start: () => void; diff --git a/packages/buttplug/wasm/package.json b/packages/buttplug/wasm/package.json new file mode 100644 index 0000000..77270cd --- /dev/null +++ b/packages/buttplug/wasm/package.json @@ -0,0 +1,32 @@ +{ + "name": "buttplug_wasm", + "type": "module", + "collaborators": [ + "Nonpolynomial Labs, LLC " + ], + "description": "WASM Interop for the Buttplug Intimate Hardware Control Library", + "version": "10.0.0", + "license": "BSD-3-Clause", + "repository": { + "type": "git", + "url": "https://github.com/buttplugio/buttplug.git" + }, + "files": [ + "index_bg.wasm", + "index.js", + "index.d.ts" + ], + "main": "index.js", + "homepage": "http://buttplug.io", + "types": "index.d.ts", + "sideEffects": [ + "./snippets/*" + ], + "keywords": [ + "usb", + "serial", + "hardware", + "bluetooth", + "teledildonics" + ] +} \ No newline at end of file