How to use the simple-peer.WEBRTC_SUPPORT function in simple-peer

To help you get started, we’ve selected a few simple-peer 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 kalm / kalm.js / packages / webrtc / src / webrtc.ts View on Github external
/* Requires ------------------------------------------------------------------*/

import Peer from 'simple-peer';

if (!Peer.WEBRTC_SUPPORT) {
  throw new Error('Unsupported environement for WebRTC');
}

/* Methods -------------------------------------------------------------------*/

function webrtc(config: WebRTCConfig = {}): KalmTransport {
  return function socket(params: ClientConfig, emitter: EventEmitter): Socket {
    let listener;

    function bind(): void {
      listener = new Peer();
      listener.on('connect', soc => emitter.emit('socket', soc));
      listener.on('error', err => emitter.emit('error', err));
      emitter.emit('ready');
    }
github webtorrent / webtorrent / index.js View on Github external
// Sometimes server.address() returns `null` in Docker.
      const address = this._tcpPool.server.address()
      if (address) this.torrentPort = address.port
    }

    this.emit('listening')
  }

  _debug () {
    const args = [].slice.call(arguments)
    args[0] = `[${this._debugId}] ${args[0]}`
    debug(...args)
  }
}

WebTorrent.WEBRTC_SUPPORT = Peer.WEBRTC_SUPPORT
WebTorrent.VERSION = VERSION

/**
 * Check if `obj` is a node Readable stream
 * @param  {*} obj
 * @return {boolean}
 */
function isReadable (obj) {
  return typeof obj === 'object' && obj != null && typeof obj.pipe === 'function'
}

/**
 * Check if `obj` is a W3C `FileList` object
 * @param  {*} obj
 * @return {boolean}
 */
github webtorrent / bittorrent-tracker / client.js View on Github external
let announce = typeof opts.announce === 'string'
      ? [opts.announce]
      : opts.announce == null ? [] : opts.announce

    // Remove trailing slash from trackers to catch duplicates
    announce = announce.map(announceUrl => {
      announceUrl = announceUrl.toString()
      if (announceUrl[announceUrl.length - 1] === '/') {
        announceUrl = announceUrl.substring(0, announceUrl.length - 1)
      }
      return announceUrl
    })
    announce = uniq(announce)

    const webrtcSupport = this._wrtc !== false && (!!this._wrtc || Peer.WEBRTC_SUPPORT)

    const nextTickWarn = err => {
      process.nextTick(() => {
        this.emit('warning', err)
      })
    }

    this._trackers = announce
      .map(announceUrl => {
        let parsedUrl
        try {
          parsedUrl = new URL(announceUrl)
        } catch (err) {
          nextTickWarn(new Error(`Invalid tracker URL: ${announceUrl}`))
          return null
        }
github rynobax / jump-game / src / App.js View on Github external
constructor(){
    super();
    if(Peer.WEBRTC_SUPPORT){ // test for webrtc support
      this.state = {
        role: 'visitor'
      };
    } else {
      this.state = {
        role: 'unsupported',
        playingGame: false
      };
    }
  }
github PearInc / PearDownloader.js / src / pear-torrent.js View on Github external
if (err) return self.error('Failed to load blocklist: ' + err.message)
      self.blocked = ipSet
      ready()
    })
  } else {
    process.nextTick(ready)
  }

  function ready () {
    if (self.destroyed) return
    self.ready = true
    self.emit('ready')
  }
}

WebTorrent.WEBRTC_SUPPORT = Peer.WEBRTC_SUPPORT

Object.defineProperty(WebTorrent.prototype, 'downloadSpeed', {
  get: function () { return this._downloadSpeed() }
})

Object.defineProperty(WebTorrent.prototype, 'uploadSpeed', {
  get: function () { return this._uploadSpeed() }
})

Object.defineProperty(WebTorrent.prototype, 'progress', {
  get: function () {
    var torrents = this.torrents.filter(function (torrent) {
      return torrent.progress !== 1
    })
    var downloaded = torrents.reduce(function (total, torrent) {
      return total + torrent.downloaded
github fastcast / fastcast / client / seed.js View on Github external
var dragDrop = require('drag-drop')
var uploadElement = require('upload-element')
var path = require('path')
var Peer = require('simple-peer')
var prettyBytes = require('pretty-bytes')
var WebTorrent = require('webtorrent')

var util = require('./util')

global.WEBTORRENT_ANNOUNCE = [ 'ws://tracker.fastcast.nz' ]

if (!Peer.WEBRTC_SUPPORT) {
  util.error('Sorry, your browser is unsupported. Please try again using Chrome.')
}

var client = new WebTorrent()

var upload = document.querySelector('input[name=upload]')
uploadElement(upload, function (err, files) {
  if (err) return util.error(err)
  files = files.map(function (file) { return file.file })
  onFiles(files)
})

dragDrop('body', onFiles)

function onFiles (files) {
  client.seed(files, onTorrent)
github fastcast / fastcast / client / stream-magnet.js View on Github external
var path = require('path')
var Peer = require('simple-peer')
var prettyBytes = require('pretty-bytes')
var WebTorrent = require('webtorrent')

var util = require('./util')

global.WEBTORRENT_ANNOUNCE = [ 'wss://tracker.fastcast.nz' ]

if (!Peer.WEBRTC_SUPPORT) {
  util.error('Sorry, your browser is unsupported. Please try again using Chrome.')
}

var client = new WebTorrent()

client.add(magnetUri, onTorrent)

function onTorrent (torrent) {
  var torrentFileName = path.basename(torrent.name, path.extname(torrent.name)) + '.torrent'

  util.log(
    '<a role="button" href="' + torrent.magnetURI + '" class="btn btn-primary btn-xs"><i class="fa fa-magnet"></i> Magnet URI</a> ' +
    '<a role="button" download="' + torrentFileName + '" href="' + torrent.torrentFileBlobURL + '" class="btn btn-primary btn-xs"><i class="fa fa-download"></i> Download .torrent</a> ' +
    '<a role="button" class="btn btn-primary btn-xs" id="downloadButton"><i class="fa fa-download"></i> Download ' + torrent.name + '</a>'
  )
github feross / whiteboard / client / index.js View on Github external
var debug = require('debug')
var dragDrop = require('drag-drop')
var hat = require('hat')
var path = require('path')
var Peer = require('simple-peer')
var thunky = require('thunky')
var Tracker = require('bittorrent-tracker/client')
var videostream = require('videostream')
var WebTorrent = require('webtorrent')
var xhr = require('xhr')

var TRACKER_URL = 'wss://tracker.fastcast.nz'

global.WEBTORRENT_ANNOUNCE = [ TRACKER_URL ]

if (!Peer.WEBRTC_SUPPORT) {
  window.alert('This browser is unsupported. Please use a browser with WebRTC support.')
}

var getClient = thunky(function (cb) {
  xhr('http://localhost:9100/rtcConfig', function (err, res) {
    var rtcConfig
    if (err || res.statusCode !== 200) {
      window.alert('Could not get WebRTC config from server. Using default (without TURN).')
    } else {
      try {
        rtcConfig = JSON.parse(res.body)
      } catch (err) {
        window.alert('Got invalid WebRTC config from server: ' + res.body)
      }
      if (rtcConfig) debug('got rtc config: %o', rtcConfig)
    }
github gundb / gun-rtc / src / index.js View on Github external
Gun.on('opt').event(function (gun, opt) {
	opt = opt || {};
	var support, browser, wire, rtc = opt.rtc;
	support = SimplePeer.WEBRTC_SUPPORT;
	browser = typeof window !== 'undefined';
	
	if (rtc === false || (!support && browser)) {
		return;
	}

	if (!peers.db) {

		peers.db = new Gun({
			peers: gun.__.opt.peers,
			rtc: false
		}).get({
			'#': 'GUN_RTC_PEERS_SETUP',
			'>': {
				'>': new Date().getTime()
			}
github jhiesey / peercloud / client / index.js View on Github external
var debug = require('debug')('peercloud.io')
var mime = require('mime')
var Peer = require('simple-peer')
var thunky = require('thunky')
var WebTorrent = require('webtorrent')
var xhr = require('xhr')

var TRACKER_URL = 'wss://tracker.webtorrent.io'

global.WEBTORRENT_ANNOUNCE = [ TRACKER_URL ]

if (!Peer.WEBRTC_SUPPORT || !navigator.serviceWorker) {
	alert('This browser is unsupported. Please use a browser with WebRTC support and ServiceWorker support.')
	return;
}

var locationField = document.getElementById('location')
var goButton = document.getElementById('go-button')

goButton.addEventListener('click', function () {
	loadPage(locationField.value)
})

function syncLocation (firstLoad) {
	if (location.hash) {
		locationField.value = location.hash.substr(1)
	} else if (!firstLoad) {
		locationField.value = ''

simple-peer

Simple one-to-one WebRTC video/voice and data channels

MIT
Latest version published 3 years ago

Package Health Score

64 / 100
Full package analysis