How to use the wrtc.RTCPeerConnection function in wrtc

To help you get started, we’ve selected a few wrtc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UWNetworksLab / uProxy-p2p / src / lib / socks / bin / webrtc.ts View on Github external
/// 

import * as node_server from '../node/server';
import * as node_socket from '../node/socket';
import * as session from '../session';

import * as wrtc from 'wrtc';

const SERVER_ADDRESS = '0.0.0.0';
const SERVER_PORT = 9999;

const getter = new wrtc.RTCPeerConnection();
const giver = new wrtc.RTCPeerConnection();

getter.onicecandidate = (event: any) => {
  if (event.candidate) {
    console.info('getter candidate', event.candidate.candidate);
    giver.addIceCandidate(event.candidate);
  }
}
giver.onicecandidate = (event: any) => {
  if (event.candidate) {
    console.info('giver candidate', event.candidate.candidate);
    getter.addIceCandidate(event.candidate);
  }
}

// Create a SocksSession in response to each new datachannel.
// NOTE: because onopen datachannel events don't fire for the
github ShareIt-project / WebP2P.io / dist / WebP2P_require.js View on Github external
function createPeerConnection(sessionID, callbackType, callback)
  {
    var pc = new RTCPeerConnection
    (
      {iceServers: [{url: 'stun:'+stun_server}]},
      {optional: [{DtlsSrtpKeyAgreement: true}]}
    );

    pc.addEventListener('icecandidate', function(event)
    {
      // There's a candidate, ignore it
      if(event.candidate)
        return;

      // There's no candidate, send the full SDP
      var type = this.localDescription.type;
      var sdp  = this.localDescription.sdp;

      if(type == callbackType)
github ShareIt-project / WebP2P.io / dist / WebP2P.js View on Github external
function createPeerConnection(sessionID, callbackType, callback)
  {
    var pc = new RTCPeerConnection
    (
      {iceServers: [{url: 'stun:'+stun_server}]},
      {optional: [{DtlsSrtpKeyAgreement: true}]}
    );

    pc.addEventListener('icecandidate', function(event)
    {
      // There's a candidate, ignore it
      if(event.candidate)
        return;

      // There's no candidate, send the full SDP
      var type = this.localDescription.type;
      var sdp  = this.localDescription.sdp;

      if(type == callbackType)
github local-group-games / web-udp / lib / server.js View on Github external
value: function _addPeer(id) {
        var _this2 = this;

        if (this._peers[id]) {
          throw new Error(
            "RTCPeer with id " + id + " already exists."
          );
        }

        var peer = new RTCPeer({
          pc: new wrtc.RTCPeerConnection(RTC_PEER_CONNECTION_OPTIONS),
          onChannel: this._onPeerChannel,
          onClose: function onClose() {
            return _this2._onPeerClose(id);
          },
          onSDP: function onSDP(sdp) {
            return _this2._onPeerSDP(sdp, id);
          },
          onICE: function onICE(ice) {
            return _this2._onPeerICE(ice, id);
          }
        });

        this._peers[id] = peer;

        return peer;
      }
github noia-network / webrtc-direct / server / src / webrtc-direct.ts View on Github external
private postChannels(req: express.Request, res: express.Response): void {
        const isUDP = (candidate: wrtc.IceCandidate): boolean => {
            if (typeof candidate.candidate !== "string") {
                throw new Error("Invalid candidate.");
            }

            return candidate.candidate.includes("udp");
        };

        const pc1 = new wrtc.RTCPeerConnection();

        pc1.onerror = (error: ErrorEvent) => {
            logger.error(`${LOG_PREFIX} ${chalk.red("error")}`, error);
        };
        pc1.onnegotationneeded = (event: Event) => {
            logger.verbose(`${LOG_PREFIX} ${chalk.yellow("negotation-needed")}`, event);
        };
        pc1.onicecandidateerror = (event: Event) => {
            logger.error(`${LOG_PREFIX} ${chalk.yellow("ice-candidate-error")}`, event);
        };
        pc1.onsignalingstatechange = (event: Event) => {
            logger.verbose(`${LOG_PREFIX} ${chalk.yellow("signaling-state")}: ${chalk.yellowBright(pc1.signalingState.toString())}`);
        };
        pc1.oniceconnectionstatechange = (event: Event) => {
            logger.verbose(
                `${LOG_PREFIX} ${chalk.yellow("ice-connection-state")}: ${chalk.yellowBright(pc1.iceConnectionState.toString())}`
github local-group-games / web-udp / packages / client / src / provider / web-rtc / rtc-connection-provider.ts View on Github external
private addPeer(pid: string) {
    if (this.peers[pid]) {
      throw new Error(`RTCPeer with id ${pid} already exists.`)
    }

    const peerOptions = {
      onChannel: this.onPeerChannel,
      onClose: () => this.onPeerClose(pid),
      onICE: (ice: RTCIceCandidate) => this.onPeerICE(ice, pid),
      peerConnection: new RTCPeerConnection({
        iceServers: this.iceServers,
        portRange: this.portRange,
      }),
    }
    const peer = new RTCPeer(peerOptions)

    this.peers[pid] = peer

    return peer
  }

wrtc

Standards-compliant WebRTC implementation for Node

BSD-2-Clause
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis