fenetre 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +98 -9
- data/app/assets/javascripts/fenetre/application.js +1 -14
- data/app/assets/javascripts/fenetre/controllers/index.js +1 -19
- data/app/assets/javascripts/fenetre/controllers/video_chat_controller.js +556 -516
- data/app/assets/javascripts/fenetre/vendor/stimulus.js +2567 -0
- data/app/assets/javascripts/fenetre/vendor/stimulus.min.js +5 -2588
- data/app/assets/javascripts/fenetre.js +12 -8
- data/app/assets/javascripts/stimulus/stimulus.min.js +5 -2588
- data/app/assets/stylesheets/fenetre/video_chat.css +218 -157
- data/app/channels/fenetre/video_chat_channel.rb +69 -111
- data/app/controllers/fenetre/status_controller.rb +13 -0
- data/app/helpers/fenetre/video_chat_helper.rb +54 -32
- data/app/javascript/controllers/fenetre/video_chat_controller.js +1 -662
- data/config/importmap/fenetre.rb +4 -0
- data/config/importmap.rb +7 -21
- data/config/routes.rb +6 -0
- data/lib/fenetre/engine.rb +4 -167
- data/lib/fenetre/parallel_formatter.rb +25 -0
- data/lib/fenetre/presence.rb +34 -0
- data/lib/fenetre/version.rb +1 -1
- data/lib/fenetre.rb +40 -2
- metadata +25 -42
- data/Rakefile +0 -33
- data/app/javascript/test/test_runner.js +0 -15
- data/app/javascript/test/video_chat_controller_test.js +0 -215
- data/lib/fenetre/video_chat_channel.rb +0 -36
- data/lib/tasks/javascript_test.rake +0 -69
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c218d212f99120aa8c395fc9f6848fd47cf55ab062ec7cc8e072f57b1f598f3a
|
|
4
|
+
data.tar.gz: 391ec2ec6dfca02e59dacbd2d13b2dbd170cfcbdde49a82c432fa9a4150324ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 981a9969e55e179c41104dc1350676a4df76cb2b82627d3bdebb35ce51e8e5ae6e884ec7efd3deaf7c0062427134f5a98c7db3227dd47d9c328b342b20056d7d
|
|
7
|
+
data.tar.gz: d6b5ff73871ae5b05b2876e840eec7f225e3dbcb0018f2a267b16e8ad3fa942970d065f2cc5e14bf3efdb6501d0f52021d228395da4e70f65865fd56465fa6e1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) #{Time.now.year} [Your Name or Organization] # TODO: Update copyright holder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
# Fenetre
|
|
2
2
|
|
|
3
3
|
[](https://github.com/andrewfader/fenetre/actions)
|
|
4
|
-
[](coverage/index.html)
|
|
5
5
|
|
|
6
6
|
A Rails engine that adds WebRTC video chat to your app using ActionCable, Stimulus, and Turbo.
|
|
7
7
|
|
|
8
8
|
## Setup
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Add the gem, then import it once from your entrypoint:
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
```javascript
|
|
13
|
+
// app/javascript/application.js
|
|
14
|
+
import "fenetre"
|
|
15
|
+
```
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
That single import registers the `fenetre--video-chat` Stimulus controller on your
|
|
18
|
+
application (it reuses `window.Stimulus` when your app already started one).
|
|
19
|
+
|
|
20
|
+
The engine adds its own pins to the host import map, so no `bin/importmap pin`
|
|
21
|
+
is needed for `fenetre`, `@hotwired/stimulus`, or `@rails/actioncable`.
|
|
22
|
+
|
|
23
|
+
**Requirements:**
|
|
24
|
+
- Your host application uses `importmap-rails` and `propshaft`.
|
|
25
|
+
- Action Cable is mounted (Rails mounts it at `/cable` by default).
|
|
26
|
+
- Your `ApplicationCable::Connection` identifies `current_user` — the channel rejects
|
|
27
|
+
anonymous subscriptions. Identify `user_role` too if you want moderation:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
# app/channels/application_cable/connection.rb
|
|
31
|
+
module ApplicationCable
|
|
32
|
+
class Connection < ActionCable::Connection::Base
|
|
33
|
+
identified_by :current_user, :user_role
|
|
34
|
+
|
|
35
|
+
def connect
|
|
36
|
+
self.current_user = User.find_by(id: cookies.encrypted[:user_id]) || reject_unauthorized_connection
|
|
37
|
+
self.user_role = current_user.host? ? :host : :guest
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
```
|
|
19
42
|
|
|
20
43
|
Add the video chat container helper to any view where you want the chat interface:
|
|
21
44
|
|
|
@@ -35,10 +58,76 @@ Customize the video chat experience using options:
|
|
|
35
58
|
room_id,
|
|
36
59
|
current_user.id,
|
|
37
60
|
theme: 'light', # 'dark' (default) or 'light'
|
|
38
|
-
#
|
|
61
|
+
ice_servers: [ # optional override; prefer Fenetre.configure
|
|
62
|
+
{ urls: 'stun:stun.l.google.com:19302' },
|
|
63
|
+
{ urls: 'turn:turn.example.com:3478', username: 'u', credential: 'p' }
|
|
64
|
+
]
|
|
39
65
|
) %>
|
|
40
66
|
```
|
|
41
67
|
|
|
68
|
+
### ICE / TURN (required for real networks)
|
|
69
|
+
|
|
70
|
+
STUN alone is not enough for many NATs. Configure TURN in an initializer:
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
# config/initializers/fenetre.rb
|
|
74
|
+
Fenetre.configure do |c|
|
|
75
|
+
c.ice_servers = [
|
|
76
|
+
{ urls: 'stun:stun.l.google.com:19302' },
|
|
77
|
+
{ urls: 'turn:turn.example.com:3478', username: ENV.fetch('TURN_USER'), credential: ENV.fetch('TURN_PASS') }
|
|
78
|
+
]
|
|
79
|
+
c.video_width = 1280
|
|
80
|
+
c.video_height = 720
|
|
81
|
+
c.frame_rate = 30
|
|
82
|
+
c.max_video_bitrate = 2_500_000
|
|
83
|
+
c.max_audio_bitrate = 128_000
|
|
84
|
+
end
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Room policy lives on the server
|
|
88
|
+
|
|
89
|
+
Nothing a browser sends decides who gets in, how many people fit, or who may
|
|
90
|
+
moderate. Configure that in an initializer:
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
# config/initializers/fenetre.rb
|
|
94
|
+
Fenetre.configure do |c|
|
|
95
|
+
# Return false to reject the subscription outright.
|
|
96
|
+
c.authorize_room = ->(user, room_id) { Room.find_by(slug: room_id)&.member?(user) }
|
|
97
|
+
|
|
98
|
+
# Per-room settings, evaluated on every subscription.
|
|
99
|
+
c.room_options = lambda do |user, room_id|
|
|
100
|
+
{
|
|
101
|
+
max_participants: 8, # join is refused atomically once the room is full
|
|
102
|
+
room_locked: false, # when true, only a :host connection may subscribe
|
|
103
|
+
enable_private_chat: true, # required before a directed chat message is delivered
|
|
104
|
+
enable_screen_sharing: true, # false drops screen_share signals
|
|
105
|
+
room_topic: 'Daily standup' # broadcast with the join message
|
|
106
|
+
}
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Directed chat and moderation (`kick`, `mute`, `unmute`) are delivered only to the
|
|
112
|
+
target user's own stream, and only a connection whose `user_role` is `:host` may
|
|
113
|
+
moderate. Chat is trimmed to 2000 characters and always rendered as text.
|
|
114
|
+
|
|
115
|
+
### Presence across processes
|
|
116
|
+
|
|
117
|
+
The default presence store is process-local, which is correct for a single Puma
|
|
118
|
+
process and wrong for anything larger. Supply your own store with the same two
|
|
119
|
+
atomic methods (`join(room, user, limit)` returning the participant list or `nil`
|
|
120
|
+
when full, and `leave(room, user)`), backed by Redis or your database:
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
Fenetre.presence = MyRedisPresence.new
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Instrumentation
|
|
127
|
+
|
|
128
|
+
`join.fenetre` and `leave.fenetre` are emitted through `ActiveSupport::Notifications`
|
|
129
|
+
with `user_id` and `room_id` payloads.
|
|
130
|
+
|
|
42
131
|
### JavaScript Interaction (Optional)
|
|
43
132
|
|
|
44
133
|
While Fenetre works out-of-the-box, you can interact with the Stimulus controller (`fenetre--video-chat`) for advanced customization:
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// It's meant to be pinned in the importmap for use by the host application
|
|
3
|
-
|
|
4
|
-
// Re-export the main fenetre module
|
|
5
|
-
import "./fenetre.js"
|
|
6
|
-
|
|
7
|
-
// Load the controllers entrypoint using a relative path
|
|
8
|
-
import "./controllers/index.js"
|
|
9
|
-
|
|
10
|
-
// Export a basic API for the host application to use
|
|
11
|
-
export const Fenetre = {
|
|
12
|
-
version: "1.0.0",
|
|
13
|
-
// Add more public API methods as needed
|
|
14
|
-
}
|
|
1
|
+
export { application, register, VideoChatController } from "fenetre"
|
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// It's referenced by the importmap
|
|
3
|
-
|
|
4
|
-
import { Application } from "../vendor/stimulus.umd.js"
|
|
5
|
-
import VideoChatController from "./video_chat_controller.js"
|
|
6
|
-
|
|
7
|
-
const application = Application.start();
|
|
8
|
-
|
|
9
|
-
// Register controllers with Stimulus
|
|
10
|
-
application.register("fenetre--video-chat", VideoChatController)
|
|
11
|
-
|
|
12
|
-
// Expose the Stimulus application globally for testing and debugging
|
|
13
|
-
// This allows tests to access controllers through window.Stimulus.application
|
|
14
|
-
if (typeof window !== 'undefined') {
|
|
15
|
-
window.Stimulus = window.Stimulus || {};
|
|
16
|
-
window.Stimulus.application = application;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { application };
|
|
1
|
+
export { application } from "fenetre"
|