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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d742e322e7ed6c94bc26878f732121911872fef3823dea593eb4141ee9c1280
4
- data.tar.gz: a6e1d6633311adf8c02aacd849cbfa262e3d50e9d1810504a1ac8bbb649c5e72
3
+ metadata.gz: c218d212f99120aa8c395fc9f6848fd47cf55ab062ec7cc8e072f57b1f598f3a
4
+ data.tar.gz: 391ec2ec6dfca02e59dacbd2d13b2dbd170cfcbdde49a82c432fa9a4150324ad
5
5
  SHA512:
6
- metadata.gz: 04e8007aae26b6c7d48d9071cd6faef061152e62c38907f346101538ff5581fa52104e20a41ccea712984b53682302f7f4e2c7ada1283253cde2aa6d7606ec36
7
- data.tar.gz: d50582f711a81470a52739c95691a31e72529e9236dc68738489699cee5869284d4bbd81153c6be70498e772ef54e29fe7c7f52c5e3b70186994e30e8e8819a0
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
  [![CI Status](https://github.com/andrewfader/fenetre/workflows/CI/badge.svg)](https://github.com/andrewfader/fenetre/actions)
4
- [![Coverage Status](https://img.shields.io/badge/coverage-78.9%25-yellow.svg)](coverage/index.html)
4
+ [![Coverage Status](https://img.shields.io/badge/coverage-90.2%25-yellow.svg)](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
- Fenetre automatically handles most of the necessary setup when used with `importmap-rails`:
10
+ Add the gem, then import it once from your entrypoint:
11
11
 
12
- - Mounting the Action Cable server at `/cable` (if not already mounted).
13
- - Making the Stimulus controllers available via the import map.
14
- - Making the view helper available.
12
+ ```javascript
13
+ // app/javascript/application.js
14
+ import "fenetre"
15
+ ```
15
16
 
16
- **Important:**
17
- - Your host application **must** use `importmap-rails`.
18
- - Your host application's `app/javascript/application.js` should load Stimulus controllers (e.g., contain `import "./controllers"`).
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
- # Add other options as needed based on helper definition
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
- // This serves as an entry point for Fenetre JavaScript
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
- // This file loads all Stimulus controllers in the fenetre engine
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"