🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

webrtc-firebase

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webrtc-firebase

wrapper over WebRTC with signaling based on firebase realtime database

1.0.6
latest
Source
npm
Version published
Weekly downloads
18
350%
Maintainers
2
Weekly downloads
 
Created
Source

WebRTC-firebase

wrapper over WebRTC with signaling based on firebase realtime database

To use this you need firebase api key, which you can get by creating a firebase project. here

This package currently supports data-channel for

  • p2p
  • client hosted room

which will look something like this

const firebaseConfig = {
    apiKey: "***************************************",
    authDomain: "<project-id>.firebaseapp.com",
    projectId: "<project-id>",
    storageBucket: "<project-id>.appspot.com",
    messagingSenderId: "************",
    appId: "<api-id>",
    measurementId: "*-**********"
};

##API

  • RoomHost
  • Host
  • Guest

##User Guide

Globally install documentation using the npm package manager:

$ npm install -g webrtc-firebase

Sample code

import wf from 'webrtc-firebase';

const firebaseConfig = {
    apiKey: "***************************************",
    authDomain: "<project-id>.firebaseapp.com",
    projectId: "<project-id>",
    storageBucket: "<project-id>.appspot.com",
    messagingSenderId: "************",
    appId: "<api-id>",
    measurementId: "*-**********"
};

const channelName = ['channel1', 'channel2'];
let rtc;
const key = getURLParam('key');

if(key){
    rtc = new wf.Guest(key, firebaseConfig, channelName ,onConnectionSuccess, onSessionStateChange );
}else{
    const channelsConfig = [{name: 'channel1', type: 'data'}, {name: 'channel1', type: 'data'}];

    // use RoomHost instead of Host here for a group communication
    rtc = new wf.Host(firebaseConfig, channelsConfig , onKeyGenerated);
}

// on connection success to get data-channels use
const channel1 = rtc.getChannel('channel1');


--- utils.js
export const getURLParam = (param) => {
    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    return urlParams.get(param)
}

export function insertParam(key, value) {
    if (window.history.pushState) {
        var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + `?${key}=${value}`;
        window.history.pushState({ path: newurl }, '', newurl);
    }
}

export const onKeyGenerated = (key) => {
        insertParam('key', key);
    });

export const onConnectionSuccess = () => {
    console.log('connection successed');
}

this code generates a room url which u can share with whome you want to connect.

RoomHost

room host takes an other parameter, which we call ActivityManager, its like a server to this room and you can read or modify message before broadcasting them.

Keywords

webRTC

FAQs

Package last updated on 13 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts