0.0.1 • Published 1 year ago

@dytesdk/opentok-shim v0.0.1

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
1 year ago

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.