Previously, I have set up a RTCPeerConnection between the main jitis-meet window and the micro window for the video transmission.
However, it hard coded a lot of stuffs and honestly speaking, the code design was a total mess. There were both main window side’s code and micro window side’s code in one page, so it was vulnerable to unintended global variables usage and namespace conflicts. I decided to refactor the code into OOP-style one, so that it can be used in more general case. It is sort of a wrapper for the webkitRTCPeerConnection, suited for the inter-Electron BrowserWindow communication which does not require a STUN server for signalling.
- windowName: the BrowserWindow’s name in main process
The WindowPeeerConnection wraps around webkitRTCPeerConnection class, which on construction in a renderer process, sets up a IPC listeners that receive message and data from other windows. All the message are relayed through the main process, and data are serialized before transmitted.
- attachStream ( streamToSend ) : attaches a MediaStream object on the peer connection channel, which can be transmitted by sendStream method. Currently, it can only attach one stream per connection.
- removeStream ( ) : removes the MediaStream attached to this peer connection channel.
- sendStream ( receiverName ) : sends the attached MediaStream object to the target window specified the string ‘receiverName’. receiverName refers to the name of the variable assigned to the target BrowserWindow in the Electron’s main process.
- onReceivedStream ( function(receivedStream) ): triggered when the WindowPeerConnection receives a MediaStream from a remote window.
Main Process: Data Relay Channel
window: BrowerWindow object,
name: "BrowserWindow's name"
- initChannel ( ) : initiates the data relay channel with the current array of clients. Clients can be furthered added after the channel is initiated.
Currently, it only supports transmission of MediaStream, but it could be extended to general Data transmission later on. I might be going to publish this code in npm, since I could find anything similar.