@streamlayer/sdk-web
Advanced tools
Comparing version
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"type": "module", | ||
@@ -12,0 +12,0 @@ "main": "./src/index.js", |
@@ -0,1 +1,2 @@ | ||
import { Feature } from './features'; | ||
/** | ||
@@ -16,2 +17,3 @@ * The main application instance is the core of a application. It includes: | ||
*/ | ||
getFeatures: () => Map<string, Feature>; | ||
initializeApp: () => Promise<{ | ||
@@ -25,2 +27,3 @@ enabled: boolean; | ||
disableApp: () => void; | ||
invalidateSettings: () => void; | ||
/** | ||
@@ -27,0 +30,0 @@ * Configure the "event id" using the "provider," enabling subscribed stores to |
@@ -14,6 +14,3 @@ import { kStore, kStoreSubscribe, kStoreUnsubscribe } from './keys'; | ||
constructor(){ | ||
/** | ||
* On initialize we subscribe to store and launch listeners | ||
* that activate data downloading over the network | ||
*/ this.initializeApp = async ()=>{ | ||
this.initializeApp = async ()=>{ | ||
this[kStoreSubscribe](); | ||
@@ -47,2 +44,7 @@ this[kStore].getStoreItem('enabled').setValue('on'); | ||
}; | ||
this.invalidateSettings = ()=>{ | ||
this.transport.nanoquery.utils.invalidateKeys(()=>{ | ||
return true; | ||
}); | ||
}; | ||
/** | ||
@@ -49,0 +51,0 @@ * Configure the "event id" using the "provider," enabling subscribed stores to |
import { FeatureConfig } from '@streamlayer/sdk-web-types'; | ||
import { AbstractFeature } from '@streamlayer/sdk-web-interfaces'; | ||
import { AbstractFeature, FeatureSource } from '@streamlayer/sdk-web-interfaces'; | ||
import { StreamLayerContext } from '../'; | ||
@@ -8,3 +8,3 @@ import { kFeatures, kFeatureInit } from '../keys'; | ||
[kFeatures]: Map<FeatureConfig['name'], Feature>; | ||
[kFeatureInit]: (overlay: FeatureConfig) => void; | ||
[kFeatureInit]: (overlay: FeatureConfig, source: FeatureSource) => Promise<void>; | ||
} | ||
@@ -14,3 +14,4 @@ } | ||
} | ||
export declare const initFeature: (overlay: FeatureConfig) => Feature; | ||
export declare const initFeature: (overlay: FeatureConfig, source: FeatureSource) => Feature; | ||
export { FeatureSource } from '@streamlayer/sdk-web-interfaces'; | ||
export declare const features: (instance: StreamLayerContext, opts: any, done: any) => void; |
import { AbstractFeature } from '@streamlayer/sdk-web-interfaces'; | ||
import { kFeatures, kFeatureInit } from '../keys'; | ||
import { kFeatures, kFeatureInit, kFeatureUpdate, kFeatureDestroy } from '../keys'; | ||
export class Feature extends AbstractFeature { | ||
} | ||
export const initFeature = (overlay)=>{ | ||
return new Feature(overlay); | ||
export const initFeature = (overlay, source)=>{ | ||
return new Feature(overlay, source); | ||
}; | ||
export { FeatureSource } from '@streamlayer/sdk-web-interfaces'; | ||
export const features = (instance, opts, done)=>{ | ||
@@ -12,6 +13,21 @@ instance.sdk[kFeatures] = new Map(); | ||
* A distinct object instance is created and initialized for each overlay. | ||
*/ instance.sdk[kFeatureInit] = (overlay)=>{ | ||
const feature = initFeature(overlay); | ||
*/ instance.sdk.getFeatures = ()=>{ | ||
return instance.sdk[kFeatures]; | ||
}; | ||
instance.sdk[kFeatureInit] = async (overlay, source)=>{ | ||
if (instance.sdk[kFeatures].has(overlay.name)) { | ||
await instance.sdk[kFeatureUpdate](overlay, source); | ||
return; | ||
} | ||
const feature = initFeature(overlay, source); | ||
instance.sdk[kFeatures].set(overlay.name, feature); | ||
}; | ||
// eslint-disable-next-line require-await | ||
instance.sdk[kFeatureUpdate] = async (overlay, source)=>{ | ||
instance.sdk[kFeatures].get(overlay.name).update(overlay, source); | ||
}; | ||
// eslint-disable-next-line require-await | ||
instance.sdk[kFeatureDestroy] = async (overlay)=>{ | ||
instance.sdk[kFeatures].delete(overlay.name); | ||
}; | ||
done(); | ||
@@ -18,0 +34,0 @@ }; |
export declare const kAuth: unique symbol; | ||
export declare const kFeatures: unique symbol; | ||
export declare const kFeatureInit: unique symbol; | ||
export declare const kFeatureUpdate: unique symbol; | ||
export declare const kFeatureDestroy: unique symbol; | ||
export declare const kStore: unique symbol; | ||
export declare const kStoreSubscribe: unique symbol; | ||
export declare const kStoreUnsubscribe: unique symbol; |
export const kAuth = Symbol('sdk-auth'); | ||
export const kFeatures = Symbol('sdk-features'); | ||
export const kFeatureInit = Symbol('sdk-features:initFeature'); | ||
export const kFeatureUpdate = Symbol('sdk-features:updateFeature'); | ||
export const kFeatureDestroy = Symbol('sdk-features:destroyFeature'); | ||
export const kStore = Symbol('sdk-store'); | ||
@@ -5,0 +7,0 @@ export const kStoreSubscribe = Symbol('sdk-store:storeSubscribe'); |
@@ -0,1 +1,2 @@ | ||
import { FeatureSource } from '@streamlayer/sdk-web-interfaces'; | ||
import { kStore, kStoreSubscribe, kStoreUnsubscribe, kFeatureInit } from '../keys'; | ||
@@ -13,2 +14,13 @@ import { CoreStore } from './store'; | ||
*/ instance.sdk[kStoreSubscribe] = ()=>{ | ||
const processSettings = (source, settings)=>{ | ||
if (!settings.data) return; | ||
const featureNames = new Set(); | ||
for (const overlay of settings.data.overlays){ | ||
const featureName = overlay.name; | ||
featureNames.add(featureName); | ||
instance.sdk[kFeatureInit](overlay, source).catch((initError)=>{ | ||
console.error(`Error initializing feature "${featureName}": ${initError}`); | ||
}); | ||
} | ||
}; | ||
const subscribes = { | ||
@@ -23,8 +35,6 @@ /** | ||
* missing in the new settings, it should be deinitialized. | ||
*/ organizationSettings: (orgSettings, changedKey)=>{ | ||
if (changedKey === 'data' && orgSettings.data) { | ||
*/ organizationSettings: (orgSettings)=>{ | ||
if (orgSettings.data) { | ||
try { | ||
for (const overlay of orgSettings.data.overlays){ | ||
instance.sdk[kFeatureInit](overlay); | ||
} | ||
processSettings(FeatureSource.ORGANIZATION, orgSettings); | ||
} catch (err) { | ||
@@ -34,2 +44,11 @@ console.log(err); | ||
} | ||
}, | ||
streamSettings: (streamSettings)=>{ | ||
if (streamSettings.data) { | ||
try { | ||
processSettings(FeatureSource.STREAM, streamSettings); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
} | ||
@@ -36,0 +55,0 @@ }; |
@@ -64,3 +64,3 @@ import type { OrganizationSettings, OrganizationAdvertising, StreamSettings, User, UserSettings } from '@streamlayer/sdk-web-types'; | ||
constructor(transport: Transport); | ||
getStoreItem: <T extends "enabled" | "status" | "providerStreamId" | "slStreamId" | "streamSettings" | "user" | "userKey" | "userToken" | "userSettings" | "organizationSettings" | "organizationAdvertising" = "enabled" | "status" | "providerStreamId" | "slStreamId" | "streamSettings" | "user" | "userKey" | "userToken" | "userSettings" | "organizationSettings" | "organizationAdvertising">(key: T) => { | ||
getStoreItem: <T extends "userKey" | "enabled" | "status" | "providerStreamId" | "slStreamId" | "streamSettings" | "user" | "userToken" | "userSettings" | "organizationSettings" | "organizationAdvertising" = "userKey" | "enabled" | "status" | "providerStreamId" | "slStreamId" | "streamSettings" | "user" | "userToken" | "userSettings" | "organizationSettings" | "organizationAdvertising">(key: T) => { | ||
readonly enabled: SingleStore<unknown, import("nanostores").WritableAtom<"on">>; | ||
@@ -67,0 +67,0 @@ readonly status: SingleStore<unknown, import("nanostores").WritableAtom<CoreStatus>>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
54717
11%601
8.09%