struct libwebrtc_context* libwebrtc_create_context(lwrtc_callback_function callback) { assert( callback != NULL ); libwebrtc_context* ctx = new libwebrtc_context(); ctx->chain = poll_init(); ctx->factory = ILibWrapper_WebRTC_ConnectionFactory_CreateConnectionFactory(ctx->chain, 0); ctx->callback = callback; return ctx; }
// Creates a Factory object that can create WebRTC Connection objects. __declspec(dllexport) ILibWrapper_WebRTC_ConnectionFactory ILibWrapper_DLL_WebRTC_ConnectionFactory_CreateConnectionFactory(void* chain, unsigned short localPort) { return(ILibWrapper_WebRTC_ConnectionFactory_CreateConnectionFactory(chain, localPort)); }
int main(int argc, char **argv) #endif { /* This is to test TLS and TLS Detect struct util_cert selfcert; struct util_cert selftlscert; SSL_CTX* ctx; */ #if defined(WIN32) _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE); // Set SIGNAL on windows to listen for Ctrl-C #elif defined(_POSIX) signal(SIGPIPE, SIG_IGN); // Set a SIGNAL on Linux to listen for Ctrl-C // Shutdown on Ctrl + C signal(SIGINT, BreakSink); { struct sigaction act; act.sa_handler = SIG_IGN; sigemptyset(&act.sa_mask); act.sa_flags = 0; sigaction(SIGPIPE, &act, NULL); } #endif #if defined(WIN32) if (argc>1 && _tcscmp(argv[1], L"STUN")==0) #else if (argc>1 && strcmp(argv[1],"STUN")==0) #endif { useStun = 1; printf("USING STUN!\r\n"); } chain = ILibCreateChain(); // Create the MicrostackChain, to which we'll attach the WebRTC ConnectionFactory mConnectionFactory = ILibWrapper_WebRTC_ConnectionFactory_CreateConnectionFactory(chain, 0); // Create the connection factory, and bind to port "0", to use a random port mServer = SimpleRendezvousServer_Create(chain, 5350, &Rendezvous_OnGet, &Rendezvous_OnPost); // Create our simple Rendezvous/HTTP server we'll use to exchange SDP offers, and bind to port 5350 htmlBodyLength = ILibReadFileFromDiskEx(&htmlBody, "webrtcsample.html"); // This will be the HTML file served if you hit /ACTIVE passiveHtmlBodyLength = ILibReadFileFromDiskEx(&passiveHtmlBody, "webrtcpassivesample.html"); // This will be the HTML file served if you hit /PASSIVE wshtmlBodyLength = ILibReadFileFromDiskEx(&wshtmlbody, "websocketsample.html"); printf("Microstack WebRTC Sample Application started.\r\n\r\n"); // We're actually listening on all interfaces, not just 127.0.0.1 printf("Browser-initiated connection: http://127.0.0.1:5350/active\r\n"); // This will cause the browser to initiate a WebRTC Connection printf("Application-initiated connection: http://127.0.0.1:5350/passive\r\n"); // This will initiate a WebRTC Connection to the browser printf("Web-Socket initiated connection: http://127.0.0.1:5350/websocket\r\n"); // This will cause the browser to initiate a websocket connection to exchange WebRTC offers. printf("\r\n"); #if defined(_REMOTELOGGING) && defined(_REMOTELOGGINGSERVER) printf("Debug logging listening url: http://127.0.0.1:%u\r\n", ILibStartDefaultLogger(chain, 7775)); #endif printf("\r\n(Press Ctrl-C to exit)\r\n"); /* This is to test TLS and TLS Detect // Init Certs util_mkCert(NULL, &selfcert, 2048, 10000, "localhost", CERTIFICATE_ROOT, NULL); util_mkCert(&selfcert, &selftlscert, 2048, 10000, "10.0.0.240", CERTIFICATE_TLS_SERVER, NULL); // Init TLS ctx = SSL_CTX_new(TLSv1_method()); SSL_CTX_use_certificate(ctx, selftlscert.x509); SSL_CTX_use_PrivateKey(ctx, selftlscert.pkey); SimpleRendezvousServer_SetSSL(mServer, ctx); */ ; ILibSpawnNormalThread(&Run, NULL); // Spawn a thread to listen for user input ILibStartChain(chain); // This will start the Microstack Chain... It will block until ILibStopChain is called /* This is to test TLS and TLS Detect SSL_CTX_free(ctx); util_freecert(&selfcert); util_freecert(&selftlscert); */ // This won't execute until the Chain was stopped free(htmlBody); free(passiveHtmlBody); free(wshtmlbody); printf("Application exited gracefully.\r\n"); #if defined(WIN32) _CrtDumpMemoryLeaks(); #endif return(0); }