Class: KurentoWebsocketsController

Inherits:
WebsocketRails::BaseController
  • Object
show all
Defined in:
lib/generators/kurento_rails/templates/controllers/kurento_websockets_controller.rb

Instance Method Summary collapse

Instance Method Details

#active_streamsObject

just to see if this can make things work def process_action(method, event)

puts "Calling process action with method #{method} and event #{event}"
super(method, event)

end



10
11
12
13
14
# File 'lib/generators/kurento_rails/templates/controllers/kurento_websockets_controller.rb', line 10

def active_streams
  search_params = message.merge streaming: true
  streams = KurentoRailsVideoStream.where(search_params)
  trigger_success streams
end

#broadcastObject

tell all users that a new video is available



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/kurento_rails/templates/controllers/kurento_websockets_controller.rb', line 23

def broadcast
  stream = KurentoRailsVideoStream.new(stream_params(message))
  if stream.save
    # notify any people watching active streams that this stream is available
    WebsocketRails[:video_streams].trigger 'new', stream
    # store the fact that this user was broadcasting
    connection_store[:streaming] = stream.id
    # and now trigger the success callback
    trigger_success stream
  else
    trigger_failure stream
  end
end

#recorded_streamsObject



16
17
18
19
20
# File 'lib/generators/kurento_rails/templates/controllers/kurento_websockets_controller.rb', line 16

def recorded_streams
  search_params = message.merge streaming: false
  streams = KurentoRailsVideoStream.where(search_params)
  trigger_success streams
end

#stop_broadcastingObject

tell all users that this broadcast is no longer streaming



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/kurento_rails/templates/controllers/kurento_websockets_controller.rb', line 38

def stop_broadcasting
  stream = KurentoRailsVideoStream.find(connection_store[:streaming])
  stream.streaming = false
  if stream.save
    # perform the relevant stop streaming actions
    stop_streaming stream
    # and finally, trigger the success callback
    trigger_success stream
  else
    trigger_failure stream
  end
end

#user_disconnectObject

handle a user disconnecting from rails. Usually, this would happen because the user refreshes the page



64
65
66
67
68
69
70
71
# File 'lib/generators/kurento_rails/templates/controllers/kurento_websockets_controller.rb', line 64

def user_disconnect
  # check to see if the user was broadcasting video. If they were, then we need
  # to notify all users viewing their channel that they're no longer broadcasting
  if connection_store[:streaming]
    stream = KurentoRailsVideoStream.find(connection_store[:streaming])
    stop_streaming stream
  end
end

#viewObject

let a user know if a video is available for streaming or not



52
53
54
55
56
57
58
59
60
# File 'lib/generators/kurento_rails/templates/controllers/kurento_websockets_controller.rb', line 52

def view
  stream = KurentoRailsVideoStream.find(stream_params(message)[:id])
  # if this stream is active, great
  if stream.streaming
    trigger_success stream
  else
    trigger_failure stream
  end
end