Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Twilio’s Programmable Video JavaScript SDK

License

NotificationsYou must be signed in to change notification settings

twilio/twilio-video.js

Repository files navigation

NPMCircleCI

twilio-video.js allows you to add real-time voice and video to your web apps.

We want your feedback! Please feel free to open aGitHub issue for suggested improvements or feature requests. If you need technical support, contacthelp@twilio.com.

Changelog

ViewCHANGELOG.md for details about our releases.

Browser Support

ChromeEdge (Chromium)FirefoxSafariWebView
Android---
iOS-*
Linux---
macOS✓ **-
Windows✓ **--

** twilio-video.js supports theChromium-based Edge browser.

Installation

NPM

npm install twilio-video --save

Using this method, you canrequire twilio-video.js like so:

constVideo=require('twilio-video');

TypeScript definitions can now be imported using this method.

import*asVideofrom'twilio-video';functionparticipantDisconnected(participant:Video.RemoteParticipant){console.log('Participant "%s" disconnected',participant.identity);document.getElementById(participant.sid).remove();}

Alternatively, you can import just the definitions you need like so:

import{RemoteParticiant}from'twilio-video';functionparticipantDisconnected(participant:RemoteParticipant){console.log('Participant "%s" disconnected',participant.identity);document.getElementById(participant.sid).remove();}

CDN

Releases of twilio-video.js are hosted on a CDN, and you can include thesedirectly in your web app using a <script> tag.

<scriptsrc="//sdk.twilio.com/js/video/releases/2.32.1/twilio-video.min.js"></script>

Using this method, twilio-video.js will set a browser global:

constVideo=Twilio.Video;

Usage

The following is a simple example for connecting to a Room. For more information, refer to theAPI Docs.

constVideo=require('twilio-video');Video.connect('$TOKEN',{name:'room-name'}).then(room=>{console.log('Connected to Room "%s"',room.name);room.participants.forEach(participantConnected);room.on('participantConnected',participantConnected);room.on('participantDisconnected',participantDisconnected);room.once('disconnected',error=>room.participants.forEach(participantDisconnected));});functionparticipantConnected(participant){console.log('Participant "%s" connected',participant.identity);constdiv=document.createElement('div');div.id=participant.sid;div.innerText=participant.identity;participant.on('trackSubscribed',track=>trackSubscribed(div,track));participant.on('trackUnsubscribed',trackUnsubscribed);participant.tracks.forEach(publication=>{if(publication.isSubscribed){trackSubscribed(div,publication.track);}});document.body.appendChild(div);}functionparticipantDisconnected(participant){console.log('Participant "%s" disconnected',participant.identity);document.getElementById(participant.sid).remove();}functiontrackSubscribed(div,track){div.appendChild(track.attach());}functiontrackUnsubscribed(track){track.detach().forEach(element=>element.remove());}

Content Security Policy (CSP)

Want to enableCSP in away that's compatible with twilio-video.js? Use the following policy directives:

connect-src wss://global.vss.twilio.com wss://sdkgw.us1.twilio.commedia-src mediastream:

If you're loading twilio-video.js fromsdk.twilio.com,you should also include the followingscript-src directive:

script-src https://sdk.twilio.com

If you are enablingKrisp Noise Cancellation foryour local audio, and you are using the followingdefault-src self directive, you should also add theunsafe-eval directive:

default-src self unsafe-eval

Keep in mind, you may need to merge these policy directives with your own ifyou're using other services.

Building

Fork and clone the repository. Then, install dependencies with

npm install

Then run thebuild script:

npm run build

The builds and docs will be placed in thedist/ directory.

Testing

Run unit tests with

npm run test:unit

Run integration tests with

ACCOUNT_SID=<Your account sid> \API_KEY_SID=<Your api key sid> \API_KEY_SECRET=<Your api key secret> \BROWSER=<Browser you'd like to use> \npm run test:integration

You can add these optional variables to control the integration test execution :

  • Topology : Decides which type of rooms to test against.
  • Debug : To get better source mapping, and the browser does not close after tests are run which allows you to easily step through code to debug.
  • Test Files : Allows you to limit the test to just one file.
TOPOLOGY=<peer-to-peer|group>DEBUG=1TEST_FILES=<path_ to_the_file>

Tips

  • Use Pre-commit hook: We have some useful pre-commit hook that would help identify common mistakes before commit. Use them by executing
ln -s ../../pre-commit.sh .git/hooks/pre-commit

Related

Applications using twilio-video.js

Developer tools

Contributing

Bug fixes welcome! If you're not familiar with the GitHub pullrequest/contribution process,this is a nice tutorial.

License

SeeLICENSE.md.

About

Twilio’s Programmable Video JavaScript SDK

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp