23 lines
641 B
JavaScript
23 lines
641 B
JavaScript
// Thin wrapper over the preload API (window.teamspeach). Requests resolve to `result` or throw BridgeError.
|
|
|
|
export const tp = window.teamspeach;
|
|
|
|
export class BridgeError extends Error {
|
|
constructor(error) {
|
|
super(error?.message || error?.code || 'error');
|
|
this.code = error?.code ?? 'internal';
|
|
this.ts_error = error?.ts_error;
|
|
this.detail = error?.detail;
|
|
}
|
|
}
|
|
|
|
export async function call(cmd, args) {
|
|
const response = await tp.request(cmd, args);
|
|
if (!response || !response.ok) throw new BridgeError(response?.error);
|
|
return response.result;
|
|
}
|
|
|
|
export function log(level, message) {
|
|
tp.log(level, message);
|
|
}
|