@dytesdk/opentok-shim
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Logo

Opentok shim by dyte


Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

About The Project

This package @dytesdk/opentok-shim is a wrapper over the Dyte SDK with a Opentok compatible external API. It is a drop-in replacement for Opentok JS, and supports most of the methods and events that are present in the library.

Built With

Getting Started

You can install the @dytesdk/opentok-shim from the NPM Registry using the npm install command.

npm install @dytesdk/opentok-shim

Usage

The @dytesdk/opentok-shim shares the same API as the opentok Video SDK. You can use most of the methods that are supported by it. Here's a compatibility specification that describes the methods from opentok-video that are supported by this @dytesdk/opentok-shim package.

Here are a few examples: Replace:

import * as OT from "@opentok/client";

with

import * as OT from "@dytesdk/opentok-shim";

Connection

const token = "<DYTE-AUTH-TOKEN>";
const sessionId = "";
const session = OT.initSession(token, sessionId);
session.on("streamCreated", function streamCreated(event) {
  console.log("[streamCreated] index.ts: ", event.stream);
  session.subscribe(
    event.stream,
    "subscriber",
    {
      insertMode: "append",
      width: "100%",
      height: "100%",
    },
    handleError
  );
  // }
});

let connections: OT.Connection[] = [];
session.on("connectionCreated", (connectionCreatedEvent) => {
  console.log("session connectionCreatedEvent: ", connectionCreatedEvent);
  connections.push(connectionCreatedEvent.connection);

  if (
    connections.find(
      (connection) =>
        connection.connectionId ===
        connectionCreatedEvent.connection.connectionId
    )
  ) {
    console.log("connection already exists");
    return;
  }
  connections.push(connectionCreatedEvent.connection);
});

session.on("connectionDestroyed", (connectionDestroyedEvent) => {
  console.log("session connectionDestroyedEvent: ", connectionDestroyedEvent);
  connections = connections.filter(
    (connection) =>
      connection.connectionId !==
      connectionDestroyedEvent.connection.connectionId
  );
});

About

opentok-shim is created & maintained by Dyte, Inc. You can find us on Twitter - @dyte_io or write to us at dev [at] dyte.io.

The names and logos for Dyte are trademarks of Dyte, Inc.

We love open source software! See our other projects and our products.

Dependencies (3)

Dev Dependencies (16)

Package Sidebar

Install

npm i @dytesdk/opentok-shim

Homepage

dyte.io

Weekly Downloads

0

Version

0.0.1

License

UNLICENSED

Unpacked Size

89.5 kB

Total Files

26

Last publish

Collaborators

  • dyteindia