Giter Club home page Giter Club logo

tokbox's Introduction

Tokbox Golang GoDoc

This Library is for creating sessions and tokens for the Tokbox Video, Voice & Messaging Platform. See Tokbox website

It is a hybrid library (supports Google App Engine and Stand-Alone binary). It supports multi-threading for faster generation of tokens.

Install

go get -u github.com/pjebs/tokbox

Usage

import "github.com/pjebs/tokbox"

//setup the api to use your credentials
tb := tokbox.New("<my api key>","<my secret key>")

//create a session
session, err := tb.NewSession("", tokbox.P2P) //no location, peer2peer enabled

//create a token
token, err := session.Token(tokbox.Publisher, "", tokbox.Hours24) //type publisher, no connection data, expire in 24 hours

//Or create multiple tokens
tokens := session.Tokens(5, true, tokbox.Publisher, "", tokbox.Hours24) //5 tokens, multi-thread token generation, type publisher, no connection data, expire in 24 hours. Returns a []string

See the unit test for a more detailed example.

Settings

type MediaMode string

const (
	/**
	 * The session will send streams using the OpenTok Media Router.
	 */
	MediaRouter MediaMode = "disabled"
	/**
	* The session will attempt to send streams directly between clients. If clients cannot connect
	* due to firewall restrictions, the session uses the OpenTok TURN server to relay streams.
	 */
	P2P = "enabled"
)

MediaMode is the second argument in NewSession method.

type Role string

const (
	/**
	* A publisher can publish streams, subscribe to streams, and signal.
	 */
	Publisher Role = "publisher"
	/**
	* A subscriber can only subscribe to streams.
	 */
	Subscriber = "subscriber"
	/**
	* In addition to the privileges granted to a publisher, in clients using the OpenTok.js 2.2
	* library, a moderator can call the <code>forceUnpublish()</code> and
	* <code>forceDisconnect()</code> method of the Session object.
	 */
	Moderator = "moderator"
)

Role is the first argument in Token method.

const (
	Days30  = 2592000 //30 * 24 * 60 * 60
	Weeks1  = 604800 //7 * 24 * 60 * 60
	Hours24 = 86400  //24 * 60 * 60
	Hours2  = 7200   //60 * 60 * 2
	Hours1  = 3600   //60 * 60
)

Expiration value forms the third argument in Token method. It dictates how long a token is valid for. The unit is in (seconds) up to a maximum of 30 days.

Methods

func (t *Tokbox) NewSession(location string, mm MediaMode) (*Session, error)

Creates a new session or returns an error. A session represents a 'virtual chat room' where participants can 'sit in' and communicate with one another. A session can not be deregistered. If you no longer require the session, just discard it's details.

location string

The location setting is optional, and generally you should keep it as "". This setting is an IP address that TokBox will use to situate the session in its global network. If no location hint is passed in (which is recommended), the session uses a media server based on the location of the first client connecting to the session. Pass a location hint in only if you know the general geographic region (and a representative IP address) and you think the first client connecting may not be in that region. If you need to specify an IP address, replace location with an IP address that is representative of the geographical location for the session. (Tokbox - REST API reference)

mm MediaMode

P2P will direct clients to transfer video-audio data between each other directly (if possible).

MediaRouter directs data to go through Tokbox's Media Router servers. Integrates Intelligent Quality Control technology to improve user-experience (albeit at higher pricing). (Tokbox - REST API reference)

func (s *Session) Token(role Role, connectionData string, expiration int64) (string, error)

Generates a token for a corresponding session. Returns a string representing the token value or returns an error. A token represents a 'ticket' allowing participants to 'sit in' a session. The permitted range of activities is determined by the role setting.

role Role

Publisher - allows participant to broadcast their own audio and video feed to other participants in the session. They can also listen to and watch broadcasts by other members of the session.

Subscriber - allows participants to only listen to and watch broadcasts by other participants in the session with Publisher rights.

connectionData string

connectionData - Extra arbitrary data that can be read by other clients. (Tokbox - Generating Tokens)

expiration int64

expiration - How long the token is valid for. The unit is in (seconds) up to a maximum of 30 days. See above for built-in enum values, or use your own.

func (s *Session) Tokens(n int, multithread bool, role Role, connectionData string, expiration int64) []string

Generates multiple (n) tokens in one go. Returns a []string. All tokens generated have the same settings as dictated by role, connectionData and expiration. See above for more details. Since the function repeatedly calls the Token method, any error in token generation is ignored. Therefore it may be prudent to check if the length of the returned []string matches n.

multithread bool

If true, the function strives to generate the tokens concurrently (if multiple CPU cores are available). Preferred if many, many, many tokens need to be generated in one go.

Credits:

(This library is based on the older tokbox library โ€“ no longer in active development)

https://github.com/cioc/tokbox by Charles Cary

tokbox's People

Contributors

pjebs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tokbox's Issues

Pstn integrations

This is a really well done project.

I am trying to get it to work with pstn and did numbers.

Maybe you know some providers for integration from your experience with opentok ?

Would be happy to write an integration between providers and this project in golang.

I am also working on a web UI for admin / management to integrate with this library.

Thanks in advance !!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.