我需要一个多窗口应用程序来共享媒体流。无论如何有这样做吗?在NW.JS中,我可以创建一个概念证明,其中可以在一个窗口中创建的介质流,但它可以在另一个窗口中播放,但是它可以

问题描述 投票:0回答:3
电子per-connection

库(实际上使过程变得非常容易)。 不幸的是,如果您采用这种方法,则有一个限制的限制(WEBRTC会以有损的压缩来压缩您的音频,您将有一个很大的延迟,当前电子错误会导致音频变成单声道,事物,事物,事物这样)

因此,这对语音之类的东西很好,但对于例如高端本机质音频处理。
electron
3个回答
1
投票
aadditionally,如果您的应用程序不是具有疯狂性能要求的怪兽野兽,则您还可以使用Web Audio API和ScriptProcessornode(电子中仍然不可用AudiOworklet)直接从MediaStream访问音频示例数据,并与该数据一起发送,并将其发送给该数据。标准电子IPC.

然后,您可以使用Web Audio API和MediaStreamDestinationnode在另一个窗口过程中重建MediaStream。 我也面临同一问题,并尝试了几乎所有方法。一种方法是在电子中使用本机窗口,并在react中创建一个门户网站并在其中打开一个带有window.open()的本机窗口,这将为我们提供一个没有浏览器的电子窗口,使用browserwindow功能,将本机窗口转换为浏览器窗口,我发现这样做的唯一方法是在“新窗口”中的新guest活动中,这是不弃用的,而没有新的Gunguest事件但它可以在22以下的版本中起作用。

mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => { // This is the name we chose for our window. You can have multiple names for // multiple windows and each have their options if (frameName === 'NewWindowComponent ') { event.preventDefault(); Object.assign(options, { // This will prevent interactions with the mainWindow parent: mainWindow, width: 300, height: 300, // You can also set left and top positions }); event.newGuest = new BrowserWindow(options); let newWindow = event.newGuest } });


现在您可以作为浏览器访问newwindow,这将起作用。

@Johnweisz答案中提到的WebRTC的限制在

2025

0
投票
,可能会完成这项工作。

电子peer-connection

包的感兴趣,但面临其限制,特别是在电子中的IPC安全性(

here
Here
)中,
I创建了一个软件包,以在Windows之间发送和接收非常非常低潜伏期
。您可以在这里找到它:
电子 - 窗口 - rtc

.

。 在编写版本的时间为

1.0.7

。未来版本可能会在窗口之间实现通过原始音频,但是暂时可以通过运行提供的示例来看到性能。

0
投票
main过程

通过致电:注册窗口: // WindowRTCMain is a singleton. import { WindowRTCMain } from 'electron-window-rtc'; const senderWindow: BrowserWindow = createWindow(); const receiverWindow: BrowserWindow = createWindow(); // Note that windows can both send and receive, it's up to the application to manage sent/received streams. WindowRTCMain.register('sender', senderWindow); WindowRTCMain.register('receiver', receiverWindow);

rendererprocess

Receiver import { WindowRTCPeerConnection, defineIpc, } from 'electron-window-rtc/renderer'; // Important: define early how to access to IPC object, according to application 'preload' script. // The IPC object must at least expose `on`, `removeListener`, `send` and `invoke` methods (see IPCObject below). defineIpc(window.electron.ipcRenderer); document.addEventListener('DOMContentLoaded', (event) => { // Connect to window named 'receiver'. const windowConnection = new WindowRTCPeerConnection('receiver'); // Canvas for example... const canvas: HTMLCanvasElement = document.getElementById('canvas'); // Add track from canvas: this will create an 'offer' for 'receiver' window. // Note the '240' fps framerate: leaving it empty creates latency in the receiver. windowConnection.addStream(canvas.captureStream(240)); }); sender import { WindowRTCPeerConnection, defineIpc, } from 'electron-window-rtc/renderer'; defineIpc(window.electron.ipcRenderer); document.addEventListener('DOMContentLoaded', (event) => { const windowConnection = new WindowRTCPeerConnection('sender'); // Listen to 'track' added by 'sender' window. windowConnection.on('track', (event: EventManagerDTO) => { const video: HTMLVideoElement = document.getElementById('video'); const trackEvent: RTCTrackEvent = event.payload; const streams = trackEvent.streams; for (const stream of streams) { // For the sake of this example, keep only one stream, we could also get `streams[0]`. video.srcObject = null; video.srcObject = stream; } }); });

audio

对于音频,您可以在SenderWindow.vue

ReceiverWindow.vue

文件中找到一个示例。它在“接收器”中可视化的“发送者”窗口中创建一个带有周期波的振荡器。

    

您应该能够通过

WebAudio通过ipc module

发出事件并在Windows中添加
main process
来在Windows之间进行通信。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.