All Projects → domchristie → webrtc-hotwire-rails

domchristie / webrtc-hotwire-rails

Licence: MIT License
A video chat app demonstration using Hotwire and Ruby on Rails

Programming Languages

javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to webrtc-hotwire-rails

singo
Simple WebRTC Signaling Server written in Go
Stars: ✭ 57 (+50%)
Mutual labels:  webrtc, webrtc-demos, webrtc-signaling
foxrtc
media sdk based on webrtc
Stars: ✭ 36 (-5.26%)
Mutual labels:  webrtc, webrtc-demos, webrtc-video
suc-love-chat
视频会议系统前端源码
Stars: ✭ 35 (-7.89%)
Mutual labels:  webrtc, webrtc-video
Mediastreamrecorder
Cross browser audio/video/screen recording. It supports Chrome, Firefox, Opera and Microsoft Edge. It even works on Android browsers. It follows latest MediaRecorder API standards and provides similar APIs.
Stars: ✭ 2,381 (+6165.79%)
Mutual labels:  webrtc, webrtc-demos
stimulus reflex
Build reactive applications with the Rails tooling you already know and love.
Stars: ✭ 2,001 (+5165.79%)
Mutual labels:  ruby-on-rails, hotwire
React Webrtc
Video chat using webRTC and react
Stars: ✭ 168 (+342.11%)
Mutual labels:  webrtc, webrtc-demos
Rtcmulticonnection
RTCMultiConnection is a WebRTC JavaScript library for peer-to-peer applications (screen sharing, audio/video conferencing, file sharing, media streaming etc.)
Stars: ✭ 2,187 (+5655.26%)
Mutual labels:  webrtc, webrtc-demos
demo-rails-webrtc
A demo project shows how to use webrtc on rails
Stars: ✭ 28 (-26.32%)
Mutual labels:  webrtc-demos, webrtc-video
Webrtc Data Channel Demo
WebRTC Data Channel demo
Stars: ✭ 116 (+205.26%)
Mutual labels:  webrtc, webrtc-demos
WebRTC-Python-Open-Source-Application-for-1-to-1-video-chat
This Sample Python Application demonstrates the use of EnableX Platform Server APIs and JavaScript Toolkit to develop basic one to one video chat application. It allows developers to ramp up on app development by hosting on their own devices.
Stars: ✭ 12 (-68.42%)
Mutual labels:  webrtc, webrtc-demos
video-chat
Simple Web Application that offer you to create video meeting room using WebRTC and Socket.
Stars: ✭ 32 (-15.79%)
Mutual labels:  webrtc-demos, webrtc-video
rails hotwire base
Rails + Hotwire base app
Stars: ✭ 54 (+42.11%)
Mutual labels:  ruby-on-rails, hotwire
Workerman Webrtc
php webrtc demo based on workerman
Stars: ✭ 161 (+323.68%)
Mutual labels:  webrtc, webrtc-demos
Samples
WebRTC Web demos and samples
Stars: ✭ 11,318 (+29684.21%)
Mutual labels:  webrtc, webrtc-demos
Cuckoo
🎥 Cuckoo - A free anonymous video-calling web application built with WebRTC and React that provides peer-to-peer video and audio communication in a web browser with no plugins or extensions required.
Stars: ✭ 195 (+413.16%)
Mutual labels:  webrtc, webrtc-demos
Wave Share
Serverless, peer-to-peer, local file sharing through sound
Stars: ✭ 1,641 (+4218.42%)
Mutual labels:  webrtc, webrtc-signaling
Webrtcchat
🔏 Pure Browser To Browser Chat (STUN & ICE Servers optional)
Stars: ✭ 230 (+505.26%)
Mutual labels:  webrtc, webrtc-demos
Translator
Translator.js is a JavaScript library built top on Google Speech-Recognition & Translation API to transcript and translate voice and text. It supports many locales and brings globalization in WebRTC! https://www.webrtc-experiment.com/Translator/
Stars: ✭ 103 (+171.05%)
Mutual labels:  webrtc, webrtc-demos
Webrtc Experiment
WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
Stars: ✭ 10,335 (+27097.37%)
Mutual labels:  webrtc, webrtc-demos
flutter-webrtc python-aiortc-opencv
Flutter WebRTC demo with Python server to perform image processing on video frames using OpenCV
Stars: ✭ 34 (-10.53%)
Mutual labels:  webrtc-demos, webrtc-video

WebRTC + Hotwire + Ruby on Rails

An basic video chat app using the WebRTC Perfect Negotiation pattern, a sprinkling of Hotwire (mainly Turbo Streams & Stimulus), and backed by Ruby on Rails.

How does it work?

The Stimulus room controller handles Enter button click. It gets the user's local audio and video and feeds them into the local video element. It also starts Action Cable subscriptions specific to the current room: one for communicating WebRTC messages: the Signaller; and one for clients to ping others: the RoomSubscription. Once connected, the room channel broadcasts the presence of this new client. Each connected client then "greets" this newcomer by calling the greet action on the room channel and specifying to and from fields.

The greet action broadcasts specifically to the newcomer, a Turbo Stream update which appends a media element representing the remote client. It's important we do this first so that it's ready for incoming streams. The medium controller messages the room controller to notify that it has been added (this will be simplified once https://github.com/hotwired/stimulus/pull/409 is merged). This begins the WebRTC negotiation to form a connection between the two clients.

The WebRTC negotiation is quite complex, and even though things are required to happen in a particular order, responses are triggered asynchronously, making it tricky to get right. This is where the WebRTC Perfect Negotiation pattern comes in. We won't go into it too much here, as it's covered well elsewhere; but for the purpose of this description, (deep breath), Session Description Protocol (SDP) descriptions and Interactive Connectivity Establishment (ICE) candidates are exchanged over the Signaller. The negotiation is "perfect" as it ensures that the RTCPeerConnection is in the correct state for setting descriptions, and avoids collision errors by having one client be "polite" and other "impolite"—the polite one backs down in the case of a collision. Anyway, the code for this has been mostly lifted from the spec and handled by the Signaller/WebrtcNegotiation. When creating the negotition, the room controller listens for track events on the RTCPeerConnection, so it can start streaming from the remote client.

Once the negotiation has been created, the newcomer client notifies the other client by reciprocating the greeting i.e. calling greet on the room channel. This triggers the same process as above on the other client: appending a media element via a Turbo Stream update, and starting a WebRTC negotiation. This time though, instead of a greeting (which would be very polite, but awkward and endless!), the client starts streaming to the other client, by adding media tracks to the connection. This kicks off the complex exchange of SDP descriptions and ICE candidates, and once either is received by the newcomer, it can start the streaming process from its own stream to the other client. Now all clients are streaming to and from each other.

Finally, when a client disconnects from the room channel, a Turbo Stream update removes the media element from the screen. The media controller broadcasts its removal so the room controller can clean up.

To summarise the flow:

  1. A newcomer broadcasts its presence to others in the room
  2. The connected clients greet this newcomer letting them know their ID
  3. A Turbo Stream update creates a video element on the newcomer's screen for each greeting it receives
  4. The newcomer creates a WebRTC negotiation and sends a greeting back to each of the other clients
  5. Turbo Stream updates create video elements on each of the other clients' screens
  6. WebRTC negotiations are created by each of the other clients, and they start streaming to the newcomer
  7. Reacting to negotiation activity (SDP descriptions and ICE candidate exchanges), the newcomer starts streaming to other clients

Browser Support?

This has only been tested in macOS Firefox/Chrome/Safari and iOS Safari.

TODO

  • Add "Leave" functionality + handle ICE candidate disconnections (rather than just closing the browser window)

License

Copyright © 2021+ Dom Christie and released under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].