Class: Proctoring::VideoStreaming

Inherits:
ApplicationRecord show all
Defined in:
app/models/proctoring/video_streaming.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.open_join_channel(user_id, event_id) ⇒ Object



37
38
39
40
41
42
43
# File 'app/models/proctoring/video_streaming.rb', line 37

def self.open_join_channel(user_id, event_id)
  video_streaming = VideoStreaming.find_by(event_id: event_id, user_id: user_id)
  unless video_streaming
    video_streaming = VideoStreaming.create(event_id: event_id, user_id: user_id)
  end
  video_streaming
end

.setup_rooms(event_id, no_of_users_in_channel) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/proctoring/video_streaming.rb', line 20

def self.setup_rooms(event_id, no_of_users_in_channel)
  @channels = VideoStreaming.by_event(event_id).active.pluck(:channel)
  video_streaming_room = VideoStreamingRoom.where(event_id: event_id, total_users: no_of_users_in_channel).active
  if (video_streaming_room.length.positive?)
    channels_in_room = video_streaming_room.pluck(:channels)&.flatten
    return if @channels == channels_in_room
    video_streaming_room.map(&:closed!)
  end

  channels_by_room = @channels.each_slice(no_of_users_in_channel).to_a if @channels.length.positive? && no_of_users_in_channel.positive?
  VideoStreaming.transaction do
    channels_by_room.each do |channels|
      VideoStreamingRoom.create(event_id: event_id, total_users: no_of_users_in_channel, channels: channels)
    end
  end
end

Instance Method Details

#all_attached_videos_sign_idsObject



16
17
18
# File 'app/models/proctoring/video_streaming.rb', line 16

def all_attached_videos_sign_ids
  videos.map(&:signed_id)
end