Rename Rooms to VideoRooms

This commit is contained in:
TheNeedful-DO 2023-12-03 16:02:22 +00:00
parent 916ba4f8a6
commit bcf00a1f18
13 changed files with 54 additions and 55 deletions

View File

@ -1,15 +1,15 @@
import { Controller } from '@hotwired/stimulus' import { Controller } from '@hotwired/stimulus'
import Client from 'models/client' import Client from 'models/client'
import WebrtcNegotiation from 'models/webrtc_negotiation' import WebrtcNegotiation from 'models/webrtc_negotiation'
import RoomSubscription from 'subscriptions/room_subscription' import VideoRoomSubscription from 'subscriptions/video_room_subscription'
import Signaller from 'subscriptions/signaling_subscription' import Signaller from 'subscriptions/signaling_subscription'
export default class RoomController extends Controller { export default class VideoRoomController extends Controller {
connect() { connect() {
this.clients = {} this.clients = {}
this.client = new Client(this.clientIdValue) this.client = new Client(this.clientIdValue)
this.subscription = new RoomSubscription({ this.subscription = new VideoRoomSubscription({
delegate: this, delegate: this,
id: this.idValue, id: this.idValue,
clientId: this.client.id clientId: this.client.id
@ -120,9 +120,9 @@ export default class RoomController extends Controller {
return this.clients[id].negotiation return this.clients[id].negotiation
} }
// RoomSubscription Delegate // VideoRoomSubscription Delegate
roomPinged (data) { videoRoomPinged (data) {
this.greetNewClient(data) this.greetNewClient(data)
} }
@ -143,5 +143,5 @@ export default class RoomController extends Controller {
} }
} }
RoomController.values = { id: String, clientId: String } VideoRoomController.values = { id: String, clientId: String }
RoomController.targets = ['localMedium', 'remoteMedium', 'enter'] VideoRoomController.targets = ['localMedium', 'remoteMedium', 'enter']

View File

@ -1,6 +1,6 @@
import { cable } from '@hotwired/turbo-rails' import { cable } from '@hotwired/turbo-rails'
export default class RoomSubscription { export default class VideoRoomSubscription {
constructor ({ delegate, id, clientId }) { constructor ({ delegate, id, clientId }) {
this.delegate = delegate this.delegate = delegate
this.id = id this.id = id
@ -11,7 +11,7 @@ export default class RoomSubscription {
const self = this const self = this
this.subscription = await cable.subscribeTo({ this.subscription = await cable.subscribeTo({
channel: 'RoomChannel', channel: 'VideoRoomChannel',
id: this.id, id: this.id,
client_id: this.clientId client_id: this.clientId
}, { }, {
@ -23,8 +23,7 @@ export default class RoomSubscription {
// Ignore self-sent data // Ignore self-sent data
if (data.from === self.clientId) return if (data.from === self.clientId) return
if (data.type === 'ping') self.delegate.roomPinged(data) if (data.type === 'ping') self.delegate.videoRoomPinged(data) }
}
}) })
this.started = true this.started = true

View File

@ -1,9 +1,9 @@
class SignalingChannel < ApplicationCable::Channel class SignalingChannel < ApplicationCable::Channel
def subscribed def subscribed
stream_for Room.new(id: params[:id]) stream_for VideoRoom.new(id: params[:id])
end end
def signal(data) def signal(data)
broadcast_to(Room.new(id: params[:id]), data) broadcast_to(VideoRoom.new(id: params[:id]), data)
end end
end end

View File

@ -1,13 +1,13 @@
class RoomChannel < ApplicationCable::Channel class VideoRoomChannel < ApplicationCable::Channel
def subscribed def subscribed
@room = find_room @video_room = find_video_room
stream_for @room stream_for @video_room
broadcast_to @room, { type: 'ping', from: params[:client_id] } broadcast_to @video_room, { type: 'ping', from: params[:client_id] }
end end
def unsubscribed def unsubscribed
Turbo::StreamsChannel.broadcast_remove_to( Turbo::StreamsChannel.broadcast_remove_to(
find_room, find_video_room,
target: "medium_#{current_client.id}" target: "medium_#{current_client.id}"
) )
end end
@ -23,7 +23,7 @@ class RoomChannel < ApplicationCable::Channel
private private
def find_room def find_video_room
Room.new(id: params[:id]) VideoRoom.new(id: params[:id])
end end
end end

View File

@ -1,4 +1,4 @@
class RoomsController < ApplicationController class VideoRoomsController < ApplicationController
before_action :skip_authorization before_action :skip_authorization
def new def new
@ -11,6 +11,6 @@ class RoomsController < ApplicationController
def show def show
@client = Client.new(id: SecureRandom.uuid) @client = Client.new(id: SecureRandom.uuid)
cookies.encrypted[:client_id] = @client.id cookies.encrypted[:client_id] = @client.id
@room = Room.new(id: params[:id]) @video_room = VideoRoom.new(id: params[:id])
end end
end end

View File

@ -1,15 +1,15 @@
import { Controller } from '@hotwired/stimulus' import { Controller } from '@hotwired/stimulus'
import Client from 'models/client' import Client from 'models/client'
import WebrtcNegotiation from 'models/webrtc_negotiation' import WebrtcNegotiation from 'models/webrtc_negotiation'
import RoomSubscription from 'subscriptions/room_subscription' import VideoRoomSubscription from 'subscriptions/video_room_subscription'
import Signaller from 'subscriptions/signaling_subscription' import Signaller from 'subscriptions/signaling_subscription'
export default class RoomController extends Controller { export default class VideoRoomController extends Controller {
connect() { connect() {
this.clients = {} this.clients = {}
this.client = new Client(this.clientIdValue) this.client = new Client(this.clientIdValue)
this.subscription = new RoomSubscription({ this.subscription = new VideoRoomSubscription({
delegate: this, delegate: this,
id: this.idValue, id: this.idValue,
clientId: this.client.id clientId: this.client.id
@ -120,9 +120,9 @@ export default class RoomController extends Controller {
return this.clients[id].negotiation return this.clients[id].negotiation
} }
// RoomSubscription Delegate // VideoRoomSubscription Delegate
roomPinged (data) { videoRoomPinged (data) {
this.greetNewClient(data) this.greetNewClient(data)
} }
@ -143,5 +143,5 @@ export default class RoomController extends Controller {
} }
} }
RoomController.values = { id: String, clientId: String } VideoRoomController.values = { id: String, clientId: String }
RoomController.targets = ['localMedium', 'remoteMedium', 'enter'] VideoRoomController.targets = ['localMedium', 'remoteMedium', 'enter']

View File

@ -1,6 +1,6 @@
import { cable } from '@hotwired/turbo-rails' import { cable } from '@hotwired/turbo-rails'
export default class RoomSubscription { export default class VideoRoomSubscription {
constructor ({ delegate, id, clientId }) { constructor ({ delegate, id, clientId }) {
this.delegate = delegate this.delegate = delegate
this.id = id this.id = id
@ -11,7 +11,7 @@ export default class RoomSubscription {
const self = this const self = this
this.subscription = await cable.subscribeTo({ this.subscription = await cable.subscribeTo({
channel: 'RoomChannel', channel: 'VideoRoomChannel',
id: this.id, id: this.id,
client_id: this.clientId client_id: this.clientId
}, { }, {
@ -23,7 +23,7 @@ export default class RoomSubscription {
// Ignore self-sent data // Ignore self-sent data
if (data.from === self.clientId) return if (data.from === self.clientId) return
if (data.type === 'ping') self.delegate.roomPinged(data) if (data.type === 'ping') self.delegate.videoRoomPinged(data)
} }
}) })

View File

@ -1,4 +1,4 @@
class Room class VideoRoom
attr_reader :id attr_reader :id
def initialize(id:) def initialize(id:)

View File

@ -2,7 +2,7 @@
class="medium" class="medium"
id="medium_<%= client_id %>" id="medium_<%= client_id %>"
data-controller="medium" data-controller="medium"
data-room-target="remoteMedium" data-video-room-target="remoteMedium"
> >
<video autoplay playsinline data-medium-target="mediaElement"></video> <video autoplay playsinline data-medium-target="mediaElement"></video>
</div> </div>

View File

@ -1,19 +0,0 @@
<%= turbo_stream_from @room %>
<%= turbo_stream_from @client.id %>
<article
class="room"
data-controller="room"
data-room-id-value="<%= @room.id %>"
data-room-client-id-value="<%= @client.id %>"
>
<div class="media" id="media">
<div class="medium medium--local" data-controller="medium">
<video data-room-target="localMedium" data-medium-target="mediaElement" muted autoplay playsinline></video>
<div class="medium-actions">
<%= button_tag 'Enter', data: { room_target: 'enter', action: 'room#enter' } %>
</div>
</div>
</div>
</article>

View File

@ -1,3 +1,3 @@
<%= form_with url: rooms_path do |form| %> <%= form_with url: rooms_path do |form| %>
<%= form.submit 'Create Room' %> <%= form.submit 'Create VideoRoom' %>
<% end %> <% end %>

View File

@ -0,0 +1,19 @@
<%= turbo_stream_from @video_room %>
<%= turbo_stream_from @client.id %>
<article
class="video_room"
data-controller="video_room"
data-video_room-id-value="<%= @video_room.id %>"
data-video_room-client-id-value="<%= @client.id %>"
>
<div class="media" id="media">
<div class="medium medium--local" data-controller="medium">
<video data-video_room-target="localMedium" data-medium-target="mediaElement" muted autoplay playsinline></video>
<div class="medium-actions">
<%= button_tag 'Enter', data: { video_room_target: 'enter', action: 'video_room#enter' } %>
</div>
</div>
</div>
</article>

View File

@ -83,7 +83,7 @@ Rails.application.routes.draw do
get '/wallet', to: 'visitors#wallet' get '/wallet', to: 'visitors#wallet'
resources :calls, only: :create resources :calls, only: :create
mount ActionCable.server, at: '/cable' mount ActionCable.server, at: '/cable'
resources :rooms, only: [:new, :create, :show] resources :video_rooms, only: [:new, :create, :show]
resources :users do resources :users do
member do member do
get :following get :following