-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch mod_rayo to fix idle timeout for connect verb (#971)
- Loading branch information
Showing
20 changed files
with
333 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class DisconnectTwilioStream < ApplicationWorkflow | ||
attr_reader :call_controller, :phone_call | ||
|
||
def initialize(call_controller) | ||
super() | ||
@call_controller = call_controller | ||
@phone_call = call_controller.call | ||
end | ||
|
||
def call | ||
phone_call.write_command(Rayo::Command::UpdateCallProgress.new(flag: 0)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class StartTwilioStream < ApplicationWorkflow | ||
attr_reader :call_controller, :phone_call, :call_properties, :url, :stream_sid, :custom_parameters | ||
|
||
def initialize(call_controller, **options) | ||
super() | ||
@call_controller = call_controller | ||
@phone_call = call_controller.call | ||
@call_properties = options.fetch(:call_properties) | ||
@url = options.fetch(:url) | ||
@stream_sid = options.fetch(:stream_sid) | ||
@custom_parameters = options.fetch(:custom_parameters) | ||
end | ||
|
||
def call | ||
call_controller.write_and_await_response( | ||
Rayo::Command::TwilioStream::Start.new( | ||
uuid: phone_call.id, | ||
url:, | ||
metadata: { | ||
call_sid: call_properties.call_sid, | ||
account_sid: call_properties.account_sid, | ||
stream_sid:, | ||
custom_parameters: | ||
} | ||
) | ||
) | ||
phone_call.write_command(Rayo::Command::UpdateCallProgress.new(flag: 1)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class StopTwilioStream < ApplicationWorkflow | ||
attr_reader :call_controller, :phone_call | ||
|
||
def initialize(call_controller) | ||
super() | ||
@call_controller = call_controller | ||
@phone_call = call_controller.call | ||
end | ||
|
||
def call | ||
call_controller.write_and_await_response(Rayo::Command::TwilioStream::Stop.new(uuid: phone_call.id)) | ||
DisconnectTwilioStream.call(call_controller) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ module Command | |
end | ||
|
||
require_relative "command/twilio_stream" | ||
require_relative "command/update_call_progress" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "adhearsion/rayo/command_node" | ||
|
||
module Rayo | ||
module Command | ||
class UpdateCallProgress < Adhearsion::Rayo::CommandNode | ||
register :call_progress, :core | ||
|
||
attribute :flag | ||
|
||
def rayo_attributes | ||
{ "flag" => flag } | ||
end | ||
end | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
components/app/spec/lib/rayo/command/update_call_progress_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "spec_helper" | ||
|
||
module Rayo | ||
module Command | ||
RSpec.describe UpdateCallProgress do | ||
describe "#to_xml" do | ||
it "serializes to Rayo XML" do | ||
xml = Hash.from_xml(UpdateCallProgress.new(flag: 1).to_xml) | ||
expect(xml.fetch("call_progress")).to include("flag" => "1") | ||
|
||
xml = Hash.from_xml(UpdateCallProgress.new(flag: 0).to_xml) | ||
expect(xml.fetch("call_progress")).to include("flag" => "0") | ||
end | ||
end | ||
end | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
components/app/spec/workflows/disconnect_twilio_stream_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe DisconnectTwilioStream, type: :call_controller do | ||
it "disconnects a twilio stream" do | ||
controller = build_controller | ||
|
||
DisconnectTwilioStream.call(controller) | ||
|
||
expect(controller.call).to have_received(:write_command).with( | ||
have_attributes( | ||
class: Rayo::Command::UpdateCallProgress, | ||
flag: 0 | ||
) | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe StartTwilioStream, type: :call_controller do | ||
it "starts a twilio stream" do | ||
controller = build_controller( | ||
stub_voice_commands: :write_and_await_response, | ||
call: build_fake_call(id: "call-id") | ||
) | ||
|
||
StartTwilioStream.call( | ||
controller, | ||
call_properties: build_call_properties(call_sid: "call-sid", account_sid: "account-sid"), | ||
url: "wss://example.com/audio", | ||
stream_sid: "stream-sid", | ||
custom_parameters: { | ||
"foo" => "bar", | ||
"bar" => "baz" | ||
} | ||
) | ||
|
||
expect(controller).to have_received(:write_and_await_response).with( | ||
have_attributes( | ||
class: Rayo::Command::TwilioStream::Start, | ||
uuid: "call-id", | ||
url: "wss://example.com/audio", | ||
metadata: { | ||
call_sid: "call-sid", | ||
account_sid: "account-sid", | ||
stream_sid: "stream-sid", | ||
custom_parameters: { | ||
"foo" => "bar", | ||
"bar" => "baz" | ||
} | ||
} | ||
) | ||
) | ||
expect(controller.call).to have_received(:write_command).with( | ||
have_attributes( | ||
class: Rayo::Command::UpdateCallProgress, | ||
flag: 1 | ||
) | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe StopTwilioStream, type: :call_controller do | ||
it "stops a twilio stream" do | ||
controller = build_controller(stub_voice_commands: :write_and_await_response) | ||
|
||
StopTwilioStream.call(controller) | ||
|
||
expect(controller).to have_received(:write_and_await_response).with( | ||
an_instance_of(Rayo::Command::TwilioStream::Stop) | ||
) | ||
expect(controller.call).to have_received(:write_command).with( | ||
have_attributes( | ||
class: Rayo::Command::UpdateCallProgress, | ||
flag: 0 | ||
) | ||
) | ||
end | ||
end |
Oops, something went wrong.