Class: LiveKit::SIPServiceClient
- Inherits:
-
Twirp::Client
- Object
- Twirp::Client
- LiveKit::SIPServiceClient
- Includes:
- AuthMixin
- Defined in:
- lib/livekit/sip_service_client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
Instance Method Summary collapse
- #create_sip_dispatch_rule(rule, name: nil, trunk_ids: nil, inbound_numbers: nil, hide_phone_number: nil, metadata: nil, attributes: nil, room_config: nil) ⇒ Object
- #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, include_headers: Proto::SIPHeaderOptions::SIP_NO_HEADERS, krisp_enabled: false) ⇒ Object
- #create_sip_outbound_trunk(name, address, numbers, metadata: nil, transport: nil, auth_username: nil, auth_password: nil, headers: nil, headers_to_attributes: nil) ⇒ Object
- #create_sip_participant(sip_trunk_id, sip_call_to, room_name, trunk: nil, from_number: nil, display_name: nil, participant_identity: nil, participant_name: nil, participant_metadata: nil, dtmf: nil, play_dialtone: false, hide_phone_number: nil, ringing_timeout: nil, max_call_duration: nil, krisp_enabled: false, wait_until_answered: false, timeout: nil) ⇒ Object
- #delete_sip_dispatch_rule(sip_dispatch_rule_id) ⇒ Object
- #delete_sip_trunk(sip_trunk_id) ⇒ Object
-
#initialize(base_url, api_key: nil, api_secret: nil, token: nil, failover: true, connection: nil) ⇒ SIPServiceClient
constructor
A new instance of SIPServiceClient.
- #list_sip_dispatch_rule ⇒ Object
- #list_sip_inbound_trunk ⇒ Object
- #list_sip_outbound_trunk ⇒ Object
- #transfer_sip_participant(room_name, participant_identity, transfer_to, play_dialtone: nil, ringing_timeout: nil, timeout: nil) ⇒ Object
-
#update_sip_dispatch_rule(sip_dispatch_rule_id, rule) ⇒ Object
Updates an existing SIP dispatch rule, replacing it entirely.
-
#update_sip_dispatch_rule_fields(sip_dispatch_rule_id, update) ⇒ Object
Updates specific fields of an existing SIP dispatch rule.
-
#update_sip_inbound_trunk(sip_trunk_id, trunk) ⇒ Object
Updates an existing SIP inbound trunk, replacing it entirely.
-
#update_sip_inbound_trunk_fields(sip_trunk_id, update) ⇒ Object
Updates specific fields of an existing SIP inbound trunk.
-
#update_sip_outbound_trunk(sip_trunk_id, trunk) ⇒ Object
Updates an existing SIP outbound trunk, replacing it entirely.
-
#update_sip_outbound_trunk_fields(sip_trunk_id, update) ⇒ Object
Updates specific fields of an existing SIP outbound trunk.
Methods included from AuthMixin
Constructor Details
#initialize(base_url, api_key: nil, api_secret: nil, token: nil, failover: true, connection: nil) ⇒ SIPServiceClient
Returns a new instance of SIPServiceClient.
13 14 15 16 17 18 |
# File 'lib/livekit/sip_service_client.rb', line 13 def initialize(base_url, api_key: nil, api_secret: nil, token: nil, failover: true, connection: nil) super(connection || LiveKit::Failover.connection(base_url, failover)) @api_key = api_key @api_secret = api_secret @token = token end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/livekit/sip_service_client.rb', line 11 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
11 12 13 |
# File 'lib/livekit/sip_service_client.rb', line 11 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, room_config: nil) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/livekit/sip_service_client.rb', line 133 def create_sip_dispatch_rule( rule, name: nil, trunk_ids: nil, inbound_numbers: nil, hide_phone_number: nil, metadata: nil, attributes: nil, room_config: 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, room_config: room_config, ) 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, include_headers: Proto::SIPHeaderOptions::SIP_NO_HEADERS, krisp_enabled: false) ⇒ Object
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 55 56 57 58 59 60 61 62 63 |
# File 'lib/livekit/sip_service_client.rb', line 20 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, # optional, map SIP response headers from INVITE to sip.h.* participant attributes automatically. include_headers: Proto::SIPHeaderOptions::SIP_NO_HEADERS, # optional, enable Krisp for this trunk krisp_enabled: false ) 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, include_headers: include_headers, krisp_enabled: krisp_enabled ) ) 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
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 94 95 96 97 98 99 100 101 102 |
# File 'lib/livekit/sip_service_client.rb', line 65 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 ) ) rpc!( :CreateSIPOutboundTrunk, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#create_sip_participant(sip_trunk_id, sip_call_to, room_name, trunk: nil, from_number: nil, display_name: nil, participant_identity: nil, participant_name: nil, participant_metadata: nil, dtmf: nil, play_dialtone: false, hide_phone_number: nil, ringing_timeout: nil, max_call_duration: nil, krisp_enabled: false, wait_until_answered: false, timeout: nil) ⇒ Object
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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/livekit/sip_service_client.rb', line 180 def create_sip_participant( sip_trunk_id, sip_call_to, room_name, # Optional inline outbound trunk configuration (SIPOutboundConfig). Use # instead of a stored sip_trunk_id to configure the trunk per call. trunk: nil, # Optional SIP From number to use. If empty, trunk number is used. from_number: nil, # Optional custom caller ID shown to the callee. Requires provider support. display_name: nil, # Optional identity of the participant in LiveKit room participant_identity: nil, # Optional name of the participant in LiveKit room participant_name: nil, # Optional metadata of the participant in LiveKit room participant_metadata: nil, # Optional, send following DTMF digits (extension codes) when making a call. # Character 'w' can be used to add a 0.5 sec delay. dtmf: nil, # Optional, play dialtone for the participant play_dialtone: false, # Optional, hide phone number from participant attributes hide_phone_number: nil, # Optional, ringing timeout in seconds ringing_timeout: nil, # Optional, max call duration in seconds max_call_duration: nil, # Optional, enable Krisp for this call krisp_enabled: false, # Optional, wait for the call to be answered before returning wait_until_answered: false, # Optional, request timeout in seconds. Defaults to a longer value when # wait_until_answered is set (dialing takes time). timeout: nil ) # When waiting for an answer, pin the ring window explicitly so our request # timeout doesn't depend on the server's default (which could change). ringing_timeout = DialTimeout::DEFAULT_RINGING_TIMEOUT if wait_until_answered && ringing_timeout.nil? request = Proto::CreateSIPParticipantRequest.new( sip_trunk_id: sip_trunk_id, trunk: trunk, sip_call_to: sip_call_to, sip_number: from_number, display_name: display_name, room_name: room_name, participant_identity: participant_identity, participant_name: participant_name, participant_metadata: , dtmf: dtmf, play_dialtone: play_dialtone, hide_phone_number: hide_phone_number, ringing_timeout: ringing_timeout, max_call_duration: max_call_duration, krisp_enabled: krisp_enabled, wait_until_answered: wait_until_answered ) headers = auth_header(sip_grant: SIPGrant.new(call: true)) # When waiting for an answer, dialing takes longer than a normal request # and the request must outlast ringing; otherwise honor any user timeout. effective_timeout = wait_until_answered ? DialTimeout.resolve(timeout, ringing_timeout) : timeout headers[Failover::TIMEOUT_HEADER] = effective_timeout.to_s if effective_timeout rpc!(:CreateSIPParticipant, request, headers: headers) end |
#delete_sip_dispatch_rule(sip_dispatch_rule_id) ⇒ Object
169 170 171 172 173 174 175 176 177 178 |
# File 'lib/livekit/sip_service_client.rb', line 169 def delete_sip_dispatch_rule(sip_dispatch_rule_id) request = Proto::DeleteSIPDispatchRuleRequest.new( sip_dispatch_rule_id: sip_dispatch_rule_id, ) rpc!( :DeleteSIPDispatchRule, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#delete_sip_trunk(sip_trunk_id) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/livekit/sip_service_client.rb', line 122 def delete_sip_trunk(sip_trunk_id) request = Proto::DeleteSIPTrunkRequest.new( sip_trunk_id: sip_trunk_id, ) rpc!( :DeleteSIPTrunk, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#list_sip_dispatch_rule ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'lib/livekit/sip_service_client.rb', line 160 def list_sip_dispatch_rule request = Proto::ListSIPDispatchRuleRequest.new rpc!( :ListSIPDispatchRule, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#list_sip_inbound_trunk ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/livekit/sip_service_client.rb', line 104 def list_sip_inbound_trunk request = Proto::ListSIPInboundTrunkRequest.new rpc!( :ListSIPInboundTrunk, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#list_sip_outbound_trunk ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/livekit/sip_service_client.rb', line 113 def list_sip_outbound_trunk request = Proto::ListSIPOutboundTrunkRequest.new 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, ringing_timeout: nil, timeout: nil) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/livekit/sip_service_client.rb', line 245 def transfer_sip_participant( room_name, participant_identity, transfer_to, play_dialtone: nil, # Optional, max time for the transfer destination to answer, in seconds. ringing_timeout: nil, # Optional, request timeout in seconds. Defaults to a longer value since # transferring dials a phone. timeout: nil ) # Transferring a call dials a phone and must outlast ringing. Pin the ring # window explicitly so our request timeout doesn't depend on the server default. ringing_timeout ||= DialTimeout::DEFAULT_RINGING_TIMEOUT request = Proto::TransferSIPParticipantRequest.new( room_name: room_name, participant_identity: participant_identity, transfer_to: transfer_to, play_dialtone: play_dialtone, ringing_timeout: ringing_timeout, ) headers = auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room_name), sip_grant: SIPGrant.new(call: true)) headers[Failover::TIMEOUT_HEADER] = DialTimeout.resolve(timeout, ringing_timeout).to_s rpc!(:TransferSIPParticipant, request, headers: headers) end |
#update_sip_dispatch_rule(sip_dispatch_rule_id, rule) ⇒ Object
Updates an existing SIP dispatch rule, replacing it entirely.
342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/livekit/sip_service_client.rb', line 342 def update_sip_dispatch_rule(sip_dispatch_rule_id, rule) request = Proto::UpdateSIPDispatchRuleRequest.new( sip_dispatch_rule_id: sip_dispatch_rule_id, replace: rule, ) rpc!( :UpdateSIPDispatchRule, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#update_sip_dispatch_rule_fields(sip_dispatch_rule_id, update) ⇒ Object
Updates specific fields of an existing SIP dispatch rule. Only the fields
set in update are changed.
359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/livekit/sip_service_client.rb', line 359 def update_sip_dispatch_rule_fields(sip_dispatch_rule_id, update) request = Proto::UpdateSIPDispatchRuleRequest.new( sip_dispatch_rule_id: sip_dispatch_rule_id, update: update, ) rpc!( :UpdateSIPDispatchRule, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#update_sip_inbound_trunk(sip_trunk_id, trunk) ⇒ Object
Updates an existing SIP inbound trunk, replacing it entirely.
276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/livekit/sip_service_client.rb', line 276 def update_sip_inbound_trunk(sip_trunk_id, trunk) request = Proto::UpdateSIPInboundTrunkRequest.new( sip_trunk_id: sip_trunk_id, replace: trunk, ) rpc!( :UpdateSIPInboundTrunk, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#update_sip_inbound_trunk_fields(sip_trunk_id, update) ⇒ Object
Updates specific fields of an existing SIP inbound trunk. Only the fields
set in update are changed.
293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/livekit/sip_service_client.rb', line 293 def update_sip_inbound_trunk_fields(sip_trunk_id, update) request = Proto::UpdateSIPInboundTrunkRequest.new( sip_trunk_id: sip_trunk_id, update: update, ) rpc!( :UpdateSIPInboundTrunk, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#update_sip_outbound_trunk(sip_trunk_id, trunk) ⇒ Object
Updates an existing SIP outbound trunk, replacing it entirely.
309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/livekit/sip_service_client.rb', line 309 def update_sip_outbound_trunk(sip_trunk_id, trunk) request = Proto::UpdateSIPOutboundTrunkRequest.new( sip_trunk_id: sip_trunk_id, replace: trunk, ) rpc!( :UpdateSIPOutboundTrunk, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |
#update_sip_outbound_trunk_fields(sip_trunk_id, update) ⇒ Object
Updates specific fields of an existing SIP outbound trunk. Only the fields
set in update are changed.
326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/livekit/sip_service_client.rb', line 326 def update_sip_outbound_trunk_fields(sip_trunk_id, update) request = Proto::UpdateSIPOutboundTrunkRequest.new( sip_trunk_id: sip_trunk_id, update: update, ) rpc!( :UpdateSIPOutboundTrunk, request, headers: auth_header(sip_grant: SIPGrant.new(admin: true)), ) end |