/* * Copyright (c) 2012 Yoann Blein * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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&) { std::cerr << "Error!" << std::endl; exit(-1); } void handleNewImageReceived(const Image& img) { const std::vector& 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 incomingScreenSharings; }; int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " " << std::endl; return -1; } JID jid(argv[1]); ScreenReceiver screenReceiver(jid, std::string(argv[2])); screenReceiver.start(); eventLoop.run(); return exitCode; }