import { App } from './App'; import { IObniz, IObnizOptions } from './Obniz.interface'; import { User } from 'obniz-cloud-sdk/sdk'; import { DeviceInfo } from './types/device'; import { Slave } from './Slave'; /** * This class is exported from this library * "Abstract" must be drop * Example: https://qiita.com/okdyy75/items/610623943979cf422775#%E3%81%BE%E3%81%82%E3%81%A8%E3%82%8A%E3%81%82%E3%81%88%E3%81%9A%E3%81%A9%E3%82%93%E3%81%AA%E6%84%9F%E3%81%98%E3%81%AB%E6%9B%B8%E3%81%8F%E3%81%AE */ export declare class Worker { /** * @deprecated Please use deviceInfo instead. */ install: DeviceInfo; deviceInfo: DeviceInfo; protected app: App; protected slave: Slave; protected obniz: O; state: 'stopped' | 'starting' | 'started' | 'stopping'; protected readonly _obnizOption: IObnizOptions; user?: User | null; private _cloudSdk; constructor(deviceInfo: DeviceInfo, app: App, slave: Slave, option?: IObnizOptions); /** * Worker lifecycle */ /** * Called When newaly Installed * This will be called before onStart after instantiated. * Introduces from v1.4.0 */ onInstall(): Promise; /** * Called When Uninstalled * This will be called before onEnd() * Introduces from v1.4.0 */ onUnInstall(): Promise; /** * Worker lifecycle */ onStart(): Promise; /** * This funcion will be called rrepeatedly while App is started. */ onLoop(): Promise; onEnd(): Promise; /** * * @param key string key that represents what types of reqeust. * @returns string for requested key */ onRequest(key: string): Promise; /** * obniz lifecycle */ onObnizConnect(obniz: O): Promise; onObnizLoop(obniz: O): Promise; onObnizClose(obniz: O): Promise; /** * Start Application by recofnizing Install/Update * @param onInstall if start reason is new install then true; */ start(onInstall?: boolean): Promise; private _loop; restart(): Promise; /** * Send a request to all other Workers in this App (across every Slave * instance) and collect their `onRequest` responses keyed by obnizId. * * This is the worker-to-worker counterpart of `App.request()`. * The requesting Worker's own Slave also handles the request, so the * returned object includes sibling Workers on the same instance. * * @param key string payload passed to `onRequest` on each Worker. * @param timeout time in milliseconds to wait for responses. Default 30s. * @returns `{ [obnizId]: response }` collected across Slaves. */ request(key: string, timeout?: number): Promise<{ [key: string]: string; }>; /** * Send a request directly to a single Worker identified by obnizId and * receive its `onRequest` response. Rejects with ObnizAppTimeoutError if * no Worker responds within `timeout`. * * @param obnizId target Worker's obniz id. * @param key string payload passed to `onRequest`. * @param timeout time in milliseconds to wait for a response. Default 30s. */ directRequest(obnizId: string, key: string, timeout?: number): Promise<{ [key: string]: string; }>; stop(): Promise; protected statusUpdateWait(status: 'success' | 'error', text: string): Promise; protected addLogQueue(level: 'info' | 'error', message: string): void; cloudLog: { info: (message: string) => void; error: (message: string) => void; }; } export type WorkerStatic = new (deviceInfo: DeviceInfo, app: App, slave: Slave, option: IObnizOptions) => Worker;