@dcefram/xjs
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

WARNING: This is still very much a work-in-progress!

XJS Framework

The XSplit JS Framework allows developers to create plugins for XSplit Broadcaster.

This branch is the proposed next version of XJS Framework. Further documentation will be done down the line.

Remote

import XJS from 'xjs';
import { XjsTypes } from 'xjs/core/xjs/types';

// Establish connection
const Connection = () => {
  return new Promise(resolve => {
    if (RTCPeerConnection !== undefined) {
      const rtc = new RTCPeerConnection();

      rtc.ondatachannel = channel => {
        resolve(channel);
      };

      return;
    }

    const ws = new WebSocket('ws://localhost:9999');

    return resolve(ws);
  });
};

(async () => {
  // PROXY using RTC
  const conn = (await Connection()) as RTCDataChannel;

  conn.addEventListener('open', d => {
    const xjs = new XJS({
      type: XjsTypes.Proxy,
      sendMessage: conn.send.bind(conn),
    });

    conn.addEventListener('message', ({ data: message }) => {
      xjs.remote.receiveMessage(message);
    });
  });
})();

(async () => {
  // PROXY using WebSocket
  const conn = (await Connection()) as WebSocket;

  conn.addEventListener('open', d => {
    const xjs = new XJS({
      type: XjsTypes.Proxy,
      sendMessage: conn.send.bind(conn),
    });

    conn.addEventListener('message', ({ data: message }) => {
      xjs.remote.receiveMessage(message);
    });
  });
})();

(async () => {
  // REMOTE using WebSocket
  const conn = (await Connection()) as RTCDataChannel;

  conn.addEventListener('open', d => {
    const xjs = new XJS({
      type: XjsTypes.Remote,
      sendMessage: conn.send.bind(conn),
    });

    conn.addEventListener('message', ({ data: message }) => {
      xjs.remote.receiveMessage(message);
    });
  });
})();

(async () => {
  // REMOTE using WebSocket
  const conn = (await Connection()) as WebSocket;

  conn.addEventListener('open', d => {
    const xjs = new XJS({
      type: XjsTypes.Remote,
      sendMessage: conn.send.bind(conn),
    });

    conn.addEventListener('message', ({ data: message }) => {
      xjs.remote.receiveMessage(message);
    });
  });
})();

Readme

Keywords

Package Sidebar

Install

npm i @dcefram/xjs

Weekly Downloads

1

Version

0.2.4

License

SEE LICENSE IN LICENSE

Unpacked Size

91.1 kB

Total Files

102

Last publish

Collaborators

  • dcefram