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

@atlasat/webphone-sdk

v1.0.33

Published

![npm](https://img.shields.io/npm/v/@atlasat/webphone-sdk?style=flat-square)

Downloads

351

Readme

Webphone SDK

npm

Example

Connecting and registering

import { Client } from '@atlasat/webphone-sdk';

const account = {
  user: 'accountId',
  password: 'password',
  uri: 'sip:accountId@<realm>',
  name: 'test',
};

const transport = {
  wsServers: '<websocket-url>', // or replace with your
  iceServers: [], // depending on if your provider needs STUN/TURN.
};

const media = {
  input: {
    id: undefined, // default audio device
    audioProcessing: true,
    volume: 1.0,
    muted: false,
  },
  output: {
    id: undefined, // default audio device
    volume: 1.0,
    muted: false,
  },
};

var client = new Client({ type: 'credential', account, transport, media });

//connect to pbx
await client.init().then(() => {
  client.connect();
});

//using token
var client = new Client({ type: 'token', token: '<your token>' });

//disconnect
client.disconnect();

Change the primary I/O devices:

//change input device
client.defaultMedia.input.id = '230988012091820398213';

Incoming call

client.on('invite', function (invitation) {
  console.log('got invitation', invitation);

  if (confirm('new invitation')) {
    //method for accept call
    invitation.accept();
  }

  //method for hold call
  invitation.hold();

  //method for unhold call
  invitation.unhold();

  //method reject if call is not accepted
  invitation.reject();

  //method end call if call is accepted
  invitation.bye();

  //get remote identify
  console.log(invitation.remoteIdentity);

  //event on duration count
  invitation.on('duration', function (duration) {
    console.log('duration', duration);
  });

  //event on status update
  invitation.on('statusUpdate', function (data) {
    console.log('statusUpdate', data);
  });
  //event on terminated
  invitation.on('terminated', function (data) {
    console.log('terminated session', data);
  });
});

Outgoing call

var session = await client.invite('sip:[email protected]');
session.on('accepted', function () {
  //session is accepted
});

session.on('duration', function (duration) {
  console.log('duration: ', duration);
});
session.on('terminated', (session) => {
  console.log('terminated call', session);
});

//method end call after connected or accepted
session.bye();

//method cancel dial
session.cancel();

Sent DTMF

var session = await client.invite('sip:[email protected]');
session.on('accepted', function () {
  session.dtmf('1');
});

Mute unMute mic

var session = await client.invite('sip:[email protected]');
session.on('accepted', function () {
  //mute mic
  session.mute();

  //unmute mic
  session.unmute();
});

Extra header outgoing call

var session = await client.invite(
    'sip:[email protected]',
    { extraHeaders: ['X-Client-Id: 44482'] }
  );
});

Attended transfer of a call

if (await sessionA.accepted()) {
  await sessionA.hold();

  const sessionB = client.invite('sip:201002@<realm>');
  if (await sessionB.accepted()) {
    // immediately transfer after the other party picked up :p
    await client.attendedTransfer(sessionA, sessionB);

    await sessionB.terminate();
  }
}

Blind transfer of a call

if (await session.accepted()) {
  await session.blindTransfer('sip:201001@<realm>');
}

Other method

//get phone number
session.phoneNumber();

//change output volume media
session.media.output.volume = 0.8;

//get output volume media
const volume = session.media.output.volume;

//event when output volume change
session.media.on('outputVolume', (value) => {
  console.log('volume is', value);
});

//set output  media muted
session.media.output.muted = true;

//event when output is mute change
session.media.on('outputMuted', (muted) => {
  console.log('media is', muted);
});

setup media device output

//change output device Id direct
navigator.mediaDevices?.enumerateDevices().then((newDevices) => {
  session.media.output.id = newDevices.filter(
    (device) => device.kind === 'audiooutput',
  )[0].deviceId;
  session.media.output.audio = new Audio();
});

//change output device via method
session.media.setOutput({
  id: deviceId,
  volume: 0.5,
  muted: true,
});

setup media device input

//change input device Id direct
navigator.mediaDevices?.enumerateDevices().then((newDevices) => {
  session.media.input.id = newDevices.filter((device) => device.kind === 'audioinput')[0].deviceId;
});

//change input device via method
session.media.setInput({
  id: deviceId,
  volume: 0.5,
});

media event

session.media.on('outputVolume', (volume) => {
  console.log('new volume', volume);
});

session.media.on('inputVolume', (volume) => {
  console.log('new volume', volume);
});

session.media.on('outputMuted', (muted) => {
  console.log('new output mute', muted);
});

session.media.on('inputMuted', (muted) => {
  console.log('new input mute', muted);
});

get media track input and output

//get media track input
session.media.localStream;

//get media track output
session.media.remoteStream;

//event media stream track add
session.media.localStream.addEventListener('addtrack', (newTrack) => {
  console.log('track added', newTrack);
});

//event media stream track remove
session.media.localStream.addEventListener('removetrack', (oldTrack) => {
  console.log('track remove', oldTrack);
});

using external file

<script src="https://unpkg.com/@atlasat/[email protected]/dist/bundle.min.js"></script>;
//using external file
var client = new webPhone.Client({
  type: 'credential',
  account: {
    user: 'accountId',
    password: 'password',
    uri: 'sip:accountId@<realm>',
    name: 'test',
  },
  transport: {
    wsServers: '<websocket-url>', // or replace with your
    iceServers: [], // depending on if your provider needs STUN/TURN.
  },
});

docs docs

demo page

Demo page visit here.

Source code demo visit here.