summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/Examples/ScreenSharing/Client.cpp132
-rw-r--r--Swiften/Examples/ScreenSharing/Host.cpp144
-rw-r--r--Swiften/Examples/ScreenSharing/SConscript8
3 files changed, 284 insertions, 0 deletions
diff --git a/Swiften/Examples/ScreenSharing/Client.cpp b/Swiften/Examples/ScreenSharing/Client.cpp
new file mode 100644
index 0000000..1e73055
--- /dev/null
+++ b/Swiften/Examples/ScreenSharing/Client.cpp
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2012 Yoann Blein
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <boost/bind.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <iostream>
+
+#include <Swiften/Base/Log.h>
+#include <Swiften/Elements/Presence.h>
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Client/Client.h>
+#include <Swiften/Elements/DiscoInfo.h>
+#include <Swiften/Network/BoostNetworkFactories.h>
+#include <Swiften/EventLoop/SimpleEventLoop.h>
+#include <Swiften/Client/ClientXMLTracer.h>
+#include <Swiften/Disco/ClientDiscoManager.h>
+#include <Swiften/ScreenSharing/ScreenSharingManager.h>
+#include <Swiften/ScreenSharing/IncomingScreenSharing.h>
+#include <Swiften/ScreenSharing/Image.h>
+
+using namespace Swift;
+
+SimpleEventLoop eventLoop;
+BoostNetworkFactories networkFactories(&eventLoop);
+
+int exitCode = 2;
+
+static const std::string CLIENT_NAME = "Swiften FT Test";
+static const std::string CLIENT_NODE = "http://swift.im";
+
+class ScreenReceiver {
+ public:
+ ScreenReceiver(const JID& jid, const std::string& password) : jid(jid), password(password) {
+ client = new Swift::Client(jid, password, &networkFactories);
+ client->onConnected.connect(boost::bind(&ScreenReceiver::handleConnected, this));
+ client->onDisconnected.connect(boost::bind(&ScreenReceiver::handleDisconnected, this, _1));
+ tracer = new ClientXMLTracer(client);
+ }
+
+ ~ScreenReceiver() {
+ delete tracer;
+ client->onDisconnected.disconnect(boost::bind(&ScreenReceiver::handleDisconnected, this, _1));
+ client->onConnected.disconnect(boost::bind(&ScreenReceiver::handleConnected, this));
+ delete client;
+ }
+
+ void start() {
+ ClientOptions options;
+ options.useTLS = ClientOptions::NeverUseTLS;
+ client->connect();
+ }
+
+ void stop() {
+ //foreach(const IncomingFileTransfer::ref transfer, incomingFileTransfers) {
+ //transfer->stop();
+ //}
+ client->disconnect();
+ }
+
+ private:
+ void handleConnected() {
+ Swift::logging = true;
+ client->getScreenSharingManager()->onIncomingScreenSharing.connect(boost::bind(&ScreenReceiver::handleIncomingScreenSharing, this, _1));
+
+ DiscoInfo discoInfo;
+ discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc"));
+ discoInfo.addFeature(DiscoInfo::JingleFeature);
+ discoInfo.addFeature(DiscoInfo::JingleRTPFeature);
+ discoInfo.addFeature(DiscoInfo::JingleTransportRawUDPFeature);
+ client->getDiscoManager()->setCapsNode(CLIENT_NODE);
+ client->getDiscoManager()->setDiscoInfo(discoInfo);
+ client->getPresenceSender()->sendPresence(Presence::create());
+ }
+
+ void handleIncomingScreenSharing(IncomingScreenSharing::ref sharing) {
+ SWIFT_LOG(debug) << "Incoming screen sharing" << std::endl;
+ incomingScreenSharings.push_back(sharing);
+ sharing->onNewImageReceived.connect(boost::bind(&ScreenReceiver::handleNewImageReceived, this, _1));
+ sharing->onFinished.connect(boost::bind(&ScreenReceiver::handleScreenSharingFinished, this));
+ sharing->accept();
+ //transfer->onFinished.connect(boost::bind(&ScreenReceiver::handleFileTransferFinished, this, _1));
+ //transfer->start();
+ }
+
+ void handleDisconnected(const boost::optional<ClientError>&) {
+ std::cerr << "Error!" << std::endl;
+ exit(-1);
+ }
+
+ void handleNewImageReceived(const Image& img) {
+ const std::vector<uint8_t>& data = img.data;
+ std::cout << "Image received: " << (int)data[0] << ", " << (int)data[1] << ", " << (int)data[2] << std::endl;
+ }
+
+ void handleScreenSharingFinished() {
+ std::cout << "Screen sharing finished" << std::endl;
+ exit(0);
+ }
+
+ void exit(int code) {
+ exitCode = code;
+ stop();
+ eventLoop.stop();
+ }
+
+ private:
+ JID jid;
+ std::string password;
+ Client* client;
+ ClientXMLTracer* tracer;
+ std::vector<IncomingScreenSharing::ref> incomingScreenSharings;
+};
+
+
+int main(int argc, char* argv[]) {
+ if (argc != 3) {
+ std::cerr << "Usage: " << argv[0] << " <jid> <password>" << std::endl;
+ return -1;
+ }
+
+ JID jid(argv[1]);
+ ScreenReceiver screenReceiver(jid, std::string(argv[2]));
+ screenReceiver.start();
+
+ eventLoop.run();
+
+ return exitCode;
+}
diff --git a/Swiften/Examples/ScreenSharing/Host.cpp b/Swiften/Examples/ScreenSharing/Host.cpp
new file mode 100644
index 0000000..ea7f79a
--- /dev/null
+++ b/Swiften/Examples/ScreenSharing/Host.cpp
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2012 Yoann Blein
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+//#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/bind.hpp>
+//#include <boost/filesystem.hpp>
+#include <iostream>
+
+#include <Swiften/Client/Client.h>
+#include <Swiften/Base/Log.h>
+#include <Swiften/Elements/Presence.h>
+//#include <Swiften/Network/BoostTimer.h>
+//#include <Swiften/Network/TimerFactory.h>
+#include <Swiften/Network/BoostNetworkFactories.h>
+//#include <Swiften/EventLoop/EventLoop.h>
+#include <Swiften/Client/ClientXMLTracer.h>
+#include <Swiften/EventLoop/SimpleEventLoop.h>
+//#include <Swiften/FileTransfer/OutgoingSIFileTransfer.h>
+//#include <Swiften/FileTransfer/FileReadBytestream.h>
+//#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h>
+//#include <Swiften/Network/BoostConnectionServer.h>
+//#include <Swiften/FileTransfer/OutgoingScreenSharingManager.h>
+#include <Swiften/ScreenSharing/OutgoingScreenSharing.h>
+//#include <Swiften/Jingle/JingleSessionManager.h>
+#include <Swiften/Disco/EntityCapsManager.h>
+//#include <Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGeneratorFactory.h>
+//#include <Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h>
+//#include <Swiften/Base/ByteArray.h>
+//#include <Swiften/StringCodecs/MD5.h>
+//#include <Swiften/StringCodecs/SHA1.h>
+//#include <Swiften/StringCodecs/Hexify.h>
+#include <Swiften/ScreenSharing/ScreenSharingManager.h>
+#include <Swiften/ScreenSharing/Image.h>
+
+using namespace Swift;
+
+SimpleEventLoop eventLoop;
+BoostNetworkFactories networkFactories(&eventLoop);
+
+int exitCode = 2;
+
+class ScreenSharer {
+ public:
+ ScreenSharer(const JID& jid, const std::string& password, const JID& recipient)
+ : jid(jid), password(password), recipient(recipient)
+ {
+ client = new Swift::Client(jid, password, &networkFactories);
+ client->onConnected.connect(boost::bind(&ScreenSharer::handleConnected, this));
+ client->onDisconnected.connect(boost::bind(&ScreenSharer::handleDisconnected, this, _1));
+ tracer = new ClientXMLTracer(client);
+ client->getEntityCapsProvider()->onCapsChanged.connect(boost::bind(&ScreenSharer::handleCapsChanged, this, _1));
+ }
+
+ ~ScreenSharer() {
+ delete tracer;
+ client->onDisconnected.disconnect(boost::bind(&ScreenSharer::handleDisconnected, this, _1));
+ client->onConnected.disconnect(boost::bind(&ScreenSharer::handleConnected, this));
+ delete client;
+ }
+
+ void start() {
+ ClientOptions options;
+ options.useTLS = ClientOptions::NeverUseTLS;
+ client->connect(options);
+ }
+
+ private:
+ void handleConnected() {
+ client->sendPresence(Presence::create());
+ }
+
+ void handleCapsChanged(JID jid) {
+ if (jid.toBare() == recipient) {
+ std::cout << "Recipient found" << std::endl;
+ outgoingScreenSharing = client->getScreenSharingManager()->createOutgoingScreenSharing(recipient);
+
+ if (outgoingScreenSharing) {
+ std::cout << "started screen sharing" << std::endl;
+ outgoingScreenSharing->onReady.connect(boost::bind(&ScreenSharer::handleRTPReady, this));
+ outgoingScreenSharing->onFinished.connect(boost::bind(&ScreenSharer::handleScreenSharingFinished, this));
+ outgoingScreenSharing->start(200, 200);
+ } else {
+ std::cout << "[ ERROR ] " << recipient << " doesn't support any kind of screen sharing!" << std::endl;
+ //client->disconnect();
+ }
+ }
+ }
+
+ void handleRTPReady() {
+ uint8_t *data = new uint8_t[200*200*3];
+ data[0] = 0;
+ data[1] = 128;
+ data[2] = 255;
+ Image img(200, 200, data);
+ for (int i = 0; i < 10; ++i)
+ outgoingScreenSharing->addImage(img);
+ outgoingScreenSharing->stop();
+
+ }
+
+ void handleDisconnected(const boost::optional<ClientError>&) {
+ std::cerr << "Error!" << std::endl;
+ exit(-1);
+ }
+
+ void handleScreenSharingFinished() {
+ std::cout << "Screen sharing finished" << std::endl;
+ exit(0);
+ }
+
+ void exit(int code) {
+ exitCode = code;
+ eventLoop.stop();
+ }
+
+ private:
+ OutgoingScreenSharing::ref outgoingScreenSharing;
+ JID jid;
+ std::string password;
+ JID recipient;
+ Client* client;
+ ClientXMLTracer* tracer;
+};
+
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cerr << "Usage: " << argv[0] << " <jid> <password> <recipient>" << std::endl;
+ return -1;
+ }
+
+ JID sender(argv[1]);
+ JID recipient(argv[3]);
+ Swift::logging = true;
+ ScreenSharer screenSharer(sender, std::string(argv[2]), recipient);
+ screenSharer.start();
+
+ eventLoop.run();
+
+ return exitCode;
+}
diff --git a/Swiften/Examples/ScreenSharing/SConscript b/Swiften/Examples/ScreenSharing/SConscript
new file mode 100644
index 0000000..7532f54
--- /dev/null
+++ b/Swiften/Examples/ScreenSharing/SConscript
@@ -0,0 +1,8 @@
+Import("env")
+
+myenv = env.Clone()
+myenv.MergeFlags(myenv["SWIFTEN_FLAGS"])
+myenv.MergeFlags(myenv["SWIFTEN_DEP_FLAGS"])
+
+myenv.Program("Host", ["Host.cpp"])
+myenv.Program("Client", ["Client.cpp"])