npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

callfusion-client

v1.1.1

Published

A WebRTC signaling and peer connection client library

Downloads

7

Readme

CallFusion Library

CallFusion is a WebRTC signaling and peer connection library that simplifies managing video and audio calls using Socket.IO as the signaling server. The library allows users to set up high-quality audio and video calls with flexible media constraints.

Features

  • Easy-to-use API for WebRTC video and audio calls.
  • Socket.IO-based signaling.
  • Customizable media constraints for both video and audio.
  • Integrated handling of client lists and call signaling.

Installation

Install the CallFusion library using npm:

npm install callfusion

General Setup

1. Signaling Server and ICE Configuration

You'll need to configure the signaling server and ICE servers for WebRTC to function properly.

const signalingServer = io("https://test-api.com");

const iceConfiguration = {
  iceServers: [
    ....
  ],
  iceTransportPolicy: "relay",
};

2. Media Constraints

Define your media constraints for video and audio:

let constraints = {
	video: {
		width: { ideal: 1280 },
		height: { ideal: 720 },
		frameRate: { ideal: 30, max: 60 },
		facingMode: "user",
	},
	audio: {
		echoCancellation: true,
		noiseSuppression: true,
		autoGainControl: true,
	},
};

3. Creating the CallFusion Instance

const callFusion = new CallFusion(
	signalingServer,
	iceConfiguration,
	document.getElementById("videoContainer"),
	constraints
);

Using CallFusion in Vanilla JavaScript

You can implement CallFusion in a pure JavaScript application like so:

HTML Example

<div id="videoContainer"></div>
<ul id="clientsList"></ul>
<button id="startVideoButton">Start Video Call</button>
<button id="startVoiceButton">Start Voice Call</button>
<button id="hangupButton">Hang Up</button>

JavaScript Example

document.getElementById("startVideoButton").addEventListener("click", async () => {
	if (!callFusion.getSelectedClientId()) {
		console.log("Please select a client.");
		return;
	}
	await callFusion.startCall(constraints, true); // Video call
});

document.getElementById("hangupButton").addEventListener("click", () => {
	callFusion.hangup();
});

Using CallFusion in React

To use CallFusion in a React component, initialize CallFusion inside a useEffect hook and manage it using React state.

React Example

import React, { useEffect, useRef, useState } from "react";
import { CallFusion } from "callfusion";
import io from "socket.io-client";

const signalingServer = io("https://test-api.com");

const iceConfiguration = {
	iceServers: [
		...
	],
};

const constraints = {
	video: true,
	audio: true,
};

function CallComponent() {
	const videoContainerRef = useRef(null);
	const [callFusion, setCallFusion] = useState(null);

	useEffect(() => {
		const cfInstance = new CallFusion(
			signalingServer,
			iceConfiguration,
			videoContainerRef.current,
			constraints
		);
		setCallFusion(cfInstance);

		return () => {
			cfInstance.hangup(); // Cleanup on unmount
		};
	}, []);

	return (
		<div>
			<div ref={videoContainerRef}></div>
			<button onClick={() => callFusion?.startCall(constraints, true)}>Start Video Call</button>
			<button onClick={() => callFusion?.hangup()}>Hang Up</button>
		</div>
	);
}

export default CallComponent;

Using CallFusion in Vue.js

To use CallFusion in Vue, initialize it in the mounted lifecycle hook.

Vue.js Example

<template>
	<div>
		<div id="videoContainer"></div>
		<button @click="startVideoCall">Start Video Call</button>
		<button @click="hangupCall">Hang Up</button>
	</div>
</template>

<script>
	import { CallFusion } from "callfusion";
	import io from "socket.io-client";

	export default {
		data() {
			return {
				callFusion: null,
			};
		},
		mounted() {
			const signalingServer = io("https://test-api.com");
			const iceConfiguration = {
				iceServers: [
	         ...
	       ],
			};

			const constraints = {
				video: { width: 1280, height: 720 },
				audio: { echoCancellation: true, noiseSuppression: true },
			};

			this.callFusion = new CallFusion(
				signalingServer,
				iceConfiguration,
				document.getElementById("videoContainer"),
				constraints
			);
		},
		methods: {
			startVideoCall() {
				this.callFusion.startCall(this.callFusion.getMediaConstraints(), true);
			},
			hangupCall() {
				this.callFusion.hangup();
			},
		},
	};
</script>

Using CallFusion in Angular

To use CallFusion in Angular, initialize the library in a component's lifecycle hook.

Angular Example

  1. Install the library:

    npm install callfusion
  2. Create the Angular component:

    import { Component, ElementRef, OnInit, ViewChild } from "@angular/core";
    import { CallFusion } from "callfusion";
    import { io } from "socket.io-client";
    
    @Component({
    	selector: "app-video-call",
    	templateUrl: "./video-call.component.html",
    	styleUrls: ["./video-call.component.css"],
    })
    export class VideoCallComponent implements OnInit {
    	@ViewChild("videoContainer") videoContainer!: ElementRef;
    	callFusion!: CallFusion;
    
    	private signalingServer = io("https://test-api.com");
    	private iceConfiguration = {
    		iceServers: [
         ...
       ],
    	};
    	private constraints = {
    		video: true,
    		audio: true,
    	};
    
    	ngOnInit(): void {
    		this.callFusion = new CallFusion(
    			this.signalingServer,
    			this.iceConfiguration,
    			this.videoContainer.nativeElement,
    			this.constraints
    		);
    	}
    
    	startVideoCall() {
    		this.callFusion.startCall(this.constraints, true);
    	}
    
    	hangupCall() {
    		this.callFusion.hangup();
    	}
    }
  3. Template file (video-call.component.html):

    <div #videoContainer></div>
    <button (click)="startVideoCall()">Start Video Call</button>
    <button (click)="hangupCall()">Hang Up</button>

API Reference

  • startCall(constraints: MediaStreamConstraints, isVideoCall: boolean): Starts a video or voice call with the specified media constraints.
  • hangup(): Ends the ongoing call.
  • acceptCall(data: any): Accepts an incoming call.
  • denyCall(data: any): Denies an incoming call.
  • getMediaConstraints(): Retrieves the media constraints used for the call.

Conclusion

The CallFusion library provides an easy way to implement WebRTC-based audio and video calling in various environments, including React, Vue, Angular, and Vanilla JavaScript. By following the steps above, you can integrate real-time communication into your application quickly and efficiently.