@telemetryos/root-sdk 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/client.d.ts +7 -1
- package/dist/devices.d.ts +16 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +320 -223
- package/dist/mqtt.d.ts +43 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @telemetryos/root-sdk
|
|
2
2
|
|
|
3
|
+
## 1.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added MQTT, publish command, and other improvements
|
|
8
|
+
- Added MQTT support to the SDK
|
|
9
|
+
- Added a command `tos publish` that sends the project to be built on the platform (requires user token, so wont work right away)
|
|
10
|
+
- Added mock data for the currency service
|
|
11
|
+
|
|
3
12
|
## 1.9.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { Devices } from './devices.js';
|
|
|
9
9
|
import { Weather } from './weather.js';
|
|
10
10
|
import { Currency } from './currency.js';
|
|
11
11
|
import { Environment } from './environment.js';
|
|
12
|
+
import { Mqtt } from './mqtt.js';
|
|
12
13
|
import { BridgeMessage } from './bridge.js';
|
|
13
14
|
/**
|
|
14
15
|
* The maximum time in milliseconds to wait for a response to a request call.
|
|
@@ -232,6 +233,7 @@ export declare class Client {
|
|
|
232
233
|
* @returns An Environment instance bound to this client
|
|
233
234
|
*/
|
|
234
235
|
get environment(): Environment;
|
|
236
|
+
get mqtt(): Mqtt;
|
|
235
237
|
get applicationName(): string;
|
|
236
238
|
get applicationSpecifier(): string;
|
|
237
239
|
get applicationInstance(): string;
|
|
@@ -293,10 +295,14 @@ export declare class Client {
|
|
|
293
295
|
* @template D The expected type of the response data
|
|
294
296
|
* @param name The name of the message type (endpoint) to request
|
|
295
297
|
* @param data The data payload to include with the request
|
|
298
|
+
* @param options Optional configuration for this request
|
|
299
|
+
* @param options.timeout Override the default timeout in milliseconds. Set to 0 to disable timeout.
|
|
296
300
|
* @returns A promise that resolves with the response data when received
|
|
297
301
|
* @throws {Error} If the request times out
|
|
298
302
|
*/
|
|
299
|
-
request<D>(name: string, data: any
|
|
303
|
+
request<D>(name: string, data: any, options?: {
|
|
304
|
+
timeout?: number;
|
|
305
|
+
}): Promise<D>;
|
|
300
306
|
/**
|
|
301
307
|
* Sets up a persistent subscription to messages from the TelemetryOS platform.
|
|
302
308
|
*
|
package/dist/devices.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ type DeviceInformation = {
|
|
|
5
5
|
deviceManufacturer: string;
|
|
6
6
|
devicePlatform: string;
|
|
7
7
|
};
|
|
8
|
+
export type DeviceCapability = 'configurableDisplays' | 'configurableAudio' | 'applicationContainers' | 'applicationManagement' | 'resourceCaching' | 'bluetooth' | 'wiFi' | 'ethernet' | 'usbProvisioning' | 'videoStreaming' | 'screenCaptureStreaming' | 'mqtt';
|
|
8
9
|
export declare class Devices {
|
|
9
10
|
_client: Client;
|
|
10
11
|
constructor(client: Client);
|
|
@@ -22,5 +23,20 @@ export declare class Devices {
|
|
|
22
23
|
* console.log(`Device: ${info.deviceManufacturer} ${info.deviceModel}`);
|
|
23
24
|
*/
|
|
24
25
|
getInformation(): Promise<DeviceInformation>;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the capabilities of the current device.
|
|
28
|
+
*
|
|
29
|
+
* Capabilities indicate what hardware and software features are available on
|
|
30
|
+
* the device running the application. This can be used to conditionally enable
|
|
31
|
+
* features based on what the device supports (e.g., MQTT, Bluetooth, WiFi).
|
|
32
|
+
*
|
|
33
|
+
* @returns A promise that resolves to an array of device capability strings
|
|
34
|
+
* @example
|
|
35
|
+
* const capabilities = await devices.getCapabilities();
|
|
36
|
+
* if (capabilities.includes('mqtt')) {
|
|
37
|
+
* // Enable MQTT features
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
getCapabilities(): Promise<DeviceCapability[]>;
|
|
25
41
|
}
|
|
26
42
|
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),D="1.9.0",U={version:D};class C{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("accounts.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current account");return e.account}}class P{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{mountPoint:e})).applications}async getByName(e){return(await this._client.request("applications.getByName",{name:e})).application}async setDependencies(e){return await this._client.request("applications.setDependencies",{applicationSpecifiers:e})}bind(e,t){if(this._client._messageInterceptors.has(e))throw new Error(`Interceptor already bound for message ${e}`);this._client._messageInterceptors.set(e,t)}}class M{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}}class T{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}async subscribeColorScheme(e){return(await this._client.subscribe("environment.subscribeColorScheme",{},e)).success}async unsubscribeColorScheme(e){return(await this._client.unsubscribe("environment.unsubscribeColorScheme",{},e)).success}}class A{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}}class B{constructor(e){this._client=e}async fetch(e,t){var s;let o;typeof e=="string"?o=e:e instanceof URL?o=e.toString():(o=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let n={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((u,h)=>{n[h]=u}):Array.isArray(t.headers)?t.headers.forEach(([u,h])=>{n[u]=h}):n=t.headers);const i=await this._client.request("proxy.fetch",{url:o,method:(t==null?void 0:t.method)||"GET",headers:n,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!i.success)throw new TypeError(i.errorMessage,{cause:i.errorCause?Error(i.errorCause):void 0});const l=new Headers(i.headers),c={status:i.status,statusText:i.statusText,headers:l};let d=null;if(i.body!==null&&i.body!==void 0)if(i.bodyType==="binary"){const u=atob(i.body),h=new Uint8Array(u.length);for(let f=0;f<u.length;f++)h[f]=u.charCodeAt(f);d=h}else i.bodyType==="text"?d=i.body:i.bodyType==="json"&&(d=JSON.stringify(i.body));return new Response(d,c)}}class F{constructor(e){this._client=e}get application(){return new w("application","",this._client)}get instance(){return new w("instance",this._client.applicationInstance,this._client)}get device(){return new w("device",this._client.applicationInstance,this._client)}shared(e){return new w("shared",e,this._client)}}class w{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class k{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class ${constructor(e){this._client=e}async getCities(e){const t=await this._client.request("weather.getCities",e);if(!t.success)throw new Error(t.error||"Failed to fetch cities");return t.data||[]}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather conditions");return t}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch daily forecast");return t}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch hourly forecast");return t}async getAlerts(e){const t=await this._client.request("weather.getAlerts",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather alerts");return t}}class R{constructor(e){this._client=e}async getSymbols(){const e=await this._client.request("currency.getSymbols",{});if(!e.success||!e.symbols)throw new Error("Failed to fetch currency symbols");return e.symbols}async getRates(e){var t,s,o;const n=await this._client.request("currency.getRates",e);if(!n.success||!n.rates)throw((t=n.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=n.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((o=n.error)===null||o===void 0?void 0:o.message)||"Failed to fetch currency rates");return n.rates}}function I(a){return{...a,type:"client"}}const L=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.anyType()});class V{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){var t;const s=this._store.shared("root-settings-navigation"),o=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;o[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",o)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},o=this._store._client._applicationSpecifier;return s[o]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const _=1e3*30,H=typeof window>"u"&&typeof self<"u",b=H?self:window;function y(a){H?self.postMessage(a):b.parent.postMessage(a,"*")}class x{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new C(this)}get users(){return new k(this)}get store(){return new F(this)}get applications(){return new P(this)}get media(){return new A(this)}get proxy(){return new B(this)}get devices(){return new M(this)}get rootSettingsNavigation(){return new V(this.store)}get weather(){return new $(this)}get currency(){return new R(this)}get environment(){return new T(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e,t,s;const o=new URL(b.location.href),n=o.searchParams;if(this._applicationInstance=(e=n.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=n.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const i=o.hostname.split(".");this._applicationSpecifier=(s=i[0])!==null&&s!==void 0?s:""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=i=>{if(i.source===b||!i.data||typeof i.data!="object"||!("type"in i.data)||i.data.type!=="client"&&i.data.type!=="bridge")return;let l;if(i.data.type==="client"){const c=this._messageInterceptors.get(i.data.name);if(!c){y(i.data);return}l={...c(i.data.data),type:"bridge"}}if(!l){const c=L.safeParse(i.data);if(!c.success)return;l=c.data;const d=this._onHandlers.get(l.name),u=this._onceHandlers.get(l.name);if(d)for(const h of d)h(l.data);if(u){for(const h of u)h(l.data);this._onceHandlers.delete(l.name)}}if(!H)for(let c=0;c<window.frames.length;c+=1)window.frames[c].postMessage(l,"*")},b.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&b.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});y(s)}request(e,t){const s=q(),o=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:s});y(o);let n=!1,i;const l=new Promise((d,u)=>{const h=new Error(`${e} message request with response name of ${s} timed out after ${_}`);setTimeout(()=>{n=!0,this.off(s,i),u(h)},_)}),c=new Promise(d=>{i=u=>{n||d(u)},this.once(s,d)});return Promise.race([l,c])}async subscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const i=q(),l=q();let c=this._subscriptionNamesBySubjectName.get(e);c||(c=[],this._subscriptionNamesBySubjectName.set(e,c)),c.push(i),this._subscriptionNamesByHandler.set(n,i),this.on(i,n);const d=I({telemetrySdkVersion:v,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:o,responseName:l,subscriptionName:i});y(d);let u=!1,h;const f=new Promise((S,g)=>{const m=new Error(`${e} subscribe request with subscription name of ${i} and response name of ${l} timed out after ${_}`);setTimeout(()=>{u=!0,this.off(l,h),g(m)},_)}),E=new Promise(S=>{h=g=>{u||S(g)},this.on(l,S)});return Promise.race([f,E])}async unsubscribe(e,t,s){let o,n;typeof t=="function"?n=t:(o=t,n=s);const i=q();let l=[];if(n){const c=this._subscriptionNamesByHandler.get(n);if(!c)return{success:!1};l=[c],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const c of l){this.off(c,n);const d=I({telemetrySdkVersion:v,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:o,responseName:i,unsubscribeName:c});y(d);let u=!1,h;const f=new Promise((g,m)=>{const j=new Error(`${e} unsubscribe request with unsubscribe name of ${c} and response name of ${i} timed out after ${_}`);setTimeout(()=>{u=!0,this.off(i,h),m(j)},_)}),E=new Promise(g=>{h=m=>{u||g(m)},this.once(i,g)});if(!(await Promise.race([f,E])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const o=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onHandlers.set(e,o),o.push(t)}once(e,t){var s;const o=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];o.length===0&&this._onceHandlers.set(e,o),o.push(t)}off(e,t){const s=this._onHandlers.get(e),o=this._onceHandlers.get(e);if(!(!s&&!o)){if(s){for(let n=0;n<s.length;n+=1)t&&s[n]!==t||(s.splice(n,1),n-=1);s.length===0&&this._onHandlers.delete(e)}if(o){for(let n=0;n<o.length;n+=1)t&&o[n]!==t||(o.splice(n,1),n-=1);o.length===0&&this._onceHandlers.delete(e)}}}}function q(){return Math.random().toString(36).slice(2,9)}const v=U.version;let r=null;function W(){return r}function O(a){r=new x(a),r.bind()}function G(){r==null||r.unbind(),r=null}function J(...a){return p(r),r.on(...a)}function K(...a){return p(r),r.once(...a)}function z(...a){return p(r),r.off(...a)}function Q(...a){return p(r),r.send(...a)}function X(...a){return p(r),r.request(...a)}function Y(...a){return p(r),r.subscribe(...a)}function Z(...a){return p(r),r.unsubscribe(...a)}function ee(){return p(r),r.store}function te(){return p(r),r.applications}function se(){return p(r),r.media}function ne(){return p(r),r.accounts}function ie(){return p(r),r.users}function re(){return p(r),r.devices}function oe(){return p(r),r.proxy}function ae(){return p(r),r.rootSettingsNavigation}function ce(){return p(r),r.weather}function le(){return p(r),r.currency}function ue(){return p(r),r.environment}function p(a){if(!a)throw new Error("SDK is not configured")}exports.Accounts=C;exports.Applications=P;exports.Client=x;exports.Currency=R;exports.Devices=M;exports.Environment=T;exports.Media=A;exports.Proxy=B;exports.Store=F;exports.StoreSlice=w;exports.Users=k;exports.Weather=$;exports.accounts=ne;exports.applications=te;exports.configure=O;exports.currency=le;exports.destroy=G;exports.devices=re;exports.environment=ue;exports.globalClient=W;exports.media=se;exports.off=z;exports.on=J;exports.once=K;exports.proxy=oe;exports.request=X;exports.rootSettingsNavigation=ae;exports.send=Q;exports.store=ee;exports.subscribe=Y;exports.telemetrySdkVersion=v;exports.unsubscribe=Z;exports.users=ie;exports.weather=ce;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./types-mYnxD5LM.cjs"),Q="1.10.0",U={version:Q};class T{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("accounts.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current account");return e.account}}class M{constructor(e){this._client=e}async getAllByMountPoint(e){return(await this._client.request("applications.getAllByMountPoint",{mountPoint:e})).applications}async getByName(e){return(await this._client.request("applications.getByName",{name:e})).application}async setDependencies(e){return await this._client.request("applications.setDependencies",{applicationSpecifiers:e},{timeout:0})}bind(e,t){if(this._client._messageInterceptors.has(e))throw new Error(`Interceptor already bound for message ${e}`);this._client._messageInterceptors.set(e,t)}}class H{constructor(e){this._client=e}async getInformation(){const e=await this._client.request("devices.getInformation",{});if(!e.success)throw new Error("Failed to get device information");return e.deviceInformation}async getCapabilities(){const e=await this._client.request("devices.getCapabilities",{});if(!e.success)throw new Error("Failed to get device capabilities");return e.capabilities}}class P{constructor(e){this._client=e}async getColorScheme(){return(await this._client.request("environment.getColorScheme",{})).colorScheme}async subscribeColorScheme(e){return(await this._client.subscribe("environment.subscribeColorScheme",{},e)).success}async unsubscribeColorScheme(e){return(await this._client.unsubscribe("environment.unsubscribeColorScheme",{},e)).success}}class F{constructor(e){this._client=e}async getAllFolders(){return(await this._client.request("mediaFolders.getAll",{})).folders}async getAllByFolderId(e){return(await this._client.request("media.getAllByFolderId",{folderId:e})).contents}async getAllByTag(e){return(await this._client.request("media.getAllByTag",{tagName:e})).contents}async getById(e){return(await this._client.request("media.getById",{id:e})).content}}class A{constructor(e){this._client=e}async fetch(e,t){var s;let i;typeof e=="string"?i=e:e instanceof URL?i=e.toString():(i=e.url,t||(t={method:e.method,headers:e.headers,body:e.body,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,integrity:e.integrity}));let n={};t!=null&&t.headers&&(t.headers instanceof Headers?t.headers.forEach((l,p)=>{n[p]=l}):Array.isArray(t.headers)?t.headers.forEach(([l,p])=>{n[l]=p}):n=t.headers);const o=await this._client.request("proxy.fetch",{url:i,method:(t==null?void 0:t.method)||"GET",headers:n,body:(s=t==null?void 0:t.body)!==null&&s!==void 0?s:null});if(!o.success)throw new TypeError(o.errorMessage,{cause:o.errorCause?Error(o.errorCause):void 0});const u=new Headers(o.headers),a={status:o.status,statusText:o.statusText,headers:u};let d=null;if(o.body!==null&&o.body!==void 0)if(o.bodyType==="binary"){const l=atob(o.body),p=new Uint8Array(l.length);for(let f=0;f<l.length;f++)p[f]=l.charCodeAt(f);d=p}else o.bodyType==="text"?d=o.body:o.bodyType==="json"&&(d=JSON.stringify(o.body));return new Response(d,a)}}class k{constructor(e){this._client=e}get application(){return new v("application","",this._client)}get instance(){return new v("instance",this._client.applicationInstance,this._client)}get device(){return new v("device",this._client.applicationInstance,this._client)}shared(e){return new v("shared",e,this._client)}}class v{constructor(e,t,s){this._kind=e,this._namespace=t,this._client=s}async set(e,t){return(await this._client.request("store.set",{kind:this._kind,namespace:this._namespace,key:e,value:t})).success}async get(e){return(await this._client.request("store.get",{kind:this._kind,namespace:this._namespace,key:e})).value}async subscribe(e,t){return(await this._client.subscribe("store.subscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async unsubscribe(e,t){return(await this._client.unsubscribe("store.unsubscribe",{kind:this._kind,namespace:this._namespace,key:e},t)).success}async delete(e){return(await this._client.request("store.delete",{kind:this._kind,namespace:this._namespace,key:e})).success}}class B{constructor(e){this._client=e}async getCurrent(){const e=await this._client.request("users.getCurrent",{});if(!e.success)throw new Error("Failed to fetch current user");return e.user}}class ${constructor(e){this._client=e}async getCities(e){const t=await this._client.request("weather.getCities",e);if(!t.success)throw new Error(t.error||"Failed to fetch cities");return t.data||[]}async getConditions(e){const t=await this._client.request("weather.getConditions",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather conditions");return t}async getDailyForecast(e){const t=await this._client.request("weather.getDailyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch daily forecast");return t}async getHourlyForecast(e){const t=await this._client.request("weather.getHourlyForecast",e);if(!t.success)throw new Error(t.error||"Failed to fetch hourly forecast");return t}async getAlerts(e){const t=await this._client.request("weather.getAlerts",e);if(!t.success)throw new Error(t.error||"Failed to fetch weather alerts");return t}}class R{constructor(e){this._client=e}async getSymbols(){const e=await this._client.request("currency.getSymbols",{});if(!e.success||!e.symbols)throw new Error("Failed to fetch currency symbols");return e.symbols}async getRates(e){var t,s,i;const n=await this._client.request("currency.getRates",e);if(!n.success||!n.rates)throw((t=n.error)===null||t===void 0?void 0:t.code)===201?new Error(`Invalid base currency '${e.base}'`):((s=n.error)===null||s===void 0?void 0:s.code)===202?new Error(`Invalid target currency symbol '${e.symbols}'`):new Error(((i=n.error)===null||i===void 0?void 0:i.message)||"Failed to fetch currency rates");return n.rates}}class x{constructor(e){this._client=e}async discover(){const e=await this._client.request("mqtt.discover",{});if(!e.success)throw new Error("Failed to discover MQTT brokers");return e.brokers}async connect(e,t){const s=await this._client.request("mqtt.connect",{brokerUrl:e,...t});if(!s.success)throw new Error("Failed to connect to MQTT broker");return s.clientId}async disconnect(e){if(!(await this._client.request("mqtt.disconnect",{clientId:e})).success)throw new Error("Failed to disconnect from MQTT broker")}async publish(e,t,s,i){if(!(await this._client.request("mqtt.publish",{clientId:e,topic:t,payload:s,...i})).success)throw new Error("Failed to publish MQTT message")}async subscribe(e,t,s,i){return(await this._client.subscribe("mqtt.subscribe",{clientId:e,topic:t,...i},s)).success}async unsubscribe(e,t,s){return(await this._client.unsubscribe("mqtt.unsubscribe",{clientId:e,topic:t},s)).success}async getConnectionStatus(e){const t=await this._client.request("mqtt.getConnectionStatus",{clientId:e});if(!t.success)throw new Error("Failed to get MQTT connection status");return t.status}async subscribeConnectionStatus(e,t){return(await this._client.subscribe("mqtt.subscribeConnectionStatus",{clientId:e},t)).success}async unsubscribeConnectionStatus(e,t){return(await this._client.unsubscribe("mqtt.unsubscribeConnectionStatus",{clientId:e},t)).success}}function E(c){return{...c,type:"client"}}const L=N.objectType({type:N.literalType("bridge"),name:N.stringType(),data:N.anyType()});class V{constructor(e){if(e._client._applicationSpecifier!=="rootSettingsNavigation")throw new Error("RootSettingsNavigation can only be used in the rootSettingsNavigation mount point");this._store=e}async setRootSettingsNavigation(e){var t;const s=this._store.shared("root-settings-navigation"),i=(t=await s.get("navigation"))!==null&&t!==void 0?t:{},n=this._store._client._applicationSpecifier;i[n]={applicationSpecifier:n,entries:e.entries},s.set("navigation",i)}async getRootSettingsNavigation(){var e;const s=(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{},i=this._store._client._applicationSpecifier;return s[i]}async getAllRootSettingsNavigation(){var e;return(e=await this._store.shared("root-settings-navigation").get("navigation"))!==null&&e!==void 0?e:{}}}const b=1e3*30,C=typeof window>"u"&&typeof self<"u",S=C?self:window;function y(c){C?self.postMessage(c):S.parent.postMessage(c,"*")}class j{constructor(e){this._applicationName=e,this._applicationInstance="",this._applicationSpecifier="",this._messageInterceptors=new Map,this._onHandlers=new Map,this._onceHandlers=new Map,this._subscriptionNamesByHandler=new Map,this._subscriptionNamesBySubjectName=new Map}get accounts(){return new T(this)}get users(){return new B(this)}get store(){return new k(this)}get applications(){return new M(this)}get media(){return new F(this)}get proxy(){return new A(this)}get devices(){return new H(this)}get rootSettingsNavigation(){return new V(this.store)}get weather(){return new $(this)}get currency(){return new R(this)}get environment(){return new P(this)}get mqtt(){return new x(this)}get applicationName(){return this._applicationName}get applicationSpecifier(){return this._applicationSpecifier}get applicationInstance(){return this._applicationInstance}bind(){var e,t,s;const i=new URL(S.location.href),n=i.searchParams;if(this._applicationInstance=(e=n.get("applicationInstance"))!==null&&e!==void 0?e:"",!this._applicationInstance)throw new Error("Missing applicationInstance query parameter");if(this._applicationSpecifier=(t=n.get("applicationSpecifier"))!==null&&t!==void 0?t:"",!this._applicationSpecifier){const o=i.hostname.split(".");this._applicationSpecifier=(s=o[0])!==null&&s!==void 0?s:""}if(!this._applicationSpecifier||this._applicationSpecifier.length!==40)throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);this._windowMessageHandler=o=>{if(o.source===S||!o.data||typeof o.data!="object"||!("type"in o.data)||o.data.type!=="client"&&o.data.type!=="bridge")return;let u;if(o.data.type==="client"){const a=this._messageInterceptors.get(o.data.name);if(!a){y(o.data);return}u={...a(o.data.data),type:"bridge"}}if(!u){const a=L.safeParse(o.data);if(!a.success)return;u=a.data;const d=this._onHandlers.get(u.name),l=this._onceHandlers.get(u.name);if(d)for(const p of d)p(u.data);if(l){for(const p of l)p(u.data);this._onceHandlers.delete(u.name)}}if(!C)for(let a=0;a<window.frames.length;a+=1)window.frames[a].postMessage(u,"*")},S.addEventListener("message",this._windowMessageHandler)}unbind(){this._windowMessageHandler&&S.removeEventListener("message",this._windowMessageHandler)}send(e,t){const s=E({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t});y(s)}request(e,t,s){var i;const n=I(),o=E({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:t,responseName:n});y(o);const u=(i=s==null?void 0:s.timeout)!==null&&i!==void 0?i:b;let a=!1,d;const l=new Promise(f=>{d=g=>{a||f(g)},this.once(n,d)});if(u===0)return l;const p=new Promise((f,g)=>{const w=new Error(`${e} message request with response name of ${n} timed out after ${u}`);setTimeout(()=>{a=!0,this.off(n,d),g(w)},u)});return Promise.race([p,l])}async subscribe(e,t,s){let i,n;typeof t=="function"?n=t:(i=t,n=s);const o=I(),u=I();let a=this._subscriptionNamesBySubjectName.get(e);a||(a=[],this._subscriptionNamesBySubjectName.set(e,a)),a.push(o),this._subscriptionNamesByHandler.set(n,o),this.on(o,n);const d=E({telemetrySdkVersion:q,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,applicationInstance:this._applicationInstance,name:e,data:i,responseName:u,subscriptionName:o});y(d);let l=!1,p;const f=new Promise((w,m)=>{const _=new Error(`${e} subscribe request with subscription name of ${o} and response name of ${u} timed out after ${b}`);setTimeout(()=>{l=!0,this.off(u,p),m(_)},b)}),g=new Promise(w=>{p=m=>{l||w(m)},this.on(u,w)});return Promise.race([f,g])}async unsubscribe(e,t,s){let i,n;typeof t=="function"?n=t:(i=t,n=s);const o=I();let u=[];if(n){const a=this._subscriptionNamesByHandler.get(n);if(!a)return{success:!1};u=[a],this._subscriptionNamesByHandler.delete(n)}else if(!this._subscriptionNamesBySubjectName.get(e))return{success:!1};for await(const a of u){this.off(a,n);const d=E({telemetrySdkVersion:q,applicationInstance:this._applicationInstance,applicationName:this._applicationName,applicationSpecifier:this._applicationSpecifier,name:e,data:i,responseName:o,unsubscribeName:a});y(d);let l=!1,p;const f=new Promise((m,_)=>{const D=new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${o} timed out after ${b}`);setTimeout(()=>{l=!0,this.off(o,p),_(D)},b)}),g=new Promise(m=>{p=_=>{l||m(_)},this.once(o,m)});if(!(await Promise.race([f,g])).success)return{success:!1}}return{success:!0}}on(e,t){var s;const i=(s=this._onHandlers.get(e))!==null&&s!==void 0?s:[];i.length===0&&this._onHandlers.set(e,i),i.push(t)}once(e,t){var s;const i=(s=this._onceHandlers.get(e))!==null&&s!==void 0?s:[];i.length===0&&this._onceHandlers.set(e,i),i.push(t)}off(e,t){const s=this._onHandlers.get(e),i=this._onceHandlers.get(e);if(!(!s&&!i)){if(s){for(let n=0;n<s.length;n+=1)t&&s[n]!==t||(s.splice(n,1),n-=1);s.length===0&&this._onHandlers.delete(e)}if(i){for(let n=0;n<i.length;n+=1)t&&i[n]!==t||(i.splice(n,1),n-=1);i.length===0&&this._onceHandlers.delete(e)}}}}function I(){return Math.random().toString(36).slice(2,9)}const q=U.version;let r=null;function W(){return r}function O(c){r=new j(c),r.bind()}function G(){r==null||r.unbind(),r=null}function J(...c){return h(r),r.on(...c)}function K(...c){return h(r),r.once(...c)}function z(...c){return h(r),r.off(...c)}function X(...c){return h(r),r.send(...c)}function Y(...c){return h(r),r.request(...c)}function Z(...c){return h(r),r.subscribe(...c)}function ee(...c){return h(r),r.unsubscribe(...c)}function te(){return h(r),r.store}function se(){return h(r),r.applications}function ne(){return h(r),r.media}function ie(){return h(r),r.accounts}function re(){return h(r),r.users}function oe(){return h(r),r.devices}function ce(){return h(r),r.proxy}function ae(){return h(r),r.rootSettingsNavigation}function ue(){return h(r),r.weather}function le(){return h(r),r.currency}function he(){return h(r),r.environment}function pe(){return h(r),r.mqtt}function h(c){if(!c)throw new Error("SDK is not configured")}exports.Accounts=T;exports.Applications=M;exports.Client=j;exports.Currency=R;exports.Devices=H;exports.Environment=P;exports.Media=F;exports.Mqtt=x;exports.Proxy=A;exports.Store=k;exports.StoreSlice=v;exports.Users=B;exports.Weather=$;exports.accounts=ie;exports.applications=se;exports.configure=O;exports.currency=le;exports.destroy=G;exports.devices=oe;exports.environment=he;exports.globalClient=W;exports.media=ne;exports.mqtt=pe;exports.off=z;exports.on=J;exports.once=K;exports.proxy=ce;exports.request=Y;exports.rootSettingsNavigation=ae;exports.send=X;exports.store=te;exports.subscribe=Z;exports.telemetrySdkVersion=q;exports.unsubscribe=ee;exports.users=re;exports.weather=ue;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Accounts } from './accounts.js';
|
|
2
2
|
export { Applications } from './applications.js';
|
|
3
|
-
export { Devices } from './devices.js';
|
|
3
|
+
export { Devices, type DeviceCapability } from './devices.js';
|
|
4
4
|
export { Environment, type ColorScheme } from './environment.js';
|
|
5
5
|
export { Media } from './media.js';
|
|
6
6
|
export { Proxy } from './proxy.js';
|
|
@@ -10,6 +10,8 @@ export { Weather } from './weather.js';
|
|
|
10
10
|
export type { CitiesSearchParams, DailyForecast, DailyForecastData, DailyForecastParams, HourlyForecast, HourlyForecastData, HourlyForecastParams, WeatherAlert, WeatherAlerts, WeatherAlertSeverity, WeatherAlertsParams, WeatherCity, WeatherConditions, WeatherConditionsParams, WeatherPartOfDay, } from './weather.js';
|
|
11
11
|
export { Currency } from './currency.js';
|
|
12
12
|
export type { CurrencySymbols, CurrencyRates, CurrencyRatesParams } from './currency.js';
|
|
13
|
+
export { Mqtt } from './mqtt.js';
|
|
14
|
+
export type { MqttBrokerInfo, MqttConnectOptions, MqttPublishOptions, MqttSubscribeOptions, MqttConnectionStatus, MqttMessage, } from './mqtt.js';
|
|
13
15
|
import { Client } from './client.js';
|
|
14
16
|
export { Client, type SubscriptionResult, type MessageHandler } from './client.js';
|
|
15
17
|
/**
|
|
@@ -303,3 +305,14 @@ export declare function currency(): import("./currency.js").Currency;
|
|
|
303
305
|
* });
|
|
304
306
|
*/
|
|
305
307
|
export declare function environment(): import("./environment.js").Environment;
|
|
308
|
+
/**
|
|
309
|
+
* Provides access to the MQTT API for connecting to MQTT brokers.
|
|
310
|
+
*
|
|
311
|
+
* This API allows applications to discover, connect to, publish/subscribe on,
|
|
312
|
+
* and disconnect from MQTT brokers. MQTT is only available on dedicated player
|
|
313
|
+
* devices.
|
|
314
|
+
*
|
|
315
|
+
* @returns The Mqtt API object
|
|
316
|
+
* @throws {Error} If called before configure() or after destroy()
|
|
317
|
+
*/
|
|
318
|
+
export declare function mqtt(): import("./mqtt.js").Mqtt;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { o as
|
|
2
|
-
const
|
|
3
|
-
version:
|
|
1
|
+
import { o as C, a as H, s as M, l as F } from "./types-CCzf8sMT.js";
|
|
2
|
+
const P = "1.10.0", A = {
|
|
3
|
+
version: P
|
|
4
4
|
};
|
|
5
|
-
class
|
|
5
|
+
class k {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
this._client = e;
|
|
8
8
|
}
|
|
@@ -21,7 +21,7 @@ class F {
|
|
|
21
21
|
return e.account;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
class
|
|
24
|
+
class B {
|
|
25
25
|
constructor(e) {
|
|
26
26
|
this._client = e;
|
|
27
27
|
}
|
|
@@ -78,9 +78,7 @@ class $ {
|
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
80
|
async setDependencies(e) {
|
|
81
|
-
return await this._client.request("applications.setDependencies", {
|
|
82
|
-
applicationSpecifiers: e
|
|
83
|
-
});
|
|
81
|
+
return await this._client.request("applications.setDependencies", { applicationSpecifiers: e }, { timeout: 0 });
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
86
84
|
* Registers a message interceptor for client messages from sub-applications.
|
|
@@ -118,7 +116,7 @@ class $ {
|
|
|
118
116
|
this._client._messageInterceptors.set(e, t);
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
|
-
class
|
|
119
|
+
class $ {
|
|
122
120
|
constructor(e) {
|
|
123
121
|
this._client = e;
|
|
124
122
|
}
|
|
@@ -141,6 +139,26 @@ class k {
|
|
|
141
139
|
throw new Error("Failed to get device information");
|
|
142
140
|
return e.deviceInformation;
|
|
143
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves the capabilities of the current device.
|
|
144
|
+
*
|
|
145
|
+
* Capabilities indicate what hardware and software features are available on
|
|
146
|
+
* the device running the application. This can be used to conditionally enable
|
|
147
|
+
* features based on what the device supports (e.g., MQTT, Bluetooth, WiFi).
|
|
148
|
+
*
|
|
149
|
+
* @returns A promise that resolves to an array of device capability strings
|
|
150
|
+
* @example
|
|
151
|
+
* const capabilities = await devices.getCapabilities();
|
|
152
|
+
* if (capabilities.includes('mqtt')) {
|
|
153
|
+
* // Enable MQTT features
|
|
154
|
+
* }
|
|
155
|
+
*/
|
|
156
|
+
async getCapabilities() {
|
|
157
|
+
const e = await this._client.request("devices.getCapabilities", {});
|
|
158
|
+
if (!e.success)
|
|
159
|
+
throw new Error("Failed to get device capabilities");
|
|
160
|
+
return e.capabilities;
|
|
161
|
+
}
|
|
144
162
|
}
|
|
145
163
|
class R {
|
|
146
164
|
constructor(e) {
|
|
@@ -208,8 +226,8 @@ class j {
|
|
|
208
226
|
}
|
|
209
227
|
async fetch(e, t) {
|
|
210
228
|
var s;
|
|
211
|
-
let
|
|
212
|
-
typeof e == "string" ?
|
|
229
|
+
let i;
|
|
230
|
+
typeof e == "string" ? i = e : e instanceof URL ? i = e.toString() : (i = e.url, t || (t = {
|
|
213
231
|
method: e.method,
|
|
214
232
|
headers: e.headers,
|
|
215
233
|
body: e.body,
|
|
@@ -220,35 +238,35 @@ class j {
|
|
|
220
238
|
integrity: e.integrity
|
|
221
239
|
}));
|
|
222
240
|
let n = {};
|
|
223
|
-
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((
|
|
224
|
-
n[
|
|
225
|
-
}) : Array.isArray(t.headers) ? t.headers.forEach(([
|
|
226
|
-
n[
|
|
241
|
+
t != null && t.headers && (t.headers instanceof Headers ? t.headers.forEach((l, p) => {
|
|
242
|
+
n[p] = l;
|
|
243
|
+
}) : Array.isArray(t.headers) ? t.headers.forEach(([l, p]) => {
|
|
244
|
+
n[l] = p;
|
|
227
245
|
}) : n = t.headers);
|
|
228
|
-
const
|
|
229
|
-
url:
|
|
246
|
+
const o = await this._client.request("proxy.fetch", {
|
|
247
|
+
url: i,
|
|
230
248
|
method: (t == null ? void 0 : t.method) || "GET",
|
|
231
249
|
headers: n,
|
|
232
250
|
body: (s = t == null ? void 0 : t.body) !== null && s !== void 0 ? s : null
|
|
233
251
|
});
|
|
234
|
-
if (!
|
|
235
|
-
throw new TypeError(
|
|
236
|
-
cause:
|
|
252
|
+
if (!o.success)
|
|
253
|
+
throw new TypeError(o.errorMessage, {
|
|
254
|
+
cause: o.errorCause ? Error(o.errorCause) : void 0
|
|
237
255
|
});
|
|
238
|
-
const
|
|
239
|
-
status:
|
|
240
|
-
statusText:
|
|
241
|
-
headers:
|
|
256
|
+
const u = new Headers(o.headers), a = {
|
|
257
|
+
status: o.status,
|
|
258
|
+
statusText: o.statusText,
|
|
259
|
+
headers: u
|
|
242
260
|
};
|
|
243
261
|
let d = null;
|
|
244
|
-
if (
|
|
245
|
-
if (
|
|
246
|
-
const
|
|
247
|
-
for (let f = 0; f <
|
|
248
|
-
|
|
249
|
-
d =
|
|
250
|
-
} else
|
|
251
|
-
return new Response(d,
|
|
262
|
+
if (o.body !== null && o.body !== void 0)
|
|
263
|
+
if (o.bodyType === "binary") {
|
|
264
|
+
const l = atob(o.body), p = new Uint8Array(l.length);
|
|
265
|
+
for (let f = 0; f < l.length; f++)
|
|
266
|
+
p[f] = l.charCodeAt(f);
|
|
267
|
+
d = p;
|
|
268
|
+
} else o.bodyType === "text" ? d = o.body : o.bodyType === "json" && (d = JSON.stringify(o.body));
|
|
269
|
+
return new Response(d, a);
|
|
252
270
|
}
|
|
253
271
|
}
|
|
254
272
|
class D {
|
|
@@ -265,7 +283,7 @@ class D {
|
|
|
265
283
|
* @returns A StoreSlice instance for the application scope
|
|
266
284
|
*/
|
|
267
285
|
get application() {
|
|
268
|
-
return new
|
|
286
|
+
return new S("application", "", this._client);
|
|
269
287
|
}
|
|
270
288
|
/**
|
|
271
289
|
* Provides access to the instance store scope.
|
|
@@ -279,7 +297,7 @@ class D {
|
|
|
279
297
|
* @returns A StoreSlice instance for the instance scope
|
|
280
298
|
*/
|
|
281
299
|
get instance() {
|
|
282
|
-
return new
|
|
300
|
+
return new S("instance", this._client.applicationInstance, this._client);
|
|
283
301
|
}
|
|
284
302
|
/**
|
|
285
303
|
* Provides access to the device store scope.
|
|
@@ -294,7 +312,7 @@ class D {
|
|
|
294
312
|
* @returns A StoreSlice instance for the device scope
|
|
295
313
|
*/
|
|
296
314
|
get device() {
|
|
297
|
-
return new
|
|
315
|
+
return new S("device", this._client.applicationInstance, this._client);
|
|
298
316
|
}
|
|
299
317
|
/**
|
|
300
318
|
* Provides access to the shared store scope with a specified namespace.
|
|
@@ -310,10 +328,10 @@ class D {
|
|
|
310
328
|
* @returns A StoreSlice instance for the specified shared namespace
|
|
311
329
|
*/
|
|
312
330
|
shared(e) {
|
|
313
|
-
return new
|
|
331
|
+
return new S("shared", e, this._client);
|
|
314
332
|
}
|
|
315
333
|
}
|
|
316
|
-
class
|
|
334
|
+
class S {
|
|
317
335
|
constructor(e, t, s) {
|
|
318
336
|
this._kind = e, this._namespace = t, this._client = s;
|
|
319
337
|
}
|
|
@@ -407,7 +425,7 @@ class v {
|
|
|
407
425
|
})).success;
|
|
408
426
|
}
|
|
409
427
|
}
|
|
410
|
-
class
|
|
428
|
+
class Q {
|
|
411
429
|
constructor(e) {
|
|
412
430
|
this._client = e;
|
|
413
431
|
}
|
|
@@ -430,7 +448,7 @@ class L {
|
|
|
430
448
|
return e.user;
|
|
431
449
|
}
|
|
432
450
|
}
|
|
433
|
-
class
|
|
451
|
+
class L {
|
|
434
452
|
constructor(e) {
|
|
435
453
|
this._client = e;
|
|
436
454
|
}
|
|
@@ -573,7 +591,7 @@ class U {
|
|
|
573
591
|
return t;
|
|
574
592
|
}
|
|
575
593
|
}
|
|
576
|
-
class
|
|
594
|
+
class U {
|
|
577
595
|
constructor(e) {
|
|
578
596
|
this._client = e;
|
|
579
597
|
}
|
|
@@ -613,20 +631,84 @@ class V {
|
|
|
613
631
|
* ```
|
|
614
632
|
*/
|
|
615
633
|
async getRates(e) {
|
|
616
|
-
var t, s,
|
|
634
|
+
var t, s, i;
|
|
617
635
|
const n = await this._client.request("currency.getRates", e);
|
|
618
636
|
if (!n.success || !n.rates)
|
|
619
|
-
throw ((t = n.error) === null || t === void 0 ? void 0 : t.code) === 201 ? new Error(`Invalid base currency '${e.base}'`) : ((s = n.error) === null || s === void 0 ? void 0 : s.code) === 202 ? new Error(`Invalid target currency symbol '${e.symbols}'`) : new Error(((
|
|
637
|
+
throw ((t = n.error) === null || t === void 0 ? void 0 : t.code) === 201 ? new Error(`Invalid base currency '${e.base}'`) : ((s = n.error) === null || s === void 0 ? void 0 : s.code) === 202 ? new Error(`Invalid target currency symbol '${e.symbols}'`) : new Error(((i = n.error) === null || i === void 0 ? void 0 : i.message) || "Failed to fetch currency rates");
|
|
620
638
|
return n.rates;
|
|
621
639
|
}
|
|
622
640
|
}
|
|
623
|
-
|
|
624
|
-
|
|
641
|
+
class V {
|
|
642
|
+
constructor(e) {
|
|
643
|
+
this._client = e;
|
|
644
|
+
}
|
|
645
|
+
async discover() {
|
|
646
|
+
const e = await this._client.request("mqtt.discover", {});
|
|
647
|
+
if (!e.success)
|
|
648
|
+
throw new Error("Failed to discover MQTT brokers");
|
|
649
|
+
return e.brokers;
|
|
650
|
+
}
|
|
651
|
+
async connect(e, t) {
|
|
652
|
+
const s = await this._client.request("mqtt.connect", {
|
|
653
|
+
brokerUrl: e,
|
|
654
|
+
...t
|
|
655
|
+
});
|
|
656
|
+
if (!s.success)
|
|
657
|
+
throw new Error("Failed to connect to MQTT broker");
|
|
658
|
+
return s.clientId;
|
|
659
|
+
}
|
|
660
|
+
async disconnect(e) {
|
|
661
|
+
if (!(await this._client.request("mqtt.disconnect", { clientId: e })).success)
|
|
662
|
+
throw new Error("Failed to disconnect from MQTT broker");
|
|
663
|
+
}
|
|
664
|
+
async publish(e, t, s, i) {
|
|
665
|
+
if (!(await this._client.request("mqtt.publish", {
|
|
666
|
+
clientId: e,
|
|
667
|
+
topic: t,
|
|
668
|
+
payload: s,
|
|
669
|
+
...i
|
|
670
|
+
})).success)
|
|
671
|
+
throw new Error("Failed to publish MQTT message");
|
|
672
|
+
}
|
|
673
|
+
async subscribe(e, t, s, i) {
|
|
674
|
+
return (await this._client.subscribe("mqtt.subscribe", {
|
|
675
|
+
clientId: e,
|
|
676
|
+
topic: t,
|
|
677
|
+
...i
|
|
678
|
+
}, s)).success;
|
|
679
|
+
}
|
|
680
|
+
async unsubscribe(e, t, s) {
|
|
681
|
+
return (await this._client.unsubscribe("mqtt.unsubscribe", {
|
|
682
|
+
clientId: e,
|
|
683
|
+
topic: t
|
|
684
|
+
}, s)).success;
|
|
685
|
+
}
|
|
686
|
+
async getConnectionStatus(e) {
|
|
687
|
+
const t = await this._client.request("mqtt.getConnectionStatus", {
|
|
688
|
+
clientId: e
|
|
689
|
+
});
|
|
690
|
+
if (!t.success)
|
|
691
|
+
throw new Error("Failed to get MQTT connection status");
|
|
692
|
+
return t.status;
|
|
693
|
+
}
|
|
694
|
+
async subscribeConnectionStatus(e, t) {
|
|
695
|
+
return (await this._client.subscribe("mqtt.subscribeConnectionStatus", {
|
|
696
|
+
clientId: e
|
|
697
|
+
}, t)).success;
|
|
698
|
+
}
|
|
699
|
+
async unsubscribeConnectionStatus(e, t) {
|
|
700
|
+
return (await this._client.unsubscribe("mqtt.unsubscribeConnectionStatus", {
|
|
701
|
+
clientId: e
|
|
702
|
+
}, t)).success;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
function q(c) {
|
|
706
|
+
return { ...c, type: "client" };
|
|
625
707
|
}
|
|
626
|
-
const W =
|
|
627
|
-
type:
|
|
708
|
+
const W = C({
|
|
709
|
+
type: F("bridge"),
|
|
628
710
|
name: M(),
|
|
629
|
-
data:
|
|
711
|
+
data: H()
|
|
630
712
|
});
|
|
631
713
|
class G {
|
|
632
714
|
/**
|
|
@@ -652,11 +734,11 @@ class G {
|
|
|
652
734
|
*/
|
|
653
735
|
async setRootSettingsNavigation(e) {
|
|
654
736
|
var t;
|
|
655
|
-
const s = this._store.shared("root-settings-navigation"),
|
|
656
|
-
|
|
737
|
+
const s = this._store.shared("root-settings-navigation"), i = (t = await s.get("navigation")) !== null && t !== void 0 ? t : {}, n = this._store._client._applicationSpecifier;
|
|
738
|
+
i[n] = {
|
|
657
739
|
applicationSpecifier: n,
|
|
658
740
|
entries: e.entries
|
|
659
|
-
}, s.set("navigation",
|
|
741
|
+
}, s.set("navigation", i);
|
|
660
742
|
}
|
|
661
743
|
/**
|
|
662
744
|
* Retrieves the current navigation entries for this root application.
|
|
@@ -668,8 +750,8 @@ class G {
|
|
|
668
750
|
*/
|
|
669
751
|
async getRootSettingsNavigation() {
|
|
670
752
|
var e;
|
|
671
|
-
const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {},
|
|
672
|
-
return s[
|
|
753
|
+
const s = (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {}, i = this._store._client._applicationSpecifier;
|
|
754
|
+
return s[i];
|
|
673
755
|
}
|
|
674
756
|
/**
|
|
675
757
|
* Retrieves the navigation entries for all root applications.
|
|
@@ -685,9 +767,9 @@ class G {
|
|
|
685
767
|
return (e = await this._store.shared("root-settings-navigation").get("navigation")) !== null && e !== void 0 ? e : {};
|
|
686
768
|
}
|
|
687
769
|
}
|
|
688
|
-
const
|
|
689
|
-
function
|
|
690
|
-
|
|
770
|
+
const b = 1e3 * 30, I = typeof window > "u" && typeof self < "u", v = I ? self : window;
|
|
771
|
+
function y(c) {
|
|
772
|
+
I ? self.postMessage(c) : v.parent.postMessage(c, "*");
|
|
691
773
|
}
|
|
692
774
|
class J {
|
|
693
775
|
/**
|
|
@@ -715,7 +797,7 @@ class J {
|
|
|
715
797
|
* @returns An Accounts instance bound to this client
|
|
716
798
|
*/
|
|
717
799
|
get accounts() {
|
|
718
|
-
return new
|
|
800
|
+
return new k(this);
|
|
719
801
|
}
|
|
720
802
|
/**
|
|
721
803
|
* Provides access to the users API for retrieving TelemetryOS user information.
|
|
@@ -729,7 +811,7 @@ class J {
|
|
|
729
811
|
* @returns A Users instance bound to this client
|
|
730
812
|
*/
|
|
731
813
|
get users() {
|
|
732
|
-
return new
|
|
814
|
+
return new Q(this);
|
|
733
815
|
}
|
|
734
816
|
/**
|
|
735
817
|
* Provides access to the store API for data persistence with multiple storage scopes.
|
|
@@ -757,7 +839,7 @@ class J {
|
|
|
757
839
|
* @returns An Applications instance bound to this client
|
|
758
840
|
*/
|
|
759
841
|
get applications() {
|
|
760
|
-
return new
|
|
842
|
+
return new B(this);
|
|
761
843
|
}
|
|
762
844
|
/**
|
|
763
845
|
* Provides access to the media API for working with content hosted on the TelemetryOS platform.
|
|
@@ -801,7 +883,7 @@ class J {
|
|
|
801
883
|
* @returns A Devices instance bound to this client
|
|
802
884
|
*/
|
|
803
885
|
get devices() {
|
|
804
|
-
return new
|
|
886
|
+
return new $(this);
|
|
805
887
|
}
|
|
806
888
|
/**
|
|
807
889
|
* Provides access to the root settings navigation API for TelemetryOS administration UI integration.
|
|
@@ -833,7 +915,7 @@ class J {
|
|
|
833
915
|
* @returns A Weather instance bound to this client
|
|
834
916
|
*/
|
|
835
917
|
get weather() {
|
|
836
|
-
return new
|
|
918
|
+
return new L(this);
|
|
837
919
|
}
|
|
838
920
|
/**
|
|
839
921
|
* Provides access to the currency API for retrieving currency exchange rates.
|
|
@@ -847,7 +929,7 @@ class J {
|
|
|
847
929
|
* @returns A Currency instance bound to this client
|
|
848
930
|
*/
|
|
849
931
|
get currency() {
|
|
850
|
-
return new
|
|
932
|
+
return new U(this);
|
|
851
933
|
}
|
|
852
934
|
/**
|
|
853
935
|
* Provides access to the environment API for accessing environment settings.
|
|
@@ -863,6 +945,9 @@ class J {
|
|
|
863
945
|
get environment() {
|
|
864
946
|
return new R(this);
|
|
865
947
|
}
|
|
948
|
+
get mqtt() {
|
|
949
|
+
return new V(this);
|
|
950
|
+
}
|
|
866
951
|
get applicationName() {
|
|
867
952
|
return this._applicationName;
|
|
868
953
|
}
|
|
@@ -889,46 +974,46 @@ class J {
|
|
|
889
974
|
*/
|
|
890
975
|
bind() {
|
|
891
976
|
var e, t, s;
|
|
892
|
-
const
|
|
977
|
+
const i = new URL(v.location.href), n = i.searchParams;
|
|
893
978
|
if (this._applicationInstance = (e = n.get("applicationInstance")) !== null && e !== void 0 ? e : "", !this._applicationInstance)
|
|
894
979
|
throw new Error("Missing applicationInstance query parameter");
|
|
895
980
|
if (this._applicationSpecifier = (t = n.get("applicationSpecifier")) !== null && t !== void 0 ? t : "", !this._applicationSpecifier) {
|
|
896
|
-
const
|
|
897
|
-
this._applicationSpecifier = (s =
|
|
981
|
+
const o = i.hostname.split(".");
|
|
982
|
+
this._applicationSpecifier = (s = o[0]) !== null && s !== void 0 ? s : "";
|
|
898
983
|
}
|
|
899
984
|
if (!this._applicationSpecifier || this._applicationSpecifier.length !== 40)
|
|
900
985
|
throw new Error(`Invalid applicationSpecifier: expected 40-character hash, got "${this._applicationSpecifier}"`);
|
|
901
|
-
this._windowMessageHandler = (
|
|
902
|
-
if (
|
|
986
|
+
this._windowMessageHandler = (o) => {
|
|
987
|
+
if (o.source === v || !o.data || typeof o.data != "object" || !("type" in o.data) || o.data.type !== "client" && o.data.type !== "bridge")
|
|
903
988
|
return;
|
|
904
|
-
let
|
|
905
|
-
if (
|
|
906
|
-
const
|
|
907
|
-
if (!
|
|
908
|
-
|
|
989
|
+
let u;
|
|
990
|
+
if (o.data.type === "client") {
|
|
991
|
+
const a = this._messageInterceptors.get(o.data.name);
|
|
992
|
+
if (!a) {
|
|
993
|
+
y(o.data);
|
|
909
994
|
return;
|
|
910
995
|
}
|
|
911
|
-
|
|
996
|
+
u = { ...a(o.data.data), type: "bridge" };
|
|
912
997
|
}
|
|
913
|
-
if (!
|
|
914
|
-
const
|
|
915
|
-
if (!
|
|
998
|
+
if (!u) {
|
|
999
|
+
const a = W.safeParse(o.data);
|
|
1000
|
+
if (!a.success)
|
|
916
1001
|
return;
|
|
917
|
-
|
|
918
|
-
const d = this._onHandlers.get(
|
|
1002
|
+
u = a.data;
|
|
1003
|
+
const d = this._onHandlers.get(u.name), l = this._onceHandlers.get(u.name);
|
|
919
1004
|
if (d)
|
|
920
|
-
for (const
|
|
921
|
-
|
|
922
|
-
if (
|
|
923
|
-
for (const
|
|
924
|
-
|
|
925
|
-
this._onceHandlers.delete(
|
|
1005
|
+
for (const p of d)
|
|
1006
|
+
p(u.data);
|
|
1007
|
+
if (l) {
|
|
1008
|
+
for (const p of l)
|
|
1009
|
+
p(u.data);
|
|
1010
|
+
this._onceHandlers.delete(u.name);
|
|
926
1011
|
}
|
|
927
1012
|
}
|
|
928
|
-
if (!
|
|
929
|
-
for (let
|
|
930
|
-
window.frames[
|
|
931
|
-
},
|
|
1013
|
+
if (!I)
|
|
1014
|
+
for (let a = 0; a < window.frames.length; a += 1)
|
|
1015
|
+
window.frames[a].postMessage(u, "*");
|
|
1016
|
+
}, v.addEventListener("message", this._windowMessageHandler);
|
|
932
1017
|
}
|
|
933
1018
|
/**
|
|
934
1019
|
* Removes the message event listener and cleans up resources.
|
|
@@ -944,7 +1029,7 @@ class J {
|
|
|
944
1029
|
* of managing their own Client instances.
|
|
945
1030
|
*/
|
|
946
1031
|
unbind() {
|
|
947
|
-
this._windowMessageHandler &&
|
|
1032
|
+
this._windowMessageHandler && v.removeEventListener("message", this._windowMessageHandler);
|
|
948
1033
|
}
|
|
949
1034
|
/**
|
|
950
1035
|
* Sends a one-way message to the TelemetryOS platform.
|
|
@@ -960,15 +1045,15 @@ class J {
|
|
|
960
1045
|
* @param data The data payload to include with the message
|
|
961
1046
|
*/
|
|
962
1047
|
send(e, t) {
|
|
963
|
-
const s =
|
|
964
|
-
telemetrySdkVersion:
|
|
1048
|
+
const s = q({
|
|
1049
|
+
telemetrySdkVersion: E,
|
|
965
1050
|
applicationName: this._applicationName,
|
|
966
1051
|
applicationSpecifier: this._applicationSpecifier,
|
|
967
1052
|
applicationInstance: this._applicationInstance,
|
|
968
1053
|
name: e,
|
|
969
1054
|
data: t
|
|
970
1055
|
});
|
|
971
|
-
|
|
1056
|
+
y(s);
|
|
972
1057
|
}
|
|
973
1058
|
/**
|
|
974
1059
|
* Sends a message to the TelemetryOS platform and waits for a response.
|
|
@@ -984,100 +1069,107 @@ class J {
|
|
|
984
1069
|
* @template D The expected type of the response data
|
|
985
1070
|
* @param name The name of the message type (endpoint) to request
|
|
986
1071
|
* @param data The data payload to include with the request
|
|
1072
|
+
* @param options Optional configuration for this request
|
|
1073
|
+
* @param options.timeout Override the default timeout in milliseconds. Set to 0 to disable timeout.
|
|
987
1074
|
* @returns A promise that resolves with the response data when received
|
|
988
1075
|
* @throws {Error} If the request times out
|
|
989
1076
|
*/
|
|
990
|
-
request(e, t) {
|
|
991
|
-
|
|
992
|
-
|
|
1077
|
+
request(e, t, s) {
|
|
1078
|
+
var i;
|
|
1079
|
+
const n = N(), o = q({
|
|
1080
|
+
telemetrySdkVersion: E,
|
|
993
1081
|
applicationName: this._applicationName,
|
|
994
1082
|
applicationSpecifier: this._applicationSpecifier,
|
|
995
1083
|
applicationInstance: this._applicationInstance,
|
|
996
1084
|
name: e,
|
|
997
1085
|
data: t,
|
|
998
|
-
responseName:
|
|
1086
|
+
responseName: n
|
|
999
1087
|
});
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1088
|
+
y(o);
|
|
1089
|
+
const u = (i = s == null ? void 0 : s.timeout) !== null && i !== void 0 ? i : b;
|
|
1090
|
+
let a = !1, d;
|
|
1091
|
+
const l = new Promise((f) => {
|
|
1092
|
+
d = (g) => {
|
|
1093
|
+
a || f(g);
|
|
1094
|
+
}, this.once(n, d);
|
|
1095
|
+
});
|
|
1096
|
+
if (u === 0)
|
|
1097
|
+
return l;
|
|
1098
|
+
const p = new Promise((f, g) => {
|
|
1099
|
+
const m = new Error(`${e} message request with response name of ${n} timed out after ${u}`);
|
|
1004
1100
|
setTimeout(() => {
|
|
1005
|
-
|
|
1006
|
-
},
|
|
1007
|
-
}), c = new Promise((d) => {
|
|
1008
|
-
i = (u) => {
|
|
1009
|
-
n || d(u);
|
|
1010
|
-
}, this.once(s, d);
|
|
1101
|
+
a = !0, this.off(n, d), g(m);
|
|
1102
|
+
}, u);
|
|
1011
1103
|
});
|
|
1012
|
-
return Promise.race([
|
|
1104
|
+
return Promise.race([p, l]);
|
|
1013
1105
|
}
|
|
1014
1106
|
async subscribe(e, t, s) {
|
|
1015
|
-
let
|
|
1016
|
-
typeof t == "function" ? n = t : (
|
|
1017
|
-
const
|
|
1018
|
-
let
|
|
1019
|
-
|
|
1020
|
-
const d =
|
|
1021
|
-
telemetrySdkVersion:
|
|
1107
|
+
let i, n;
|
|
1108
|
+
typeof t == "function" ? n = t : (i = t, n = s);
|
|
1109
|
+
const o = N(), u = N();
|
|
1110
|
+
let a = this._subscriptionNamesBySubjectName.get(e);
|
|
1111
|
+
a || (a = [], this._subscriptionNamesBySubjectName.set(e, a)), a.push(o), this._subscriptionNamesByHandler.set(n, o), this.on(o, n);
|
|
1112
|
+
const d = q({
|
|
1113
|
+
telemetrySdkVersion: E,
|
|
1022
1114
|
applicationName: this._applicationName,
|
|
1023
1115
|
applicationSpecifier: this._applicationSpecifier,
|
|
1024
1116
|
applicationInstance: this._applicationInstance,
|
|
1025
1117
|
name: e,
|
|
1026
|
-
data:
|
|
1027
|
-
responseName:
|
|
1028
|
-
subscriptionName:
|
|
1118
|
+
data: i,
|
|
1119
|
+
responseName: u,
|
|
1120
|
+
subscriptionName: o
|
|
1029
1121
|
});
|
|
1030
|
-
|
|
1031
|
-
let
|
|
1032
|
-
const f = new Promise((
|
|
1033
|
-
const
|
|
1122
|
+
y(d);
|
|
1123
|
+
let l = !1, p;
|
|
1124
|
+
const f = new Promise((m, w) => {
|
|
1125
|
+
const _ = new Error(`${e} subscribe request with subscription name of ${o} and response name of ${u} timed out after ${b}`);
|
|
1034
1126
|
setTimeout(() => {
|
|
1035
|
-
|
|
1036
|
-
},
|
|
1037
|
-
}),
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
}, this.on(
|
|
1127
|
+
l = !0, this.off(u, p), w(_);
|
|
1128
|
+
}, b);
|
|
1129
|
+
}), g = new Promise((m) => {
|
|
1130
|
+
p = (w) => {
|
|
1131
|
+
l || m(w);
|
|
1132
|
+
}, this.on(u, m);
|
|
1041
1133
|
});
|
|
1042
|
-
return Promise.race([f,
|
|
1134
|
+
return Promise.race([f, g]);
|
|
1043
1135
|
}
|
|
1044
1136
|
async unsubscribe(e, t, s) {
|
|
1045
|
-
let
|
|
1046
|
-
typeof t == "function" ? n = t : (
|
|
1047
|
-
const
|
|
1048
|
-
let
|
|
1137
|
+
let i, n;
|
|
1138
|
+
typeof t == "function" ? n = t : (i = t, n = s);
|
|
1139
|
+
const o = N();
|
|
1140
|
+
let u = [];
|
|
1049
1141
|
if (n) {
|
|
1050
|
-
const
|
|
1051
|
-
if (!
|
|
1142
|
+
const a = this._subscriptionNamesByHandler.get(n);
|
|
1143
|
+
if (!a)
|
|
1052
1144
|
return { success: !1 };
|
|
1053
|
-
|
|
1145
|
+
u = [a], this._subscriptionNamesByHandler.delete(n);
|
|
1054
1146
|
} else if (!this._subscriptionNamesBySubjectName.get(e))
|
|
1055
1147
|
return { success: !1 };
|
|
1056
|
-
for await (const
|
|
1057
|
-
this.off(
|
|
1058
|
-
const d =
|
|
1059
|
-
telemetrySdkVersion:
|
|
1148
|
+
for await (const a of u) {
|
|
1149
|
+
this.off(a, n);
|
|
1150
|
+
const d = q({
|
|
1151
|
+
telemetrySdkVersion: E,
|
|
1060
1152
|
applicationInstance: this._applicationInstance,
|
|
1061
1153
|
applicationName: this._applicationName,
|
|
1062
1154
|
applicationSpecifier: this._applicationSpecifier,
|
|
1063
1155
|
name: e,
|
|
1064
|
-
data:
|
|
1065
|
-
responseName:
|
|
1066
|
-
unsubscribeName:
|
|
1156
|
+
data: i,
|
|
1157
|
+
responseName: o,
|
|
1158
|
+
unsubscribeName: a
|
|
1067
1159
|
});
|
|
1068
|
-
|
|
1069
|
-
let
|
|
1070
|
-
const f = new Promise((
|
|
1071
|
-
const
|
|
1160
|
+
y(d);
|
|
1161
|
+
let l = !1, p;
|
|
1162
|
+
const f = new Promise((w, _) => {
|
|
1163
|
+
const T = new Error(`${e} unsubscribe request with unsubscribe name of ${a} and response name of ${o} timed out after ${b}`);
|
|
1072
1164
|
setTimeout(() => {
|
|
1073
|
-
|
|
1074
|
-
},
|
|
1075
|
-
}),
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
}, this.once(
|
|
1165
|
+
l = !0, this.off(o, p), _(T);
|
|
1166
|
+
}, b);
|
|
1167
|
+
}), g = new Promise((w) => {
|
|
1168
|
+
p = (_) => {
|
|
1169
|
+
l || w(_);
|
|
1170
|
+
}, this.once(o, w);
|
|
1079
1171
|
});
|
|
1080
|
-
if (!(await Promise.race([f,
|
|
1172
|
+
if (!(await Promise.race([f, g])).success)
|
|
1081
1173
|
return { success: !1 };
|
|
1082
1174
|
}
|
|
1083
1175
|
return { success: !0 };
|
|
@@ -1101,8 +1193,8 @@ class J {
|
|
|
1101
1193
|
*/
|
|
1102
1194
|
on(e, t) {
|
|
1103
1195
|
var s;
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1196
|
+
const i = (s = this._onHandlers.get(e)) !== null && s !== void 0 ? s : [];
|
|
1197
|
+
i.length === 0 && this._onHandlers.set(e, i), i.push(t);
|
|
1106
1198
|
}
|
|
1107
1199
|
/**
|
|
1108
1200
|
* Registers a one-time handler for a specific message type.
|
|
@@ -1120,8 +1212,8 @@ class J {
|
|
|
1120
1212
|
*/
|
|
1121
1213
|
once(e, t) {
|
|
1122
1214
|
var s;
|
|
1123
|
-
const
|
|
1124
|
-
|
|
1215
|
+
const i = (s = this._onceHandlers.get(e)) !== null && s !== void 0 ? s : [];
|
|
1216
|
+
i.length === 0 && this._onceHandlers.set(e, i), i.push(t);
|
|
1125
1217
|
}
|
|
1126
1218
|
/**
|
|
1127
1219
|
* Removes previously registered message handlers.
|
|
@@ -1139,17 +1231,17 @@ class J {
|
|
|
1139
1231
|
* all handlers for this message type will be removed.
|
|
1140
1232
|
*/
|
|
1141
1233
|
off(e, t) {
|
|
1142
|
-
const s = this._onHandlers.get(e),
|
|
1143
|
-
if (!(!s && !
|
|
1234
|
+
const s = this._onHandlers.get(e), i = this._onceHandlers.get(e);
|
|
1235
|
+
if (!(!s && !i)) {
|
|
1144
1236
|
if (s) {
|
|
1145
1237
|
for (let n = 0; n < s.length; n += 1)
|
|
1146
1238
|
t && s[n] !== t || (s.splice(n, 1), n -= 1);
|
|
1147
1239
|
s.length === 0 && this._onHandlers.delete(e);
|
|
1148
1240
|
}
|
|
1149
|
-
if (
|
|
1150
|
-
for (let n = 0; n <
|
|
1151
|
-
t &&
|
|
1152
|
-
|
|
1241
|
+
if (i) {
|
|
1242
|
+
for (let n = 0; n < i.length; n += 1)
|
|
1243
|
+
t && i[n] !== t || (i.splice(n, 1), n -= 1);
|
|
1244
|
+
i.length === 0 && this._onceHandlers.delete(e);
|
|
1153
1245
|
}
|
|
1154
1246
|
}
|
|
1155
1247
|
}
|
|
@@ -1157,108 +1249,113 @@ class J {
|
|
|
1157
1249
|
function N() {
|
|
1158
1250
|
return Math.random().toString(36).slice(2, 9);
|
|
1159
1251
|
}
|
|
1160
|
-
const
|
|
1252
|
+
const E = A.version;
|
|
1161
1253
|
let r = null;
|
|
1162
1254
|
function O() {
|
|
1163
1255
|
return r;
|
|
1164
1256
|
}
|
|
1165
|
-
function z(
|
|
1166
|
-
r = new J(
|
|
1257
|
+
function z(c) {
|
|
1258
|
+
r = new J(c), r.bind();
|
|
1167
1259
|
}
|
|
1168
|
-
function
|
|
1260
|
+
function X() {
|
|
1169
1261
|
r == null || r.unbind(), r = null;
|
|
1170
1262
|
}
|
|
1171
|
-
function
|
|
1172
|
-
return
|
|
1173
|
-
}
|
|
1174
|
-
function Y(...a) {
|
|
1175
|
-
return p(r), r.once(...a);
|
|
1263
|
+
function Y(...c) {
|
|
1264
|
+
return h(r), r.on(...c);
|
|
1176
1265
|
}
|
|
1177
|
-
function Z(...
|
|
1178
|
-
return
|
|
1266
|
+
function Z(...c) {
|
|
1267
|
+
return h(r), r.once(...c);
|
|
1179
1268
|
}
|
|
1180
|
-
function ee(...
|
|
1181
|
-
return
|
|
1269
|
+
function ee(...c) {
|
|
1270
|
+
return h(r), r.off(...c);
|
|
1182
1271
|
}
|
|
1183
|
-
function te(...
|
|
1184
|
-
return
|
|
1272
|
+
function te(...c) {
|
|
1273
|
+
return h(r), r.send(...c);
|
|
1185
1274
|
}
|
|
1186
|
-
function se(...
|
|
1187
|
-
return
|
|
1275
|
+
function se(...c) {
|
|
1276
|
+
return h(r), r.request(...c);
|
|
1188
1277
|
}
|
|
1189
|
-
function ne(...
|
|
1190
|
-
return
|
|
1278
|
+
function ne(...c) {
|
|
1279
|
+
return h(r), r.subscribe(...c);
|
|
1191
1280
|
}
|
|
1192
|
-
function ie() {
|
|
1193
|
-
return
|
|
1281
|
+
function ie(...c) {
|
|
1282
|
+
return h(r), r.unsubscribe(...c);
|
|
1194
1283
|
}
|
|
1195
1284
|
function re() {
|
|
1196
|
-
return
|
|
1285
|
+
return h(r), r.store;
|
|
1197
1286
|
}
|
|
1198
1287
|
function oe() {
|
|
1199
|
-
return
|
|
1200
|
-
}
|
|
1201
|
-
function ae() {
|
|
1202
|
-
return p(r), r.accounts;
|
|
1288
|
+
return h(r), r.applications;
|
|
1203
1289
|
}
|
|
1204
1290
|
function ce() {
|
|
1205
|
-
return
|
|
1291
|
+
return h(r), r.media;
|
|
1206
1292
|
}
|
|
1207
|
-
function
|
|
1208
|
-
return
|
|
1293
|
+
function ae() {
|
|
1294
|
+
return h(r), r.accounts;
|
|
1209
1295
|
}
|
|
1210
1296
|
function ue() {
|
|
1211
|
-
return
|
|
1297
|
+
return h(r), r.users;
|
|
1298
|
+
}
|
|
1299
|
+
function le() {
|
|
1300
|
+
return h(r), r.devices;
|
|
1212
1301
|
}
|
|
1213
1302
|
function he() {
|
|
1214
|
-
return
|
|
1303
|
+
return h(r), r.proxy;
|
|
1215
1304
|
}
|
|
1216
1305
|
function pe() {
|
|
1217
|
-
return
|
|
1306
|
+
return h(r), r.rootSettingsNavigation;
|
|
1218
1307
|
}
|
|
1219
1308
|
function de() {
|
|
1220
|
-
return
|
|
1309
|
+
return h(r), r.weather;
|
|
1221
1310
|
}
|
|
1222
1311
|
function fe() {
|
|
1223
|
-
return
|
|
1312
|
+
return h(r), r.currency;
|
|
1313
|
+
}
|
|
1314
|
+
function ge() {
|
|
1315
|
+
return h(r), r.environment;
|
|
1316
|
+
}
|
|
1317
|
+
function we() {
|
|
1318
|
+
return h(r), r.mqtt;
|
|
1224
1319
|
}
|
|
1225
|
-
function
|
|
1226
|
-
if (!
|
|
1320
|
+
function h(c) {
|
|
1321
|
+
if (!c)
|
|
1227
1322
|
throw new Error("SDK is not configured");
|
|
1228
1323
|
}
|
|
1229
1324
|
export {
|
|
1230
|
-
|
|
1231
|
-
|
|
1325
|
+
k as Accounts,
|
|
1326
|
+
B as Applications,
|
|
1232
1327
|
J as Client,
|
|
1233
|
-
|
|
1234
|
-
|
|
1328
|
+
U as Currency,
|
|
1329
|
+
$ as Devices,
|
|
1235
1330
|
R as Environment,
|
|
1236
1331
|
x as Media,
|
|
1332
|
+
V as Mqtt,
|
|
1237
1333
|
j as Proxy,
|
|
1238
1334
|
D as Store,
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1335
|
+
S as StoreSlice,
|
|
1336
|
+
Q as Users,
|
|
1337
|
+
L as Weather,
|
|
1242
1338
|
ae as accounts,
|
|
1243
|
-
|
|
1339
|
+
oe as applications,
|
|
1244
1340
|
z as configure,
|
|
1245
|
-
|
|
1246
|
-
|
|
1341
|
+
fe as currency,
|
|
1342
|
+
X as destroy,
|
|
1247
1343
|
le as devices,
|
|
1248
|
-
|
|
1344
|
+
ge as environment,
|
|
1249
1345
|
O as globalClient,
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
Y as
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1346
|
+
ce as media,
|
|
1347
|
+
we as mqtt,
|
|
1348
|
+
ee as off,
|
|
1349
|
+
Y as on,
|
|
1350
|
+
Z as once,
|
|
1351
|
+
he as proxy,
|
|
1352
|
+
se as request,
|
|
1353
|
+
pe as rootSettingsNavigation,
|
|
1354
|
+
te as send,
|
|
1355
|
+
re as store,
|
|
1356
|
+
ne as subscribe,
|
|
1357
|
+
E as telemetrySdkVersion,
|
|
1358
|
+
ie as unsubscribe,
|
|
1359
|
+
ue as users,
|
|
1360
|
+
de as weather
|
|
1264
1361
|
};
|
package/dist/mqtt.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Client, type MessageHandler } from './client.js';
|
|
2
|
+
export type MqttBrokerInfo = {
|
|
3
|
+
name: string;
|
|
4
|
+
address: string;
|
|
5
|
+
port: number;
|
|
6
|
+
protocol: 'mqtt' | 'mqtts' | 'ws' | 'wss';
|
|
7
|
+
};
|
|
8
|
+
export type MqttConnectOptions = {
|
|
9
|
+
username?: string;
|
|
10
|
+
password?: string;
|
|
11
|
+
clientId?: string;
|
|
12
|
+
keepalive?: number;
|
|
13
|
+
clean?: boolean;
|
|
14
|
+
reconnectPeriod?: number;
|
|
15
|
+
connectTimeout?: number;
|
|
16
|
+
};
|
|
17
|
+
export type MqttPublishOptions = {
|
|
18
|
+
qos?: 0 | 1 | 2;
|
|
19
|
+
retain?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type MqttSubscribeOptions = {
|
|
22
|
+
qos?: 0 | 1 | 2;
|
|
23
|
+
};
|
|
24
|
+
export type MqttConnectionStatus = 'connected' | 'disconnected' | 'connecting' | 'reconnecting' | 'error';
|
|
25
|
+
export type MqttMessage = {
|
|
26
|
+
topic: string;
|
|
27
|
+
payload: string;
|
|
28
|
+
qos: 0 | 1 | 2;
|
|
29
|
+
retain: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare class Mqtt {
|
|
32
|
+
_client: Client;
|
|
33
|
+
constructor(client: Client);
|
|
34
|
+
discover(): Promise<MqttBrokerInfo[]>;
|
|
35
|
+
connect(brokerUrl: string, options?: MqttConnectOptions): Promise<string>;
|
|
36
|
+
disconnect(clientId: string): Promise<void>;
|
|
37
|
+
publish(clientId: string, topic: string, payload: string, options?: MqttPublishOptions): Promise<void>;
|
|
38
|
+
subscribe(clientId: string, topic: string, handler: MessageHandler<MqttMessage>, options?: MqttSubscribeOptions): Promise<boolean>;
|
|
39
|
+
unsubscribe(clientId: string, topic: string, handler?: MessageHandler<MqttMessage>): Promise<boolean>;
|
|
40
|
+
getConnectionStatus(clientId: string): Promise<MqttConnectionStatus>;
|
|
41
|
+
subscribeConnectionStatus(clientId: string, handler: MessageHandler<MqttConnectionStatus>): Promise<boolean>;
|
|
42
|
+
unsubscribeConnectionStatus(clientId: string, handler?: MessageHandler<MqttConnectionStatus>): Promise<boolean>;
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemetryos/root-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "The official TelemetryOS root application sdk package. Provides types and apis for building root TelemetryOS applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|