Class: LiveKit::SIPServiceClient

Inherits:
Twirp::Client
  • Object
show all
Includes:
AuthMixin
Defined in:
lib/livekit/sip_service_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AuthMixin

#auth_header

Constructor Details

#initialize(base_url, api_key: nil, api_secret: nil) ⇒ SIPServiceClient

Returns a new instance of SIPServiceClient.



11
12
13
14
15
# File 'lib/livekit/sip_service_client.rb', line 11

def initialize(base_url, api_key: nil, api_secret: nil)
  super(File.join(Utils.to_http_url(base_url), "/twirp"))
  @api_key = api_key
  @api_secret = api_secret
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



9
10
11
# File 'lib/livekit/sip_service_client.rb', line 9

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



9
10
11
# File 'lib/livekit/sip_service_client.rb', line 9

def api_secret
  @api_secret
end

Instance Method Details

#create_sip_dispatch_rule(rule, name: nil, trunk_ids: nil, inbound_numbers: nil, hide_phone_number: nil, metadata: nil, attributes: nil) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/livekit/sip_service_client.rb', line 124

def create_sip_dispatch_rule(
  rule,
  name: nil,
  trunk_ids: nil,
  inbound_numbers: nil,
  hide_phone_number: nil,
  metadata: nil,
  attributes: nil
)
  request = Proto::CreateSIPDispatchRuleRequest.new(
    rule: rule,
    name: name,
    trunk_ids: trunk_ids,
    inbound_numbers: inbound_numbers,
    hide_phone_number: hide_phone_number,
    metadata: ,
    attributes: attributes,
  )
  self.rpc(
    :CreateSIPDispatchRule,
    request,
    headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
  )
end

#create_sip_inbound_trunk(name, numbers, metadata: nil, allowed_addresses: nil, allowed_numbers: nil, auth_username: nil, auth_password: nil, headers: nil, headers_to_attributes: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
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/livekit/sip_service_client.rb', line 17

def create_sip_inbound_trunk(
  # name to identify the trunk
  name,
  # numbers associated with LiveKit SIP. The Trunk will only accept calls made to these numbers.
  numbers,
  # optional, metadata to attach to the trunk
  metadata: nil,
  # optional, CIDR or IPs that traffic is accepted from.
  allowed_addresses: nil,
  # CIDR or IPs that traffic is accepted from.
  allowed_numbers: nil,
  # optional, Username and password used to authenticate inbound SIP invites.
  auth_username: nil,
  auth_password: nil,
  # optional, include these SIP X-* headers in 200 OK responses.
  headers: nil,
  # optional map SIP X-* headers from INVITE to SIP participant attributes.
  headers_to_attributes: nil
)
  request = Proto::CreateSIPInboundTrunkRequest.new(
    trunk: Proto::SIPInboundTrunkInfo.new(
      name: name,
      metadata: ,
      numbers: numbers,
      allowed_addresses: allowed_addresses,
      allowed_numbers: allowed_numbers,
      auth_username: auth_username,
      auth_password: auth_password,
      headers: headers,
      headers_to_attributes: headers_to_attributes
    )
  )
  self.rpc(
    :CreateSIPInboundTrunk,
    request,
    headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
  )
end

#create_sip_outbound_trunk(name, address, numbers, metadata: nil, transport: nil, auth_username: nil, auth_password: nil, headers: nil, headers_to_attributes: nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/livekit/sip_service_client.rb', line 56

def create_sip_outbound_trunk(
  # name to identify the trunk
  name,
  # Hostname or IP that SIP INVITE is sent too.
  address,
  # Numbers used to make the calls. Random one from this list will be selected.
  numbers,
  # optional, metadata to attach to the trunk
  metadata: nil,
  # SIP Transport used for outbound call.
  transport: nil,
  # optional, Username and password used to authenticate inbound SIP invites.
  auth_username: nil,
  auth_password: nil,
  # optional, include these SIP X-* headers in 200 OK responses.
  headers: nil,
  # optional map SIP X-* headers from INVITE to SIP participant attributes.
  headers_to_attributes: nil
)
  request = Proto::CreateSIPOutboundTrunkRequest.new(
    trunk: Proto::SIPOutboundTrunkInfo.new(
      name: name,
      address: address,
      numbers: numbers,
      metadata: ,
      transport: transport,
      auth_username: auth_username,
      auth_password: auth_password,
      headers: headers,
      headers_to_attributes: headers_to_attributes
    )
  )
  self.rpc(
    :CreateSIPOutboundTrunk,
    request,
    headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
  )
end

#create_sip_participant(sip_trunk_id, sip_call_to, room_name, participant_identity: nil, participant_name: nil, participant_metadata: nil, dtmf: nil, play_ringtone: nil, play_dialtone: nil, hide_phone_number: nil) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/livekit/sip_service_client.rb', line 169

def create_sip_participant(
  sip_trunk_id,
  sip_call_to,
  room_name,
  participant_identity: nil,
  participant_name: nil,
  participant_metadata: nil,
  dtmf: nil,
  play_ringtone: nil, # deprecated, use play_dialtone
  play_dialtone: nil,
  hide_phone_number: nil
)

  if (play_ringtone == true || play_dialtone == true)
    play_dialtone = true
    play_ringtone = true
  end

  request = Proto::CreateSIPParticipantRequest.new(
    sip_trunk_id: sip_trunk_id,
    sip_call_to: sip_call_to,
    room_name: room_name,
    participant_identity: participant_identity,
    participant_name: participant_name,
    participant_metadata: ,
    dtmf: dtmf,
    play_ringtone: play_ringtone,
    play_dialtone: play_dialtone,
    hide_phone_number: hide_phone_number,
  )
  self.rpc(
    :CreateSIPParticipant,
    request,
    headers: auth_header(sip_grant: SIPGrant.new(call: true)),
  )
end

#delete_sip_dispatch_rule(sip_dispatch_rule_id) ⇒ Object



158
159
160
161
162
163
164
165
166
167
# File 'lib/livekit/sip_service_client.rb', line 158

def delete_sip_dispatch_rule(sip_dispatch_rule_id)
  request = Proto::DeleteSIPDispatchRuleRequest.new(
    sip_dispatch_rule_id: sip_dispatch_rule_id,
  )
  self.rpc(
    :DeleteSIPDispatchRule,
    request,
    headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
  )
end

#delete_sip_trunk(sip_trunk_id) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/livekit/sip_service_client.rb', line 113

def delete_sip_trunk(sip_trunk_id)
  request = Proto::DeleteSIPTrunkRequest.new(
    sip_trunk_id: sip_trunk_id,
  )
  self.rpc(
    :DeleteSIPTrunk,
    request,
    headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
  )
end

#list_sip_dispatch_ruleObject



149
150
151
152
153
154
155
156
# File 'lib/livekit/sip_service_client.rb', line 149

def list_sip_dispatch_rule
  request = Proto::ListSIPDispatchRuleRequest.new
  self.rpc(
    :ListSIPDispatchRule,
    request,
    headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
  )
end

#list_sip_inbound_trunkObject



95
96
97
98
99
100
101
102
# File 'lib/livekit/sip_service_client.rb', line 95

def list_sip_inbound_trunk
  request = Proto::ListSIPInboundTrunkRequest.new
  self.rpc(
    :ListSIPInboundTrunk,
    request,
    headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
  )
end

#list_sip_outbound_trunkObject



104
105
106
107
108
109
110
111
# File 'lib/livekit/sip_service_client.rb', line 104

def list_sip_outbound_trunk
  request = Proto::ListSIPOutboundTrunkRequest.new
  self.rpc(
    :ListSIPOutboundTrunk,
    request,
    headers: auth_header(sip_grant: SIPGrant.new(admin: true)),
  )
end

#transfer_sip_participant(room_name, participant_identity, transfer_to, play_dialtone: nil) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/livekit/sip_service_client.rb', line 206

def transfer_sip_participant(
  room_name,
  participant_identity,
  transfer_to,
  play_dialtone: nil
)

  request = Proto::TransferSIPParticipantRequest.new(
    room_name: room_name,
    participant_identity: participant_identity,
    transfer_to: transfer_to,
    play_dialtone: play_dialtone,
  )
  self.rpc(
    :TransferSIPParticipant,
    request,
    headers: auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room_name), sip_grant: SIPGrant.new(call: true)),
  )
end