Files
client/app/preload/preload.js
T
2026-10-24 03:43:41 +03:00

34 lines
1.7 KiB
JavaScript

'use strict';
// Sandboxed preload: the only surface the renderer gets. No paths, no commands, no generic IPC.
const { contextBridge, ipcRenderer } = require('electron');
function subscribe(channel, callback) {
if (typeof callback !== 'function') throw new TypeError('callback must be a function');
const handler = (_event, payload) => callback(payload);
ipcRenderer.on(channel, handler);
return () => ipcRenderer.removeListener(channel, handler);
}
contextBridge.exposeInMainWorld('teamspeach', {
request: (cmd, args) => ipcRenderer.invoke('core:request', cmd, args),
sendAudioFrame: (frame) => ipcRenderer.send('core:audio-frame', frame),
endAudio: () => ipcRenderer.send('core:audio-end'),
onEvent: (callback) => subscribe('core:event', callback),
onAudio: (callback) => subscribe('core:audio', callback),
onCoreStatus: (callback) => subscribe('core:status', callback),
getCoreStatus: () => ipcRenderer.invoke('core:status'),
restartCore: () => ipcRenderer.invoke('core:restart'),
getAppInfo: () => ipcRenderer.invoke('app:info'),
getPrefs: () => ipcRenderer.invoke('prefs:get'),
setPrefs: (partial) => ipcRenderer.invoke('prefs:set', partial),
exportIdentity: () => ipcRenderer.invoke('identity:export'),
importIdentity: () => ipcRenderer.invoke('identity:import'),
copyText: (text) => ipcRenderer.invoke('clipboard:write', text),
openLogs: () => ipcRenderer.invoke('app:open-logs'),
fetchExternalMedia: (url) => ipcRenderer.invoke('media:external', url),
getVideoStatus: () => ipcRenderer.invoke('app:video-status'),
relaunch: () => ipcRenderer.invoke('app:relaunch'),
log: (level, message) => ipcRenderer.send('app:log', level, String(message)),
});