/* * Copyright (c) 2012 Yoann Blein * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ //#include #include //#include #include #include #include #include //#include //#include #include //#include #include #include //#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; 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.toBare() || jid == recipient) { std::cout << "Recipient found" << std::endl; outgoingScreenSharing = client->getScreenSharingManager()->createOutgoingScreenSharing(recipient); if (outgoingScreenSharing) { client->getEntityCapsProvider()->onCapsChanged.disconnect(boost::bind(&ScreenSharer::handleCapsChanged, this, _1)); 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[200*200*3]; data[0] = 0; data[1] = 128; data[2] = 255; Image img(200, 200, (const uint8_t*)data); for (int i = 0; i < 10; ++i) outgoingScreenSharing->addImage(img); outgoingScreenSharing->stop(); } void handleDisconnected(const boost::optional&) { 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] << " " << 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; }