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

nativescript-twilio

v0.14.0

Published

NativeScript Twilio SDK plugin

Downloads

5

Readme

NativeScript Twilio

nativescript-twilio is a plugin that exposes the Twilio Voice SDK, the leading platform for Voice solutions.

Note: For now it only for making outbound calls, both for Android and iOS

Prerequisites / Requirements

Plugin installation on your Nativescript app

tns plugin add nativescript-twilio

Usage

Demo App

Setup

Running the Demo app

  • Clone the repo, cd src, and npm run demo.android or npm run demo.ios.

Integrating into your NativeScript app

  • On the main.ts or app.ts file, put this code in order to init Twilio:

  import * as application from 'tns-core-modules/application';
  import { initTwilio } from 'nativescript-twilio';
  import { TwilioAppDelegate } from 'nativescript-twilio/delegate';

  // The following endpoint should return the raw token in the request body
  const accessTokenUrl = 'http://yourserver/path/to/access-token';
  const accessTokenHeaders = {'Authorization': 'Token sometoken'};

  initTwilio(accessTokenUrl, accessTokenHeaders);

  if (application.ios) {
    // register twilio app delegate in order to receive incoming calls
    application.ios.delegate = TwilioAppDelegate;
  }
  • In some place in your code (i.e. in some UI component loaded event) you need to setUp the call listener, which will handle the call's connection events:
  import { setupCallListener, setupPushListener } from 'nativescript-twilio';

  // listener for inbound/outbound calls
  const callListener = {
    onConnectFailure(call, error) {
      dialogs.alert(`connection failure: ${error}`);
    },
    onConnected (call) {
      dialogs.alert('call connected');
    },
    onDisconnected (call) {
      dialogs.alert('disconnected');
    }
  };

  setupCallListener(callListener);

  // listener for push notifications (incoming calls)
  const pushListener = {
    onPushRegistered(accessToken, deviceToken) {
      dialogs.alert('push registration succeded');
    },
    onPushRegisterFailure (error) {
      dialogs.alert(`push registration failed: ${error}`);
    }
  };

  setupPushListener(pushListener);
  • On the component for making outbound calls, put the following code:

  import * as dialogs from 'tns-core-modules/ui/dialogs';
  import { getAccessToken, Twilio } from 'nativescript-twilio';

  const phoneNumber = '+1555365432';

  getAccessToken() // it will use the Twilio configuration set before
    .then((token) => {
      const twilio = new Twilio(token);

      const call = twilio.makeCall(phoneNumber);

      // example of muting the call after 10 seconds
      setTimeout(() => {
        console.log('Muting call after 10 seconds...');
        call.mute(true);
      }, 10000);

      // example of disconnecting the call after 30 seconds
      setTimeout(() => {
        console.log('Disconnecting call after 30 seconds...');
        call.disconnect();
      }, 30000);

    })

API

Functions

| Function | Description | | ---------------------------------------- | -------------------------------------------------------- | | initTwilio(url: string, headers?: any) | Initialize Twilio passing the endpoint to the access token backend | | getAccessToken(): Promise<string> | Ask the backend for an access token. Returns a Promise with the token retrieved | | setupCallListener(listener: any) | Setup the call listener, passing an object with onConnectFailure, onConnected and onDisconnected callbacks | | setupPushListener(listener: any) | Setup the push notifications listener, passing an object with onPushRegistered and onPushRegisterFailure callbacks | | unregisterPushNotifications(token: string, deviceToken: string, callback?: (error: any) => void) | Unregister push notifications (incoming calls) |

Twilio Methods

| Method | Description | | ------------------------------- | ------------------------------------------------------------- | | makeCall(senderPhoneNumber: any, phoneNumber: any, options?: any): Call | Make an outbound call. | | toggleAudioOutput(toSpeaker: boolean) | iOS Only Set the audio session output to the speaker or not. |

Call Methods

| Method | Description | | ------------------------------- | ------------------------------------------------------------ | | mute(value: boolean) | Mute the call. | | disconnect() | Hang-up the call. |

License

Apache License Version 2.0, April 2018