How to use peerjs - 10 common examples

To help you get started, we’ve selected a few peerjs 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 gxchain / gxchain-light / web / app / components / Chat / Chat.jsx View on Github external
_connectToServer() {
        this._peer = new Peer(hostConfig);

        this._peer.on("open", id => {
            // console.log("open, my ID is:", id);
            this._myID = id;
            this.setState({
                connected: true,
                loading: false,
                open: true
            });

            this._peer.listAllPeers(this._connectToPeers.bind(this, true));
        });

        this._peer.on("connection", this.onConnection.bind(this));
        // this._peer.on('disconnect', this.onDisconnect.bind(this));
github bitshares / bitshares-ui / web / app / components / Chat / Chat.jsx View on Github external
_connectToServer() {
        this._peer = new Peer(hostConfig);

        this._peer.on("open", id => {
            // console.log("open, my ID is:", id);
            this._myID = id;
            this.setState({
                connected: true,
                loading: false,
                open: true
            });

            this._peer.listAllPeers(this._connectToPeers.bind(this, true));
        });

        this._peer.on("connection", this.onConnection.bind(this));
        // this._peer.on('disconnect', this.onDisconnect.bind(this));
github ByronHsu / Never-Blink / src / app.jsx View on Github external
constructor(props) {
    super();
    this.props = props;

    // Create client id.
    this.id = uuidv4();

    // Create peer and socket to communicate.
    this.peer = new Peer(this.id);
    this.socket = io(document.URL, { query: { id: this.id } });

    // Function bind.
    this.handleOnClick = this.handleOnClick.bind(this);
    this.onUnload = this.onUnload.bind(this);

    // Define state and other member variable.
    this.state = {
      isPlaying: 0,
      role: '',
      rivalId: '',
      connectToggle: false
    };
    this.rivalId = '';

    console.log('id', this.id);
github kumavis / node-warrior / src / js / util / rtc_utils.js View on Github external
function RtcConnection(id) {
  var rtc = new Peer(id,{key: __ApiKey})
  rtc.on('open', function(id) { console.log('>> opened, got id:',id) })
  rtc.on('error', function(err) { console.log('>> had error:'); throw err })
  rtc.on('close', function() { console.log('>> closed') })
  rtc.on('connection', function(dataConnection) {
    console.log('>> got connection')
    // connection open
    dataConnection.on('open',function() {
      dataConnectionHasOpened(rtc,dataConnection)
    })
  })
  return rtc
}
github DecenterApps / MatchChannels / etherships / src / services / webrtcService.js View on Github external
export const createPeer = (peerId) => {
  try {
    peer = new Peer(peerId, {
      key: WEBRTC_API_KEY,
      debug: 3,
      host: WEBRTC_SERVER,
      port: WEBRTC_PORT,
      secure: true,
      config: {
        'iceServers': [
          {url:'stun:stun01.sipphone.com'},
          {url:'stun:stun.ekiga.net'},
          {url:'stun:stun.fwdnet.net'},
          {url:'stun:stun.ideasip.com'},
          {url:'stun:stun.iptel.org'},
          {url:'stun:stun.rixtelecom.se'},
          {url:'stun:stun.schlund.de'},
          {url:'stun:stun.l.google.com:19302'},
          {url:'stun:stun1.l.google.com:19302'},
github kern / filepizza / client / stores / PeerStore.js View on Github external
import Peer from 'peerjs';
import PeerActions from '../actions/PeerActions';
import alt from '../alt';
import uuid from 'node-uuid';

let id = uuid.v4();
let peer = new Peer(id, {
  host: window.location.hostname,
  port: window.location.port,
  path: '/peer'
});

peer.on('connection', (conn) => {
  PeerActions.peerConnected(conn);
});

export default alt.createStore(class PeerStore {

  static connect(peerID, metadata) {
    return peer.connect(peerID, {
      reliable: true,
      metadata: metadata
    });
github oysterprotocol / webnode / webnode / src / redux / services / peer.js View on Github external
const init = () => {
  const randomClient = Math.random()
    .toString(36)
    .replace(/[^a-z]+/g, "")
    .substr(0, 8);
  const peer = new Peer(randomClient, {
    host: PEER_HOST,
    port: PEER_PORT,
    path: PEER_PATH,
    debug: PEER_DEBUG
  });
  return peer;
};
github DecenterApps / MatchChannels / library / src / App.vue View on Github external
async host() {
    await this.openChannel();
    playerType = 1;

    peer = new Peer('abc', {
      key: 'asdf',
      debug: 3,
      host: '139.59.146.81',
      port: 9000,
    });

    peer.on('connection', function(_conn) {
      this.showGame = true;
      conn = _conn;
      conn.on('data', this.msgReceived);
    }.bind(this));
  }
}
github agneym / json-formatter / src / components / App.js View on Github external
useEffect(() => {
    const params = new URLSearchParams(window.location.search);
    const userLink = params.get("q");
    if (userLink) {
      const peer = new Peer();
      const connection = peer.connect(userLink);
      connection.on("open", () => {
        connection.on("data", value => {
          editorConfig.setValue(value);
        });
      });
    }
  }, [editorConfig]);
  useEffect(() => {
github conclave-team / conclave / lib / userBot.js View on Github external
constructor(peerId, targetPeerId, script, mde) {
    this.siteId = 'bot-1';
    this.peer = new Peer(peerId, {
  			host: location.hostname,
  			port: location.port || (location.protocol === 'https:' ? 443 : 80),
  			path: '/peerjs',
  			debug: 3
  		});
    this.vector = new VersionVector(this.siteId);
    this.crdt = new CRDT(this);
    this.buffer = [];
    this.mde = mde;
    this.script = script;

    this.connectToUser(targetPeerId);
    this.onConnection();
  }

peerjs

PeerJS client

MIT
Latest version published 4 months ago

Package Health Score

81 / 100
Full package analysis