Rename Rooms to VideoRooms
This commit is contained in:
parent
7f584876ce
commit
6ff340f58b
@ -1,15 +1,15 @@
|
||||
import { Controller } from '@hotwired/stimulus'
|
||||
import Client from 'models/client'
|
||||
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'
|
||||
|
||||
export default class RoomController extends Controller {
|
||||
export default class VideoRoomController extends Controller {
|
||||
connect() {
|
||||
this.clients = {}
|
||||
this.client = new Client(this.clientIdValue)
|
||||
|
||||
this.subscription = new RoomSubscription({
|
||||
this.subscription = new VideoRoomSubscription({
|
||||
delegate: this,
|
||||
id: this.idValue,
|
||||
clientId: this.client.id
|
||||
@ -120,9 +120,9 @@ export default class RoomController extends Controller {
|
||||
return this.clients[id].negotiation
|
||||
}
|
||||
|
||||
// RoomSubscription Delegate
|
||||
// VideoRoomSubscription Delegate
|
||||
|
||||
roomPinged (data) {
|
||||
videoRoomPinged (data) {
|
||||
this.greetNewClient(data)
|
||||
}
|
||||
|
||||
@ -143,5 +143,5 @@ export default class RoomController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
RoomController.values = { id: String, clientId: String }
|
||||
RoomController.targets = ['localMedium', 'remoteMedium', 'enter']
|
||||
VideoRoomController.values = { id: String, clientId: String }
|
||||
VideoRoomController.targets = ['localMedium', 'remoteMedium', 'enter']
|
||||
@ -1,6 +1,6 @@
|
||||
import { cable } from '@hotwired/turbo-rails'
|
||||
|
||||
export default class RoomSubscription {
|
||||
export default class VideoRoomSubscription {
|
||||
constructor ({ delegate, id, clientId }) {
|
||||
this.delegate = delegate
|
||||
this.id = id
|
||||
@ -11,7 +11,7 @@ export default class RoomSubscription {
|
||||
const self = this
|
||||
|
||||
this.subscription = await cable.subscribeTo({
|
||||
channel: 'RoomChannel',
|
||||
channel: 'VideoRoomChannel',
|
||||
id: this.id,
|
||||
client_id: this.clientId
|
||||
}, {
|
||||
@ -23,8 +23,7 @@ export default class RoomSubscription {
|
||||
// Ignore self-sent data
|
||||
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
|
||||
@ -1,9 +1,9 @@
|
||||
class SignalingChannel < ApplicationCable::Channel
|
||||
def subscribed
|
||||
stream_for Room.new(id: params[:id])
|
||||
stream_for VideoRoom.new(id: params[:id])
|
||||
end
|
||||
|
||||
def signal(data)
|
||||
broadcast_to(Room.new(id: params[:id]), data)
|
||||
broadcast_to(VideoRoom.new(id: params[:id]), data)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
class RoomChannel < ApplicationCable::Channel
|
||||
class VideoRoomChannel < ApplicationCable::Channel
|
||||
def subscribed
|
||||
@room = find_room
|
||||
stream_for @room
|
||||
broadcast_to @room, { type: 'ping', from: params[:client_id] }
|
||||
@video_room = find_video_room
|
||||
stream_for @video_room
|
||||
broadcast_to @video_room, { type: 'ping', from: params[:client_id] }
|
||||
end
|
||||
|
||||
def unsubscribed
|
||||
Turbo::StreamsChannel.broadcast_remove_to(
|
||||
find_room,
|
||||
find_video_room,
|
||||
target: "medium_#{current_client.id}"
|
||||
)
|
||||
end
|
||||
@ -23,7 +23,7 @@ class RoomChannel < ApplicationCable::Channel
|
||||
|
||||
private
|
||||
|
||||
def find_room
|
||||
Room.new(id: params[:id])
|
||||
def find_video_room
|
||||
VideoRoom.new(id: params[:id])
|
||||
end
|
||||
end
|
||||
@ -1,4 +1,4 @@
|
||||
class RoomsController < ApplicationController
|
||||
class VideoRoomsController < ApplicationController
|
||||
before_action :skip_authorization
|
||||
|
||||
def new
|
||||
@ -11,6 +11,6 @@ class RoomsController < ApplicationController
|
||||
def show
|
||||
@client = Client.new(id: SecureRandom.uuid)
|
||||
cookies.encrypted[:client_id] = @client.id
|
||||
@room = Room.new(id: params[:id])
|
||||
@video_room = VideoRoom.new(id: params[:id])
|
||||
end
|
||||
end
|
||||
@ -1,15 +1,15 @@
|
||||
import { Controller } from '@hotwired/stimulus'
|
||||
import Client from 'models/client'
|
||||
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'
|
||||
|
||||
export default class RoomController extends Controller {
|
||||
export default class VideoRoomController extends Controller {
|
||||
connect() {
|
||||
this.clients = {}
|
||||
this.client = new Client(this.clientIdValue)
|
||||
|
||||
this.subscription = new RoomSubscription({
|
||||
this.subscription = new VideoRoomSubscription({
|
||||
delegate: this,
|
||||
id: this.idValue,
|
||||
clientId: this.client.id
|
||||
@ -120,9 +120,9 @@ export default class RoomController extends Controller {
|
||||
return this.clients[id].negotiation
|
||||
}
|
||||
|
||||
// RoomSubscription Delegate
|
||||
// VideoRoomSubscription Delegate
|
||||
|
||||
roomPinged (data) {
|
||||
videoRoomPinged (data) {
|
||||
this.greetNewClient(data)
|
||||
}
|
||||
|
||||
@ -143,5 +143,5 @@ export default class RoomController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
RoomController.values = { id: String, clientId: String }
|
||||
RoomController.targets = ['localMedium', 'remoteMedium', 'enter']
|
||||
VideoRoomController.values = { id: String, clientId: String }
|
||||
VideoRoomController.targets = ['localMedium', 'remoteMedium', 'enter']
|
||||
@ -1,6 +1,6 @@
|
||||
import { cable } from '@hotwired/turbo-rails'
|
||||
|
||||
export default class RoomSubscription {
|
||||
export default class VideoRoomSubscription {
|
||||
constructor ({ delegate, id, clientId }) {
|
||||
this.delegate = delegate
|
||||
this.id = id
|
||||
@ -11,7 +11,7 @@ export default class RoomSubscription {
|
||||
const self = this
|
||||
|
||||
this.subscription = await cable.subscribeTo({
|
||||
channel: 'RoomChannel',
|
||||
channel: 'VideoRoomChannel',
|
||||
id: this.id,
|
||||
client_id: this.clientId
|
||||
}, {
|
||||
@ -23,7 +23,7 @@ export default class RoomSubscription {
|
||||
// Ignore self-sent data
|
||||
if (data.from === self.clientId) return
|
||||
|
||||
if (data.type === 'ping') self.delegate.roomPinged(data)
|
||||
if (data.type === 'ping') self.delegate.videoRoomPinged(data)
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
class Room
|
||||
class VideoRoom
|
||||
attr_reader :id
|
||||
|
||||
def initialize(id:)
|
||||
@ -2,7 +2,7 @@
|
||||
class="medium"
|
||||
id="medium_<%= client_id %>"
|
||||
data-controller="medium"
|
||||
data-room-target="remoteMedium"
|
||||
data-video-room-target="remoteMedium"
|
||||
>
|
||||
<video autoplay playsinline data-medium-target="mediaElement"></video>
|
||||
</div>
|
||||
|
||||
@ -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>
|
||||
@ -1,3 +1,3 @@
|
||||
<%= form_with url: rooms_path do |form| %>
|
||||
<%= form.submit 'Create Room' %>
|
||||
<%= form.submit 'Create VideoRoom' %>
|
||||
<% end %>
|
||||
19
app/views/video_rooms/show.html.erb
Normal file
19
app/views/video_rooms/show.html.erb
Normal 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>
|
||||
@ -83,7 +83,7 @@ Rails.application.routes.draw do
|
||||
get '/wallet', to: 'visitors#wallet'
|
||||
resources :calls, only: :create
|
||||
mount ActionCable.server, at: '/cable'
|
||||
resources :rooms, only: [:new, :create, :show]
|
||||
resources :video_rooms, only: [:new, :create, :show]
|
||||
resources :users do
|
||||
member do
|
||||
get :following
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user