tutorial: HelloWorld

Change-Id: Ie19a7749ba028ceda16a2479398645daeb08f277
diff --git a/HelloWorld/CoinCircleMediaHandler.cpp b/HelloWorld/CoinCircleMediaHandler.cpp
new file mode 100644
index 0000000..213e836
--- /dev/null
+++ b/HelloWorld/CoinCircleMediaHandler.cpp
@@ -0,0 +1,107 @@
+/**
+ *  Copyright (C) 2020 Savoir-faire Linux Inc.
+ *
+ *  Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#include "CoinCircleMediaHandler.h"
+// Logger
+#include "pluglog.h"
+const char sep = separator();
+const std::string TAG = "CoinCircle";
+
+#define NAME "CoinCircle"
+
+namespace jami {
+
+CoinCircleMediaHandler::CoinCircleMediaHandler(std::map<std::string, std::string>&& ppm,
+                                               std::string&& datapath)
+    : datapath_ {datapath}
+    , ppm_ {ppm}
+{
+    setId(datapath_);
+    mVS = std::make_shared<CoinCircleVideoSubscriber>(datapath_);
+    auto it = ppm_.find("color");
+    if (it != ppm_.end()) {
+        mVS->setColor(it->second);
+    } else {
+        mVS->setColor("#0000FF");
+    }
+}
+
+void
+CoinCircleMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
+{
+    Plog::log(Plog::LogPriority::INFO, TAG, "IN AVFRAMESUBJECT");
+    std::ostringstream oss;
+    std::string direction = data.direction ? "Receive" : "Preview";
+    oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
+
+    bool preferredStreamDirection = false; // false for output; true for input
+    auto it = ppm_.find("videostream");
+    if (it != ppm_.end()) {
+        preferredStreamDirection = it->second == "1";
+    }
+    oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
+    if (data.type == StreamType::video && !data.direction
+        && data.direction == preferredStreamDirection) {
+        subject->attach(mVS.get()); // your image
+        oss << "got my sent image attached" << std::endl;
+    } else if (data.type == StreamType::video && data.direction
+               && data.direction == preferredStreamDirection) {
+        subject->attach(mVS.get()); // the image you receive from others on the call
+        oss << "got received image attached" << std::endl;
+    }
+
+    Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
+}
+
+std::map<std::string, std::string>
+CoinCircleMediaHandler::getCallMediaHandlerDetails()
+{
+    return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.png"}, {"pluginId", id()}};
+}
+
+void
+CoinCircleMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
+{
+    auto it = ppm_.find(key);
+    if (it != ppm_.end() && it->second != value) {
+        it->second = value;
+    }
+}
+
+bool
+CoinCircleMediaHandler::preferenceMapHasKey(const std::string& key)
+{
+    return false;
+}
+
+void
+CoinCircleMediaHandler::detach()
+{
+    mVS->detach();
+}
+
+CoinCircleMediaHandler::~CoinCircleMediaHandler()
+{
+    std::ostringstream oss;
+    oss << " ~CoinCircleMediaHandler from HelloWorld Plugin" << std::endl;
+    Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
+    detach();
+}
+} // namespace jami