npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stimulus-twilio-video

v1.0.9

Published

Stimulus controller for video chat with Twilio

Downloads

6

Readme

https://nodei.co/npm/stimulus-twilio-video.png?downloads=true&downloadRank=true&stars=true

Stimulus Twilio Video

A Stimulus controller for video calls using Twilio's video API

Install

For yarn:

yarn add stimulus-twilio-video

For npm:

npm add stimulus-twilio-video

Register the controller with your Stimulus application

import { Application } from 'stimulus'
import TwilioVideoController from 'stimulus-twilio-video'

const application = Application.start()
application.register('video-call', TwilioVideoController)

Add Stimulus values, targets and actions to your HTML

1. The wrapper container

The wrapper container needs the data-controller attribute, as well as a few values. The examples below assume that you registered the controller with the name video-call, as above.

<div data-controller="video-call"
     data-video-call-access-token-value="YOUR TWILIO JWT"
     data-video-call-room-id-value="YOUR ROOM ID"
     data-video-call-buddy-video-width-value="200"
     >
...
</div>

Values

  • access-token - a JWT which you have already prepared on your server. See the Twilio API documentation
  • room-id - an ID which you have already generated on your server. It should be a unique string identifying the video call
  • buddy-video-width - the optional width in pixels for the element showing the user's chat buddy's webcam video. (Default: 640)

2. The video targets

This target will be used to attach and display the user's chat buddy's webcam video:

<div data-video-call-target="buddyVideo"></div>

This target will be used to attach and display the user's own webcam video:

<div data-video-call-target="localVideo"></div>

3. The call buttons

To allow the user to join and end the video call, you should add code similar to this. It uses Stimulus actions to trigger the joinCall and endCall events which are defined in the controller.

<div class="btn-call-start" data-action="click->video-call#joinCall">Call</div>
<div class="btn-call-end" data-action="click->video-call#endCall">End call</div>

Responding to events

You might want your code to do something when an event happens, eg. show/hide part of the DOM when a buddy joins the call. This is possible if you extend the controller with a class of your own. You can implement the following methods:

  • callStarted() - will be triggered when the user has successfully connected to the Twilio video call
  • callEnded() - will be triggered when a buddy has disconnected, or when the user ends the call
  • buddyJoined() - will be triggered when a buddy joins the call
  • buddyLeft() - will be triggered when the buddy leaves the call

Note: If you choose to inherit the stimulus-twilio-video controller, you should remove the code above which registers that controller with the application. Instead, add your own controller along these lines:

// ./controllers/video_call_controller.js
import TwilioVideoController from 'stimulus-twilio-video'

export default class extends TwilioVideoController {
  callStarted() {
    console.log('Call started!')
    // Do something interesting here, eg. hide the 'start call' button
  }

  callEnded() {
    console.log('Call ended!')
    // Do something interesting here, eg. show a message
  }

  buddyJoined() {
    console.log('Buddy has joined the call')
  }

  buddyLeft() {
    console.log('Buddy has left the call')
  }
}

Demo App

Here is a Rails application which uses this package to build a simple one-to-one chat application.