File Explorer

/proc/self/root/var/runtime/node_modules/@aws-sdk/node_modules/aws-crt/dist/common

This explorer reads the filesystem of the server it runs on, so /workspace/user isn't present here. Browsing and the terminal still work against this server's own disk from /.

mqtt_shared.js6.5 KB · 173 lines
"use strict";/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */Object.defineProperty(exports, "__esModule", { value: true });exports.PublishAcknowledgementHandle = exports.queueAcknowledgeableEvent = exports.emitAcknowledgeableEvent = exports.PublishAcknowledgementHandleWrapper = exports.DEFAULT_RECEIVE_MAXIMUM = exports.MAXIMUM_PACKET_SIZE = exports.MAXIMUM_VARIABLE_LENGTH_INTEGER = exports.DEFAULT_KEEP_ALIVE = exports.AWSIoTMetrics = exports.SDK_NAME = exports.normalize_payload = exports.ProtocolMode = void 0;/** * @internal */var ProtocolMode;(function (ProtocolMode) {    ProtocolMode[ProtocolMode["Mqtt311"] = 0] = "Mqtt311";    ProtocolMode[ProtocolMode["Mqtt5"] = 1] = "Mqtt5";})(ProtocolMode = exports.ProtocolMode || (exports.ProtocolMode = {}));/** * Converts payload to Buffer or string regardless of the supplied type * @param payload The payload to convert * @internal */function normalize_payload(payload) {    if (payload instanceof Buffer) {        // pass Buffer through        return payload;    }    if (typeof payload === 'string') {        // pass string through        return payload;    }    if (ArrayBuffer.isView(payload)) {        // return Buffer with view upon the same bytes (no copy)        const view = payload;        return Buffer.from(view.buffer, view.byteOffset, view.byteLength);    }    if (payload instanceof ArrayBuffer) {        // return Buffer with view upon the same bytes (no copy)        return Buffer.from(payload);    }    if (typeof payload === 'object') {        // Convert Object to JSON string        return JSON.stringify(payload);    }    if (!payload) {        return "";    }    throw new TypeError("payload parameter must be a string, object, or DataView.");}exports.normalize_payload = normalize_payload;/** * SDK name used for metrics and identification * @internal */exports.SDK_NAME = "IoTDeviceSDK/JS";/** * IoT Device SDK Metrics Structure */class AWSIoTMetrics {    constructor() {        /**         * Name of the library         */        this.libraryName = exports.SDK_NAME;        this.metadata = new Array;    }}exports.AWSIoTMetrics = AWSIoTMetrics;/** @internal */exports.DEFAULT_KEEP_ALIVE = 1200;/** @internal */exports.MAXIMUM_VARIABLE_LENGTH_INTEGER = 268435455;/** @internal */exports.MAXIMUM_PACKET_SIZE = 5 + exports.MAXIMUM_VARIABLE_LENGTH_INTEGER;/** @internal */exports.DEFAULT_RECEIVE_MAXIMUM = 65535;/** * Wrapper class containing a one-use singleton handle that can be used to trigger sending the acknowledgement (Puback in * QoS 1, Pubrec in QoS 2) packet for an incoming publish. */class PublishAcknowledgementHandleWrapper {    constructor(handle) {        this.ackHandle = handle;    }    /**     * Attempt to take the acknowledgement handle held by the wrapper.  This will only succeed for the first caller;     * after the initial call, null will be returned.  By taking the handle, the caller assumes responsibility     * for sending the acknowledgement packet associated with the incoming publish packet.  Failing to trigger the     * acknowledgement will cause the broker to potentially re-send the publish.     */    acquireHandle() {        let handle = this.ackHandle;        this.ackHandle = null;        return handle;    }}exports.PublishAcknowledgementHandleWrapper = PublishAcknowledgementHandleWrapper;function movePublishAcknowledgementHandleWrapper(wrapper, compositionFunctor) {    if (wrapper) {        let handle = wrapper.acquireHandle();        if (compositionFunctor && handle) {            let interiorHandle = handle;            handle = new PublishAcknowledgementHandle(() => {                interiorHandle.invokeAcknowledgement();                compositionFunctor();            });        }        return new PublishAcknowledgementHandleWrapper(handle);    }    return undefined;}/** @internal */function emitAcknowledgeableEvent(emitter, ackEvent, ackEventPayload, wrapperFieldName, ackHandleWrapper, compositionFunctor) {    ackHandleWrapper = movePublishAcknowledgementHandleWrapper(ackHandleWrapper, compositionFunctor);    if (ackHandleWrapper) {        ackEventPayload[wrapperFieldName] = ackHandleWrapper;        emitter.emitWithCallback(ackEvent, () => {            if (ackHandleWrapper) {                let handle = ackHandleWrapper.acquireHandle();                if (handle) {                    // Even if corked, all listeners have had a chance to react to the event                    // and acquire the acknowledgement handle if they wanted to.  If no one did so, then we do it ourselves.                    handle.invokeAcknowledgement();                }            }        }, ackEventPayload);    }    else {        emitter.emit(ackEvent, ackEventPayload);    }}exports.emitAcknowledgeableEvent = emitAcknowledgeableEvent;/** @internal */function queueAcknowledgeableEvent(emitter, ackEvent, ackEventPayload, wrapperFieldName, ackHandleWrapper, compositionFunctor) {    let wrapper = movePublishAcknowledgementHandleWrapper(ackHandleWrapper, compositionFunctor);    queueMicrotask(() => {        if (wrapper) {            ackEventPayload[wrapperFieldName] = wrapper;            emitter.emitWithCallback(ackEvent, () => {                if (wrapper) {                    let handle = wrapper.acquireHandle();                    if (handle) {                        // Even if corked, all listeners have had a chance to react to the event                        // and acquire the acknowledgement handle if they wanted to.  If no one did so, then we do it ourselves.                        handle.invokeAcknowledgement();                    }                }            }, ackEventPayload);        }        else {            emitter.emit(ackEvent, ackEventPayload);        }    });}exports.queueAcknowledgeableEvent = queueAcknowledgeableEvent;/** * Object that allows the holder to trigger the acknowledgement for an associated publish packet. */class PublishAcknowledgementHandle {    constructor(acknowledgementFunction) {        this.acknowledgementFunction = acknowledgementFunction;    }    /**     * trigger the acknowledgement for an associated Publish packet     */    invokeAcknowledgement() {        let acknowledgementFunction = this.acknowledgementFunction;        this.acknowledgementFunction = undefined;        if (acknowledgementFunction) {            acknowledgementFunction();        }    }}exports.PublishAcknowledgementHandle = PublishAcknowledgementHandle;//# sourceMappingURL=mqtt_shared.js.map