增加 Windows 与 Web 端到端加密群语音
This commit is contained in:
1 parent
9c84b38fd9
commit
de722039d6
8 files changed
+125
-16
No files matched your search
+10
-2
@@ -77,9 +77,14 @@ async function start() {
|
||||
frame.url.split('#')[0] === appURL
|
||||
}
|
||||
let microphoneUntil = 0
|
||||
let microphonePage = ''
|
||||
function recordingPage(url: string) {
|
||||
if (!url.startsWith(appURL)) return false
|
||||
return /^#\/(chat|groups)\/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/.test(url.slice(appURL.length))
|
||||
}
|
||||
function voicePermission(contents: Electron.WebContents | null, url: string, mainFrame: boolean, permission: string, types: string[]) {
|
||||
return !win.isDestroyed() && contents === win.webContents && mainFrame &&
|
||||
url.split('#')[0] === appURL && win.webContents.getURL().startsWith(appURL + '#/chat/') &&
|
||||
url.split('#')[0] === appURL && win.webContents.getURL() === microphonePage &&
|
||||
Date.now() <= microphoneUntil && permission === 'media' && types.length === 1 && types[0] === 'audio'
|
||||
}
|
||||
trusted.setPermissionCheckHandler((contents, permission, _origin, details) =>
|
||||
@@ -89,13 +94,16 @@ async function start() {
|
||||
callback(voicePermission(contents, details.requestingUrl, details.isMainFrame, permission,
|
||||
'mediaTypes' in details ? details.mediaTypes ?? [] : [])))
|
||||
ipcMain.handle('voice:allow', (event) => {
|
||||
if (!trustedSender(event) || !event.senderFrame?.url.startsWith(appURL + '#/chat/')) {
|
||||
const page = event.senderFrame?.url ?? ''
|
||||
if (!trustedSender(event) || !recordingPage(page)) {
|
||||
throw new Error('录音请求来源无效')
|
||||
}
|
||||
microphonePage = page
|
||||
microphoneUntil = Date.now() + 30_000
|
||||
})
|
||||
ipcMain.handle('voice:end', (event) => {
|
||||
if (!trustedSender(event)) throw new Error('录音请求来源无效')
|
||||
microphonePage = ''
|
||||
microphoneUntil = 0
|
||||
})
|
||||
ipcMain.handle('device:sign', (event, username: unknown, challenge: unknown) => {
|
||||
|
||||
Reference in new issue
Block a user