Class: Vonage::Video

Inherits:
Namespace
  • Object
show all
Defined in:
lib/vonage/video.rb

Defined Under Namespace

Classes: Archives, Broadcasts, Captions, Moderation, Renders, SIP, Signals, Streams, WebSocket

Instance Method Summary collapse

Instance Method Details

#archivesArchives

Returns:



82
83
84
# File 'lib/vonage/video.rb', line 82

def archives
  @archives ||= Archives.new(@config)
end

#broadcastsBroadcasts

Returns:



88
89
90
# File 'lib/vonage/video.rb', line 88

def broadcasts
  @broadcasts ||= Broadcasts.new(@config)
end

#captionsCaptions

Returns:



112
113
114
# File 'lib/vonage/video.rb', line 112

def captions
  @captions ||= Captions.new(@config)
end

#create_session(**params) ⇒ Response

Generate a new session.

Examples:

session = client.video.create_session({
  archive_mode: 'always',
  location: '10.1.200.30',
  media_mode: 'routed'
})

Parameters:

  • :location (optional, String)

Returns:

See Also:

  • Add document link here


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vonage/video.rb', line 31

def create_session(**params)
  request_params = params.clone
  request_params[:archive_mode] ||= 'manual'
  media_mode = request_params.delete(:media_mode) || 'routed'

  if media_mode == 'relayed' && request_params[:archive_mode] == 'manual'
    request_params['p2p.preference'] = 'enabled'
  else
    request_params['p2p.preference'] = 'disabled'
  end

  response = request('/session/create', params: camelcase(request_params), type: Post)

  public_response_data = {
    session_id: response.entity.first.session_id,
    archive_mode: request_params[:archive_mode],
    media_mode: media_mode,
    location: request_params[:location]
  }

  entity = Entity.new(public_response_data)

  response.class.new(entity, response.http_response)
end

#generate_client_token(session_id:, scope: 'session.connect', role: 'publisher', **params) ⇒ Object

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/vonage/video.rb', line 56

def generate_client_token(session_id:, scope: 'session.connect', role: 'publisher', **params)
  valid_roles = %w[publisher subscriber moderator publisheronly]
  raise ArgumentError, "Invalid role: #{role}" unless valid_roles.include?(role)

  claims = {
    application_id: @config.application_id,
    scope: scope,
    session_id: session_id,
    role: role,
    initial_layout_class_list: '',
    sub: 'video',
    acl: {
      paths: {'/session/**' => {}}
    }
  }


  claims[:data] = params[:data] if params[:data]
  claims[:initial_layout_class_list] = params[:initial_layout_class_list].join(' ') if params[:initial_layout_class_list]
  claims[:exp] = params[:expire_time].to_i if params[:expire_time]

  JWT.generate(claims, @config.private_key)
end

#moderationModeration

Returns:



94
95
96
# File 'lib/vonage/video.rb', line 94

def moderation
  @moderation ||= Moderation.new(@config)
end

#rendersRenders

Returns:



118
119
120
# File 'lib/vonage/video.rb', line 118

def renders
  @renders ||= Renders.new(@config)
end

#signalsSignals

Returns:



100
101
102
# File 'lib/vonage/video.rb', line 100

def signals
  @signals ||= Signals.new(@config)
end

#streamsStreams

Returns:



106
107
108
# File 'lib/vonage/video.rb', line 106

def streams
  @streams ||= Streams.new(@config)
end

#web_socketWebSocket

Returns:



124
125
126
# File 'lib/vonage/video.rb', line 124

def web_socket
  @web_socket ||= WebSocket.new(@config)
end