electron#webFrame JavaScript Examples

The following examples show how to use electron#webFrame. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: webRTC.js    From vupc with MIT License 5 votes vote down vote up
export async function createOffer(screenID) {
  try {
    const stream = await getStreamFromScreen(screenID);
    const peerConfig = {
      initiator: true,
      trickle: false,
      stream,
      // sdpTransform: setBandwidth,
      config: {
        iceServers: [{ urls: "stun:stun.l.google.com:19302" }],
      },
    };
    const p = new Peer(peerConfig);
    waitAnswerSignal((answer) => p.signal(answer));

    // Return observer for listen connection events
    const facade = {
      onConnect(callback) {
        p.on("connect", callback);
      },
      onClose(callback) {
        p.on("close", callback);
      },
      onData(callback) {
        p.on("data", (data) => {
          // TODO improve system events
          const dataParsed = JSON.parse(data.toString("utf8"));
          if (dataParsed.click) {
            const { x, y } = dataParsed;
            const {
              availWidth: width,
              availHeight: height,
            } = webFrame.context.screen;
            const size = {
              width,
              height,
            };
            mouseClickEvent(transformFromPercentToPixels(x, y, size));
          } else {
            callback(dataParsed);
          }
        });
      },
      onCode(callback) {
        // Listen signaling events
        p.on("signal", async (data) => {
          if (data.type === "offer") {
            const code = await generateOfferCode(data);
            callback(code);
          }
        });
      },
      disconnect() {
        p.destroy();
      },
    };

    return facade;
  } catch (error) {
    throw new Error(error);
  }
}