tingz-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.31 • Public • Published

👨‍💻 Tingz SDK

How to use

yarn add tingz-sdk

Import the SDK and initialize.

import Tingz from 'tingz-sdk'

// Controller
const tingz = new Tings(APP_API_KEY)

// Scene Player
const tingz = new Tingz(APP_API_KEY, { isServer: true })

This SDK handles user authentication and communication between a controller app and it's scene player counterpart.

Communication is acheived through the send() and receive() functions.

Send / Receive Methods

send() accepts a JSON object which is send to the receive() function in an apps other half.

tingz.send({ action: 'START', payload: { id: 123 } })

tingz.receive((data) => {
  console.log(data) // { action: 'START', payload: { id: 123 } }
})

Other Methods

tingz.getMeetingUserList((userList) => {
  console.log(userList) // [ { id, isHost, username }, {...}, {...} ]
})

tingz.getMeetingUserHost((userHost) => {
  console.log(userHost) // { id, isHost, username }
})

tingz.changeMeetingUserHost(userId, (wasUpdated) => {
  // userIds can be obtained for example from tingz.getMeetingUserList()
  // Use this method to change the host user of the Tingz meeting room.
  console.log(wasUpdated) // Boolean
})

Events

Events can be listened to through the on() function.

Event Description
ready SDK initialization complete
message Incoming message
userConnected User connected to Tingz meeting room
userDisconnected User disconnected from Tingz meeting room
meetingHostUpdated Tingz meeting room host user was changed
// On app initialization. `ready`
tingz.on('ready', () => console.log('App is ready!'))

// On incoming message. Same as `receive()`. `message`
tingz.on('message', (data) => console.log('Message', data))

// On user has connected to Tingz meeting room event
tingz.on('userConnected', (user) => console.log('User connected', user))

// On user has disconnected from Tingz meeting room event
tingz.on('userDisconnected', (user) => console.log('User disconnected', user))

// On meeting host user has been changed inside Tingz meeting room
tingz.on('meetingHostUpdated', (hostUser) => console.log('Meeting host user', hostUser))

User

A user object is exposed with the following properties:

Key Type Description
id String Unique ID of the current user
username String Username of the current user
isHost Boolean true is current user is the meeting host

Readme

Keywords

none

Package Sidebar

Install

npm i tingz-sdk

Weekly Downloads

1

Version

1.0.31

License

MIT

Unpacked Size

1.64 MB

Total Files

16

Last publish

Collaborators

  • sisaka
  • jremi
  • trillcyborg