import ICommand from './ICommand'; import IPostMessage from '../IPostMessage'; import ICommandDispatchToAppletMessage from './ICommandDispatchToAppletMessage'; import ICommandEvent from './ICommandEvent'; /** * In some cases, you might be interested in a complete log of what the device was doing during its operation. All of your business or technical logs can be stored in our storage for later usage. You can identify which events happened or even trigger self-repairing logic. * * All commands will be available in [Applet Command REST API](https://developers.signageos.io/api/#tag/DeviceApplet-Command) and can be downloaded historically as [CSV export](https://developers.signageos.io/api/#tag/DeviceMonitoring/paths/~1v1~1device~1%7BdeviceUid%7D~1report/get). */ export default class Command { private messagePrefix; private postMessage; static MESSAGE_PREFIX: string; private eventEmitter; /** @internal */ constructor(messagePrefix: string, postMessage: IPostMessage); /** * The `dispatch()` method dispatches a new log record to the signageOS. * * :::warning[Dispatch throttling] * Sending commands from an applet is throttled, this means that after if the dispatch frequency is too high, some commands may be * discarded. Currently, the limit is 30 commands per 30 seconds, although this may not be fully accurate, and it's not possible to know the * exact limit. * ::: * * @param command The command to be dispatched. * @throws {AppletCommandError} If type contains invalid characters, allowed to are `/^[a-zA-Z0-9\.\-_]+$/g` * @throws {AppletCommandError} If the command type is longer then 100 characters limit. * @throws {AppletCommandError} If the command is not an object or is missing required properties. * @since 1.0.3 * * @example // {@link https://github.com/signageos/applet-examples/blob/master/examples/content-js-api/command/sending/ | Sending commands in Applet} * @example // {@link https://developers.signageos.io/api/#tag/DeviceApplet-Command/paths/~1v1~1device~1%7BdeviceUid%7D~1applet~1%7BappletUid%7D~1command/post | Rest API - Dispatching commands} * @example // {@link https://developers.signageos.io/api/#tag/DeviceApplet-Command/paths/~1v1~1device~1%7BdeviceUid%7D~1applet~1command/get | Rest API - Get commands} * @example // {@link https://developers.signageos.io/api/#tag/DeviceMonitoring/paths/~1v1~1device~1%7BdeviceUid%7D~1report/get | Rest API - Receiving historical data} * * @example * await sos.command.dispatch({ * type: 'Files.StartLoading', * fileName: 'my-file', * fileType: 'txt' * }); */ dispatch(command: TCommand): Promise; /** * The `onCommand()` method sets up a listener, which is called whenever a new command from signageOS is received. * * @param listener The listener to be called when a new command is received. * @returns {void} Resolves when the listener is successfully set up. * @since 1.0.3 * * @example // {@link https://github.com/signageos/applet-examples/blob/master/examples/content-js-api/command/receiving | Receiving commands in Applet} */ onCommand(listener: (command: ICommandEvent) => void): void; /** @internal */ handleMessageData(data: ICommandDispatchToAppletMessage): void; private getMessage; private checkTypeValidity; }