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

tonio-captions

v1.0.10

Published

This package allows vendors to provide live captions.

Downloads

5

Readme

tonio-captions

A client for interaction with the Tonio service. It allows vendors to provide live captions.

Version npm Continious Integration Continious Deployment npm Downloads

NPM

Table of contents

Installation

Install with npm

npm install tonio-captions --save

Usage

The recommended way to use tonio-captions is to create Tonio client with base Tonio service url and initialize it before first usage. tonio-captions should be initialized only once:

const Tonio = require("tonio-captions");

//Provide base Tonio service url into constructor.
const tonio = new Tonio("https://api.tonio.com/v1/");

//Tonio should be initialized only once before first usage.
tonio.initialize();

You could check whether tonio-captions is initialized or not by using tonio.isInitialized property:

console.log(`Initialized: ${tonio.isInitialized}.`);

After finishing working with tonio-captions is is recommended to free up resources by using destroy method:

tonio.destroy();

Authentication

After creation of instance and initialization of tonio-captions you have to pass authentication. You could sign in to Tonio using your email and password via tonio.signIn method:

tonio.signIn("username", "password")
    .then(() => {
        console.log("Successfully signed in.");
    })
    .catch(error => {
        console.log(error);
    });

You could also subscribe to authentication state change by using tonio.onAuthStateChange method:

tonio.onAuthStateChange(isSignedIn => {
        console.log(`Signed in: ${isSignedIn}.`);
    });

If you dont want to use authentication state change callback you could use tonio.isSignedIn property to find out if user is signed in or not:

console.log(`Signed in: ${tonio.isSignedIn}.`);

To sign out from Tonio just call tonio.signOut method:

tonio.signOut()
    .then(() => {
        console.log("Successfully signed out.");
    })
    .catch(error => {
        console.log(error);
    });

Tonio API

When performance started you should call tonio.startPerformance method with performance id. It updates performance with the actual start time:

tonio.startPerformance("sn7Q3mYJmup3SxUFeas66M")
            .then(response => {
                console.log("Performance started successfully.", response);
            })
            .catch(error => {
                console.log("An error happened while starting performance.", error);
            });

When performance ended you should call tonio.endPerformance method with performance id. It updates performance with the actual end time:

tonio.endPerformance("sn7Q3mYJmup3SxUFeas66M")
            .then(response => {
                console.log("Performance ended successfully.", response);
            })
            .catch(error => {
                console.log("An error happened while ending performance.", error);
            });

When during the performance an interval occures you should call method tonio.startInterval with performance id to start the interval:

tonio.startInterval("sn7Q3mYJmup3SxUFeas66M")
            .then(response => {
                console.log("Interval started successfully.", response);
            })
            .catch(error => {
                console.log("An error happened while starting interval.", error);
            });

When started interval is ended you should call method tonio.endInterval with performance id to end the interval:

tonio.endInterval("sn7Q3mYJmup3SxUFeas66M")
            .then(response => {
                console.log("Interval ended successfully.", response);
            })
            .catch(error => {
                console.log("An error happened while ending interval.", error);
            });

When certain caption should be shown during the performance you should call tonio.sendCaption with performance id and caption id to send Tonio the caption:

tonio.sendCaption("sn7Q3mYJmup3SxUFeas66M", "-opceWusILY")
            .then(response => {
                console.log("Caption has been sent successfully.", response);
            })
            .catch(error => {
                console.log("An error happened while sending caption.", error);
            }); 

Error Handling

If something is wrong during the Tonio methods invocation TonioError would be thrown. It has stack trace and additional errors array properties:

tonio.sendCaption("sn7Q3mYJmup3SxUFeas66M", "-opceWusILY")
            .then(response => {
                console.log("Caption has been sent successfully.", response);
            })
            .catch(error => {
                console.log("Additional errors.", error.errors);

                console.log("Stack trace.", error.stackTrace);
            }); 

You could also convert TonioError to JSON object:

tonio.startInterval("sn7Q3mYJmup3SxUFeas66M")
    .catch(error => console.log("An error happened while ending interval.", error.toObject()));

Logging

By default Tonio uses winston library to log into file. Default log level is error and log directory is ./node_modules/tonio-captions/logs. Logs are rotated every week or by size, 20m is maximum size of log file.

You could change log level to info if you want to get more debug information:

tonio.logger.level = "info";

Or you could turn all logs off if you want to get rid of them:

tonio.logger = null;

Finally, you could replace the default logger with your own with tonio.logger property. Keep in mind that your logger should implement following methods:

const functions = require("firebase-functions");

tonio.logger = functions.logger;

tonio.logger.info("Info log message.", { message: "Test info object." });

tonio.logger.warn("Warn log message.", { message: "Test warn object." });

tonio.logger.error("Error log message.", { message: "Test error object." });

Promises

tonio-captions depends on a native ES6 Promise implementation to be supported. If your environment doesn't support ES6 Promises, you can polyfill.

License

MIT