@peers-app/peers-sdk 0.8.11 → 0.8.12
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/dist/data/persistent-vars.d.ts +2 -0
- package/dist/data/persistent-vars.js +32 -25
- package/dist/rpc-types.d.ts +13 -0
- package/dist/rpc-types.js +12 -0
- package/package.json +1 -1
|
@@ -60,6 +60,8 @@ export declare class PersistentVarsTable extends Table<IPersistentVar> {
|
|
|
60
60
|
export declare function PersistentVars(dataContext?: DataContext): PersistentVarsTable;
|
|
61
61
|
export type PersistentVar<T> = Observable<T> & {
|
|
62
62
|
loadingPromise: Promise<PersistentVar<T>>;
|
|
63
|
+
/** Delete the persistent variable from the database and reset to default value */
|
|
64
|
+
delete: () => Promise<void>;
|
|
63
65
|
};
|
|
64
66
|
export declare function getPersistentVar(name: string, dataContext?: DataContext): Promise<IPersistentVar | undefined>;
|
|
65
67
|
interface IPersistentVarOptionsBase {
|
|
@@ -155,6 +155,14 @@ function persistentVarFactory(name, opts) {
|
|
|
155
155
|
pvarCache.set(cacheKey, persistentVar);
|
|
156
156
|
let isSecret = opts.isSecret;
|
|
157
157
|
let rec = undefined;
|
|
158
|
+
let deleteVarImpl = undefined;
|
|
159
|
+
// Assign the delete method - it will wait for loading and then call the implementation
|
|
160
|
+
persistentVar.delete = async () => {
|
|
161
|
+
await persistentVar.loadingPromise;
|
|
162
|
+
if (deleteVarImpl) {
|
|
163
|
+
await deleteVarImpl();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
158
166
|
persistentVar.loadingPromise = new Promise(async (resolve) => {
|
|
159
167
|
try {
|
|
160
168
|
const userContext = opts?.userContext || await (0, user_context_singleton_1.getUserContext)();
|
|
@@ -224,37 +232,36 @@ function persistentVarFactory(name, opts) {
|
|
|
224
232
|
rec.value.value = value;
|
|
225
233
|
const dc = getDataContext();
|
|
226
234
|
const table = PersistentVars(dc);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
console.log(`deleted persistent var ${name} from db:`, rec.value.value);
|
|
232
|
-
}
|
|
233
|
-
await table.delete(rec);
|
|
235
|
+
try {
|
|
236
|
+
rec = await table.save(rec);
|
|
237
|
+
if (name === 'colorModePreference') {
|
|
238
|
+
console.log(`Saved var ${name} to db:`, rec.value.value);
|
|
234
239
|
}
|
|
235
|
-
rec = undefined;
|
|
236
240
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
catch (err) {
|
|
242
|
+
const errMsg = err?.message || String(err) || '';
|
|
243
|
+
if (errMsg.includes('UNIQUE constraint failed')) {
|
|
244
|
+
console.warn(`Detected UNIQUE constraint failed error when saving persistent var, reloading and retrying: ${name}`);
|
|
245
|
+
rec = await loadRecFromDb();
|
|
246
|
+
persistentVar(rec.value.value);
|
|
243
247
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
console.warn(`Detected UNIQUE constraint failed error when saving persistent var, reloading and retrying: ${name}`);
|
|
248
|
-
rec = await loadRecFromDb();
|
|
249
|
-
persistentVar(rec.value.value);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
console.error('Error saving persistent var', { name, value, rec, err });
|
|
253
|
-
throw err;
|
|
254
|
-
}
|
|
248
|
+
else {
|
|
249
|
+
console.error('Error saving persistent var', { name, value, rec, err });
|
|
250
|
+
throw err;
|
|
255
251
|
}
|
|
256
252
|
}
|
|
257
253
|
}
|
|
254
|
+
deleteVarImpl = async () => {
|
|
255
|
+
const dc = getDataContext();
|
|
256
|
+
const table = PersistentVars(dc);
|
|
257
|
+
if (rec?.persistentVarId) {
|
|
258
|
+
await table.delete(rec);
|
|
259
|
+
rec = undefined;
|
|
260
|
+
}
|
|
261
|
+
if (defaultValue !== undefined) {
|
|
262
|
+
persistentVar(defaultValue);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
258
265
|
// subscribe to db changes
|
|
259
266
|
userContext.subscribeToDataChangedAcrossAllGroups(exports.persistentVarsMetaData.name, async (evt) => {
|
|
260
267
|
const dbRec = evt.data.dataObject;
|
package/dist/rpc-types.d.ts
CHANGED
|
@@ -93,6 +93,19 @@ export declare const rpcServerCalls: {
|
|
|
93
93
|
success: boolean;
|
|
94
94
|
error?: string;
|
|
95
95
|
}>);
|
|
96
|
+
voiceGetState: (() => Promise<{
|
|
97
|
+
state: "disabled" | "idle" | "listening" | "recording" | "processing" | "speaking";
|
|
98
|
+
}>);
|
|
99
|
+
voiceStartRecording: (() => Promise<void>);
|
|
100
|
+
voiceStopRecording: (() => Promise<void>);
|
|
101
|
+
voiceSetTargetChannel: ((channelId: string) => Promise<void>);
|
|
102
|
+
voiceGetAudioDevices: (() => Promise<string[]>);
|
|
103
|
+
voiceTestTTS: ((text: string) => Promise<void>);
|
|
104
|
+
voiceNotifyPlaybackComplete: (() => Promise<void>);
|
|
105
|
+
voiceStopPlayback: (() => Promise<void>);
|
|
106
|
+
voiceGetThreadId: (() => Promise<string | null>);
|
|
107
|
+
voiceSetThreadId: ((threadId: string | null) => Promise<void>);
|
|
108
|
+
voiceNotifyTextActivity: (() => Promise<void>);
|
|
96
109
|
};
|
|
97
110
|
export declare const rpcClientCalls: {
|
|
98
111
|
ping: (msg: string) => Promise<string>;
|
package/dist/rpc-types.js
CHANGED
|
@@ -39,6 +39,18 @@ exports.rpcServerCalls = {
|
|
|
39
39
|
uiClick: rpcStub('uiClick'),
|
|
40
40
|
uiSet: rpcStub('uiSet'),
|
|
41
41
|
uiScroll: rpcStub('uiScroll'),
|
|
42
|
+
// Voice control (settings managed via voiceSettings pvar, keys via secret pvars)
|
|
43
|
+
voiceGetState: rpcStub('voiceGetState'),
|
|
44
|
+
voiceStartRecording: rpcStub('voiceStartRecording'),
|
|
45
|
+
voiceStopRecording: rpcStub('voiceStopRecording'),
|
|
46
|
+
voiceSetTargetChannel: rpcStub('voiceSetTargetChannel'),
|
|
47
|
+
voiceGetAudioDevices: rpcStub('voiceGetAudioDevices'),
|
|
48
|
+
voiceTestTTS: rpcStub('voiceTestTTS'),
|
|
49
|
+
voiceNotifyPlaybackComplete: rpcStub('voiceNotifyPlaybackComplete'),
|
|
50
|
+
voiceStopPlayback: rpcStub('voiceStopPlayback'),
|
|
51
|
+
voiceGetThreadId: rpcStub('voiceGetThreadId'),
|
|
52
|
+
voiceSetThreadId: rpcStub('voiceSetThreadId'),
|
|
53
|
+
voiceNotifyTextActivity: rpcStub('voiceNotifyTextActivity'),
|
|
42
54
|
// TODO try to get rid of this and rely on the client-side table and server-side table individually emitting events
|
|
43
55
|
// TODO TODO before deleting this, check if we can stop client-side tables from emitting events and rely solely on server-side tables
|
|
44
56
|
// propagating events with rpcClientCalls.emitEvent. It's very likely we're currently seeing two events for every one write originating from the UI
|