Skip to main content

Introduction

The Twilio Shim by Ospi is a package that allows you to migrate your video calling applications from Twilio to Ospi infrastructure.

  • Ospi provides a set of shim libraries that serve as seamless replacements for the Twilio video APIs. These shims serve as a fundamental building block for migrating your real-time voice and video applications from Twilio to Ospi infrastructure.
  • The @dytesdk/twilio-shim package serves as a wrapper over the Ospi SDK with an external API that is fully compatible with Twilio JS. As a drop-in replacement for Twilio JS, it can handle most of the methods and events that are present in the original library.

Please contact us for any help or support with the migration.

Start migrating from Twilio to Ospi with Shim

To get started with the Ospi Shim for Twilio, install the shim from the NPM Registry using the following command:

npm install @dytesdk/twilio-shim

Usage

The @dytesdk/twilio-shim shares the same API as the Twilio video SDK. You can use most of the methods that are supported by it.

Here are some sample cases, and if you want to see a complete list of compatible features, see the Twilio Shim: Supported Features page.

Connect to a room

You can obtain Ospi authentication token <DYTE-AUTH-TOKEN> using the Add a Participant API.

const { connect } = require('@dytesdk/twilio-shim');

const authToken = '<AUTH_TOKEN_FROM_DYTE_API>';
const room = await connect(authToken, { audio: false, video: true });
console.log(`Successfully joined a Room: ${room.name}`);
console.log(room);
room.on('participantConnected', (participant) => {
console.log(`A remote Participant connected: ${participant}`);
});

Add a participant

const { connect } = require('@dytesdk/twilio-shim');

const authToken = '<AUTH_TOKEN_FROM_DYTE_API>';
const room = await connect(authToken, { audio: false, video: false });
room.on('participantConnected', (participant) => {
console.log(`Participant "${participant.identity}" connected`);

participant.tracks.forEach((publication) => {
if (publication.isSubscribed) {
const track = publication.track;
document.getElementById('remote-media-div').appendChild(track.attach());
}
});

participant.on('trackSubscribed', (track) => {
console.log('Subscribed to track', track);
const element = track.attach();
console.log(element);
document.getElementById('remote-media-div').appendChild(element);
});
});

Enable audio and video

const { connect } = require('@dytesdk/twilio-shim');

const authToken = '<AUTH_TOKEN_FROM_DYTE_API>';
const room = await connect(authToken, { audio: true, video: true });

room.localParticipant.audioTracks.forEach((publication) => {
publication.track.disable();
});

room.localParticipant.videoTracks.forEach((publication) => {
publication.track.disable();
});

// Enable audio and video tracks after 5 seconds
setTimeout(() => {
room.localParticipant.audioTracks.forEach((publication) => {
publication.track.enable();
});

room.localParticipant.videoTracks.forEach((publication) => {
publication.track.enable();
});
}, 5000);