Sceenic - WatchTogether
  • Watch Together and Synchronization SDKs
  • Watch together SDK
    • Watch Together SDK overview
    • Authentication overview
    • Tutorials
      • Android
        • Android - Java/Kotlin
      • iOS
        • iOS Swift/Objective-c adapter
      • Web
        • Authentication
        • Create a New Project
        • Adding WT SDK library to the project
        • Installing the NPM package
        • Sample application
          • The conference skeleton
          • Connecting to a Session
          • How to turn on and off video and audio
          • How to change video quality
          • Errors handling
          • Leave the call
        • Support
    • API references
      • Android reference
        • Session
        • SessionListener
        • SessionReconnectListener
        • SessionConnectionListener
        • Participant
          • ParticipantType
        • SessionError
      • iOS Swift reference
        • Session
        • SessionDelegate
        • Participant
        • ParticipantActiveSpeakerDelegate
        • ParticipantDelegate
        • LocalParticipant
        • WTError
        • DataTypes
      • iOS Objective-c adapter reference
        • SessionAdapter
        • SessionAdapterDelegate
        • ParticipantAdapter
        • LocalParticipantAdapter
        • ParticipantAdpaterDelegate
        • ParticipantAdapterActiveSpeakerDelegate
        • NSError
        • DataTypes
      • Web reference
        • WT Session
          • WTSession.connect(sToken, pName, uC, m)
          • WTSession.connectAsAViewer(sToken, pName)
          • WTSession.connectWithSharingScreen(sToken, pName)
          • WTSession.disconnect()
          • WTSession.enableStats()
          • WTSession.sendMessage(msg)
          • WTSession.sendPlayerData(time)
          • async WTSession.getSessionState()
        • SessionListeners
          • WTSessionListeners.onConnected(fn)
          • WTSessionListeners.onDisconnected(fn)
          • WTSessionListeners.onStreamCreated(fn)
          • WTSessionListeners.onLocalStreamCreated(fn)
          • WTSessionListeners.onMosReport(fn)
          • WTSessionListeners.offMosReport(fn)
          • WTSessionListeners.onMessageReceived(fn)
          • WTSessionListeners.onSyncData(fn)
          • WTSessionListeners.onIceDisconnected(fn)
        • Participant
          • setMediaQuality
        • ParticipantListeners
        • ErrorsListeners
        • ReconnectListeners
        • MediaDevices
      • Cluster authentication service reference (CAS)
  • Synchronization SDK
    • Synchronization SDK overview
    • Tutorials
      • Android
        • Android - Java/Kotlin
      • iOS
        • iOS - Swift/Objective-c
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
        • v2.0 Migration Guide
    • API references
      • Android reference
        • SynchSDK
        • SynchListener
      • iOS reference
        • SynchSDK
        • SynchListener
      • Web reference
  • Celebrity SDK
    • Celebrity SDK overview
    • Tutorials
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
    • API References
      • Web reference
  • Chat SDK
    • Chat SDK overview
    • Tutorials
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
    • API Refences
      • Web reference
  • Public Chat SDK
    • Public Chat SDK overview
    • Tutorials
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
    • API Refences
      • Web reference
  • Celebrity Watch Party
    • Web application
    • Android
    • iOS
    • Celebrity View & Fan View
Powered by GitBook
On this page
  • Overview
  • Requirements
  • Authentication
  • Acquiring an Access Token
  • Going to production
  • Create a project
  • Add chat SDK library to your project
  • Basic setup
  • Support

Was this helpful?

  1. Public Chat SDK
  2. Tutorials
  3. Web

Web - TypeScript/React

PreviousInstalling the NPM packageNextAPI Refences

Last updated 2 years ago

Was this helpful?

Overview

Follow this step-by-step tutorial to create basic implementation of Public Chat SDK.

Requirements

  • A Sceenic account

  • Code Editor( , )

  • NPM access token for Chat SDK

  • API_KEY and API_SECRET

Authentication

An Access Token is needed in order to allow a client to connect to chat service.

Note: It is important that the client application does not request an Access Token directly from the frontend. By doing that you risk exposing the API_KEY and API_SECRET.

Acquiring an Access Token

curl -iL --request GET --url https://YOUR_CAS_URL/public-chat/token/?sub=USER_ID --header 'auth-api-key: API_KEY'   --header 'auth-api-secret: API_SECRET'

A successful response will look like that:

{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...."
}

USER_ID is some unique identifier of the user in your system.

Note: Every chat token corresponds to one specific user only.

Going to production

When moving from the Sandbox environment to production you will need to implement your own authentication server. This server will supply the various clients (Web, Android, and iOS) with a valid Access Token so that they can use the service.

For that you will need:

  • Your own working authentication server

Create a project

To create a project we recommended using the following stack: React + TypeScript + ChatSDK.

  • Create an empty React + Typescript project

npx create-react-app my-app --template typescript  

Add chat SDK library to your project

  • Create .npmrc file. In the project’s root folder

  • Put your Access Token inside //registry.npmjs.org/:_authToken=YOUR_ACCESS_TOKEN.

  • Install Public Chat SDK via npm i @sscale/pchatsdk.

Basic setup

  • Add the following import

import { PChatSDK } from '@sscale/pchatsdk';
  • Create public chat SDK instance

const pchatSDK = new PChatSDK();
  • Subscribe to events

import { Events } from '@sscale/pchatsdk';

pchatSDK.on(Events.ERROR, (e) => {});
pchatSDK.on(Events.CONNECT, () => {});
pchatSDK.on(Events.MESSAGE, (message) => {});
...
  • Connect to room

pchatSDK.connect('room_id', 'username', JWT_ACCESS_TOKEN)
        .then(() => {})
        .catch(e => {});
  • Load history

pchatSDK.loadOlder()
        .then(() => {})
        .catch(e => {});
  • Access messages

pchatSDK.messages.forEach((message) => {});
  • Send message

pchatSDK.publish('Hello')
        .then(() => {})
        .catch(e => {});

In addition, have a look at the extra features available for you:

pchatSDK.user;
pchatSDK.state;

pchatSDK.disconnect();

Support

The Access Token is a JWT token - more about jwt you can read - .

You can get your API_KEY and API_SECRET in your private area, .

API_KEY, and API_SECRET - can be retrieved in your private area once you

For more information on NPM installation look .

Have a look at the and it's to see all the features and public chat SDK API documentation .

Need technical support? contact us at .

Code samples
Demo application
API Documentation
WebStorm
VS Code
Node >= 8.10 and npm >= 5.6
here
here
login
here
demo application
sources
here
Support@sceenic.co