Skip to content

Commit

Permalink
Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Pallastrelli committed Apr 15, 2019
1 parent 5f2cd91 commit 1ceaa41
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 28 deletions.
5 changes: 4 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Changelog

## Version 0.6.0 - <DATE>
## Version 0.6.0 - 2019-04-15

- Solve an issue with stop record function
- The bridge creation is now delegated to the AriModel class (for uniformity with Channel)
- Complete management of playbacks
- Channel variables notifications
- Monodirectional audio support when adding a channel to a bridge

## Version 0.5.0 - 2019-02-14

Expand Down
2 changes: 1 addition & 1 deletion Version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.0
0.6.0
22 changes: 22 additions & 0 deletions aricpp/arimodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ class AriModel
AriModel& operator=(const AriModel&&) = delete;

using ChHandler = std::function<void(ChannelPtr)>;
using ChVarSetHandler = std::function<void(ChannelPtr, const std::string&, const std::string&)>;
using PlaybackHandler = std::function<void(const Playback&)>;
using StasisStartedHandler = std::function<void(ChannelPtr, bool external)>;

void OnChannelCreated(ChHandler handler) { chCreated = handler; }
void OnChannelDestroyed(ChHandler handler) { chDestroyed = handler; }
void OnChannelStateChanged(ChHandler handler) { chStateChanged = handler; }
void OnChannelVarSet(ChVarSetHandler handler) { chVarSet = handler; }
void OnStasisStarted(StasisStartedHandler handler) { stasisStarted = handler; }
void OnPlaybackStarted(PlaybackHandler handler) { PlaybackStarted = handler; }
void OnPlaybackFinished(PlaybackHandler handler) { PlaybackFinished = handler; }

ChannelPtr CreateChannel()
{
Expand Down Expand Up @@ -197,6 +202,18 @@ class AriModel
}
);

client.OnEvent(
"ChannelVarset",
[this](const JsonTree& e)
{
auto variable = Get<std::string>(e, {"variable"});
auto value = Get<std::string>(e, {"value"});
auto chId = Get<std::string>(e, {"channel","id"});
auto ch = channels.find(chId);
if ( ch == channels.end() ) return;
chVarSet(ch->second, variable, value);
}
);
client.OnEvent(
"PlaybackStarted",
[this](const JsonTree& e)
Expand All @@ -206,6 +223,7 @@ class AriModel
const std::string target_uri = Get<std::string>( e, {"playback", "target_uri"} );
const std::string language = Get<std::string>( e, {"playback", "language"} );
const std::string state = Get<std::string>( e, {"playback", "state"} );
if (PlaybackStarted) PlaybackStarted(Playback(id, &client));
}
);

Expand All @@ -218,6 +236,7 @@ class AriModel
const std::string target_uri = Get<std::string>( e, {"playback", "target_uri"} );
const std::string language = Get<std::string>( e, {"playback", "language"} );
const std::string state = Get<std::string>( e, {"playback", "state"} );
if (PlaybackFinished) PlaybackFinished(Playback(id, &client));
}
);

Expand All @@ -230,7 +249,10 @@ class AriModel
ChHandler chCreated;
ChHandler chDestroyed;
ChHandler chStateChanged;
ChVarSetHandler chVarSet;
StasisStartedHandler stasisStarted;
PlaybackHandler PlaybackStarted;
PlaybackHandler PlaybackFinished;
};

} // namespace aricpp
Expand Down
9 changes: 5 additions & 4 deletions aricpp/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ class Bridge
}
#endif

Proxy& Add(const Channel& ch, Role role=Role::participant)
Proxy& Add(const Channel& ch, bool mute=false, Role role=Role::participant)
{
return Proxy::Command(
Method::post,
"/ari/bridges/" + id +
"/addChannel?channel=" + ch.Id() +
"&mute=" + (mute ? "true" : "false") +
"&role=" + static_cast<std::string>(role),
client
);
Expand Down Expand Up @@ -215,15 +216,15 @@ class Bridge
}

ProxyPar<Playback>& Play(const std::string& media, const std::string& lang={},
const std::string& playbackId={}, int offsetms=-1, int skipms=-1) const
int offsetms=-1, int skipms=-1) const
{
Playback playback(media, client);
Playback playback(client);
return ProxyPar<Playback>::Command(
Method::post,
"/ari/bridges/"+id+"/play?"
"media=" + UrlEncode(media) +
( lang.empty() ? "" : "&lang=" + lang ) +
( playbackId.empty() ? "" : "&playbackId=" + playbackId ) +
"&playbackId=" + playback.Id() +
( offsetms < 0 ? "" : "&offsetms=" + std::to_string(offsetms) ) +
( skipms < 0 ? "" : "&skipms=" + std::to_string(skipms) ),
client,
Expand Down
2 changes: 1 addition & 1 deletion aricpp/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class Channel
ProxyPar<Playback>& Play(const std::string& media, const std::string& lang={},
const std::string& playbackId={}, int offsetms=-1, int skipms=-1) const
{
Playback playback(name, client);
Playback playback(client);
return ProxyPar<Playback>::Command(
Method::post,
"/ari/channels/"+id+"/play?"
Expand Down
8 changes: 4 additions & 4 deletions aricpp/httpclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ class HttpClient
CallBack( e );
else
{
#ifdef ARICPP_TRACE_HTTP
#ifdef ARICPP_TRACE_HTTP
std::cout << "### <= " << resp.result() << " " << resp.reason() << '\n';
if ( !resp.body.empty() )
std::cout << " " << resp.body << '\n';
#endif
if ( !resp.body().empty() )
std::cout << " " << resp.body() << '\n';
#endif
CallBack( e, resp.result(), resp.reason().to_string(), resp.body() );
}

Expand Down
96 changes: 96 additions & 0 deletions aricpp/playback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*******************************************************************************
* ARICPP - ARI interface for C++
* Copyright (C) 2019 Daniele Pallastrelli
*
* This file is part of aricpp.
* For more information, see http://github.com/daniele77/aricpp
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
* this license (the "Software") to use, reproduce, display, distribute,
* execute, and transmit the Software, and to prepare derivative works of the
* Software, and to permit third-parties to whom the Software is furnished to
* do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including
* the above license grant, this restriction and the following disclaimer,
* must be included in all copies of the Software, in whole or in part, and
* all derivative works of the Software, unless such copies or derivative
* works are solely in the form of machine-executable object code generated by
* a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
******************************************************************************/


#ifndef ARICPP_PLAYBACK_H_
#define ARICPP_PLAYBACK_H_

#include <string>
#include "proxy.h"
#include "client.h"

namespace aricpp
{

class Playback
{
public:
Playback() = default;
Playback(const Playback&) = default;
Playback(Playback&&) = default;
Playback& operator=(const Playback&) = default;
Playback& operator=(Playback&&) = default;

const std::string& Id() const { return id; }

Proxy& Stop()
{
if (id.empty()) return Proxy::CreateEmpty();

return Proxy::Command(Method::delete_, "playbacks/"+id, client);
}
private:
friend class Channel;
friend class Bridge;
friend class AriModel;

Playback(Client* _client) :
id(NextId()), client(_client)
{}

Playback(const std::string& _id, Client* _client) :
id(_id), client(_client)
{}

static std::string NextId()
{
static unsigned long long nextId = 0;
return "aricpp-p" + std::to_string(nextId++);
}

std::string id;
Client* client;
};

inline bool operator == (const Playback& lhs, const Playback& rhs)
{
return lhs.Id() == rhs.Id();
}

inline bool operator != (const Playback& lhs, const Playback& rhs)
{
return lhs.Id() != rhs.Id();
}

} // namespace aricpp

#endif
2 changes: 1 addition & 1 deletion aricpp/recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Recording
{
if (name.empty()) return Proxy::CreateEmpty();

return Proxy::Command(Method::post, "recordings/live/"+name+"/stop", client);
return Proxy::Command(Method::post, "/ari/recordings/live/"+name+"/stop", client);
}
private:
friend class Channel;
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = aricpp
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.5
PROJECT_NUMBER = 0.6

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
17 changes: 7 additions & 10 deletions samples/high_level_dial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ enum class ChMode { calling=1, called=2, both=3 };
class Call
{
public:
Call( Client& c, shared_ptr<Channel> callingCh, shared_ptr<Channel> calledCh, bool _moh ) :
client(&c), calling(callingCh), called(calledCh), moh(_moh)
Call( AriModel& m, shared_ptr<Channel> callingCh, shared_ptr<Channel> calledCh, bool _moh ) :
model(m), calling(callingCh), called(calledCh), moh(_moh)
{}

bool HasChannel(const Channel& ch, ChMode mode) const
Expand All @@ -72,8 +72,7 @@ class Call

void DialingChUp()
{
Bridge::Create(
*client,
model.CreateBridge(
[this](unique_ptr<Bridge> newBridge)
{
bridge = move(newBridge);
Expand All @@ -92,7 +91,7 @@ class Call

private:

Client* client;
AriModel& model;
shared_ptr<Channel> calling;
shared_ptr<Channel> called;
unique_ptr<Bridge> bridge;
Expand All @@ -102,9 +101,8 @@ class Call
class CallContainer
{
public:
CallContainer(const string& app, Client& c, AriModel& m, bool _moh, bool _autoAns, bool _sipCh) :
CallContainer(const string& app, AriModel& m, bool _moh, bool _autoAns, bool _sipCh) :
application(app),
connection(c),
channels(m),
moh(_moh),
inviteVariables(CalcVariables(_autoAns, _sipCh)),
Expand Down Expand Up @@ -198,7 +196,7 @@ class CallContainer

void Create(shared_ptr<Channel> callingCh, shared_ptr<Channel> calledCh)
{
calls.emplace_back(make_shared<Call>(connection, callingCh, calledCh, moh));
calls.emplace_back(make_shared<Call>(channels, callingCh, calledCh, moh));
}

void Remove(shared_ptr<Call> call)
Expand Down Expand Up @@ -229,7 +227,6 @@ class CallContainer


const string application;
Client& connection;
vector<shared_ptr<Call>> calls;
AriModel& channels;
const bool moh;
Expand Down Expand Up @@ -303,7 +300,7 @@ int main( int argc, char* argv[] )

Client client( ios, host, port, username, password, application );
AriModel channels( client );
CallContainer calls( application, client, channels, moh, autoAns, sipCh );
CallContainer calls( application, channels, moh, autoAns, sipCh );

client.Connect( [&](boost::system::error_code e){
if (e)
Expand Down
9 changes: 4 additions & 5 deletions samples/holding_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,16 @@ int main( int argc, char* argv[] )
vector<shared_ptr<Channel>> channels;

Client client( ios, host, port, username, password, application );
AriModel model( client );
shared_ptr<Bridge> bridge;
Bridge::Create(
client,
model.CreateBridge(
[&bridge](unique_ptr<Bridge> newBridge)
{
bridge = move(newBridge);
cout << "Bridge created" << endl;
},
Bridge::Type::holding
);
AriModel model( client );
model.OnStasisStarted(
[&channels, &bridge](shared_ptr<Channel> ch, bool external)
{
Expand All @@ -126,12 +125,12 @@ int main( int argc, char* argv[] )
if (channels.empty())
{
cout << "Adding announcer to bridge" << endl;
bridge->Add(*ch, Bridge::Role::announcer);
bridge->Add(*ch, false /* mute */, Bridge::Role::announcer);
}
else
{
cout << "Adding participant to bridge" << endl;
bridge->Add(*ch, Bridge::Role::participant);
bridge->Add(*ch, false /* mute */, Bridge::Role::participant);
}
channels.push_back(ch);
}
Expand Down

0 comments on commit 1ceaa41

Please sign in to comment.