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

webphone-plugin

v0.2.1

Published

This project integrates the `webphone-plugin` to provide VoIP functionality using `Jssip`. Below you'll find instructions on how to configure and use the plugin in your React application.

Downloads

10

Readme

WebPhone Plugin Setup with Jssip

This project integrates the webphone-plugin to provide VoIP functionality using Jssip. Below you'll find instructions on how to configure and use the plugin in your React application.

Installation

Install the required webphone-plugin dependency:

npm install webphone-plugin

Configuration

To initialize the WebPhone Plugin, you'll need to configure the required settings. These settings will be passed to the Jssip component through a _config object, which is a Map containing key-value pairs for various parameters.

Example Configuration

const _config = new Map([
  ["extension", "xxxx"], // SIP extension
  // ['turn_username', 'xxxx:xxxx'],    // Optional TURN username
  // ['turn_password', 'xxxx='],        // Optional TURN password
  ["stun_url", "stun:stun.l.google.com:19302"], // STUN server URL for NAT traversal
  // ['turn_url', 'xxxx'],              // Optional TURN server URL
  ["domain", "xxxx"], // SIP domain
  ["password", "xxxxxxxx"], // SIP account password
  ["name", "xxxx"], // Display name for the caller
  ["wss_url", "wss://xxxx"], // WebSocket URL for SIP signaling
  ["via_transport", "WSS"], // Transport protocol (WebSocket Secure)
  ["logs", false], // Enable or disable logs
  ["callerID", "xxxx"], // Caller ID to display
  ["turn_policy", "xxxx"], // TURN server policy (if applicable)
]);

Configuration Parameters

  • extension: Your SIP extension (e.g., 1001).
  • stun_url: The STUN server URL, used for NAT traversal.
  • domain: The SIP domain or server.
  • password: Your SIP account password.
  • name: Display name of the caller.
  • wss_url: WebSocket Secure URL for SIP signaling.
  • via_transport: Transport protocol for SIP (WSS for WebSocket Secure).
  • logs: Boolean flag to enable or disable logging.
  • callerID: The Caller ID to use during calls.
  • turn_policy: Optional TURN server policy (e.g., "mandatory" or "optional").

Note: TURN servers can be configured for enhanced NAT traversal, but they are commented out in the configuration. Uncomment and fill in these parameters if TURN is required for your setup.

Usage

The Jssip component from webphone-plugin is a render prop component. It takes _config as a prop and provides various methods and states to control VoIP functionality.

Basic Usage Example

import React from "react";
import Jssip from "webphone-plugin";

const App = () => {
  const _config = new Map([
    ["extension", "1001"],
    ["stun_url", "stun:stun.l.google.com:19302"],
    ["domain", "your.sipdomain.com"],
    ["password", "yourpassword"],
    ["name", "Your Name"],
    ["wss_url", "wss://your.sipdomain.com:8089/ws"],
    ["via_transport", "WSS"],
    ["logs", false],
    ["callerID", "YourCallerID"],
    ["turn_policy", "optional"],
  ]);

  return (
    <Jssip _config={_config}>
      {(_data) => {
        const {
          _makeCall,
          _setNumber,
          _toggleHold,
          _answerCall,
          _terminate,
          _muteCall,
          _sendDtmf,
          _referUser,
          _passInfo,
          _start,
          _stop,
          _attendedTransfer,
          _speakerOff,
          _speakerOn,
          _nbTerminate,
        } = _data;

        const {
          _status,
          _number,
          _uaSessions,
          _uiSessions,
          _ring,
          _total,
          _speakers,
        } = _data;

        return (
          <div>
            <h1>VoIP WebPhone</h1>

            {/* Display current phone status */}
            <p>Status: {_status}</p>

            {/* Set the number to call */}
            <input
              type="text"
              placeholder="Enter Number"
              onChange={(e) => _setNumber(e.target.value)}
            />

            {/* Make a call */}
            <button onClick={() => _makeCall()}>Make Call</button>

            {/* Answer an incoming call */}
            <button onClick={() => _answerCall()}>Answer Call</button>

            {/* End an ongoing call */}
            <button onClick={() => _terminate()}>End Call</button>

            {/* Additional features */}
            <button onClick={() => _muteCall(true)}>Mute</button>
            <button onClick={() => _muteCall(false)}>Unmute</button>
            <button onClick={() => _toggleHold()}>Hold/Resume Call</button>
            <button onClick={() => _sendDtmf("1")}>Send DTMF (1)</button>
            <button onClick={() => _speakerOn()}>Speaker On</button>
            <button onClick={() => _speakerOff()}>Speaker Off</button>
          </div>
        );
      }}
    </Jssip>
  );
};

export default App;

Available Methods

The Jssip component provides the following methods via the _data object:

  • _makeCall: Initiates a call to the number set in _setNumber.
  • _setNumber: Sets the number to be called.
  • _toggleHold: Toggles the hold status of the current call based on uuid.
  • _answerCall: Answers an incoming call.
  • _terminate: Terminates an ongoing call based on uuid.
  • _muteCall: Mutes/unmutes the microphone (_muteCall(true) to mute, _muteCall(false) to unmute).
  • _sendDtmf: Sends DTMF tones (e.g., _sendDtmf('1')).
  • _referUser: Transfers the call to another user.
  • _passInfo: Sends in-call information.
  • _start: Starts the web phone service.
  • _stop: Stops the web phone service.
  • _attendedTransfer: Attends to a transfer.
  • _speakerOff: Turns off the speakerphone.
  • _speakerOn: Turns on the speakerphone.
  • _nbTerminate: Terminates the session based on number.

Available State Variables

The component also provides various states, including:

  • _status: The current status of the call (e.g., "ringing", "connected").
  • _number: The phone number currently set.
  • _uaSessions: User agent sessions object.
  • _uiSessions: UI sessions object.
  • _ring: Status of the phone ringer.
  • _total: Total number of active sessions.
  • _speakers: List of active speakers.