void libwebrtc_close_connection( struct libwebrtc_connection* conn ) { ILibWrapper_WebRTC_Connection connection = (ILibWrapper_WebRTC_Connection)conn; void* user_data = NULL; libwebrtc_context* ctx = NULL; ILibWrapper_WebRTC_Connection_GetUserData(connection, (void**)&ctx, NULL, &user_data); assert( ctx != NULL ); // this will trigger the callback for any existing channels. ILibWrapper_WebRTC_Connection_Disconnect(connection); // the connection object is now destroyed }
// Disconnects the unerlying SCTP session, if it is connected __declspec(dllexport) void ILibWrapper_DLL_WebRTC_Connection_Disconnect(ILibWrapper_WebRTC_Connection connection) { ILibWrapper_WebRTC_Connection_Disconnect(connection); }
// This gets called When the browser hits one of the two URLs void Rendezvous_OnGet(SimpleRendezvousServer sender, SimpleRendezvousServerToken token, char* path, char* receiver) { printf(green"on Get\n"rst); if(strcmp(path, "/active")==0) { if(mConnection != NULL) { ILibWrapper_WebRTC_Connection_Disconnect(mConnection); mConnection = NULL; } #ifdef MICROSTACK_TLS_DETECT if(SimpleRendezvousServer_IsTLS(token)!=0) { printf(" Received Client Request: [TLS]\r\n"); } else { printf(" Received Client Request: [No-TLS]\r\n"); } #endif SimpleRendezvousServer_Respond(sender, token, 1, htmlBody, htmlBodyLength, ILibAsyncSocket_MemoryOwnership_USER); // Send the HTML to the Browser } else if(strcmp(path, "/websocket")==0) { printf(red"/websocket\n"rst); int v = SimpleRendezvousServer_WebSocket_IsRequest(token); if(SimpleRendezvousServer_IsAuthenticated(token, "www.meshcentral.com", 19)!=0) { char* name = SimpleRendezvousServer_GetUsername(token); if(SimpleRendezvousServer_ValidatePassword(token, "bryan", 5)!=0) { printf(red"rendevous respond\n"rst); SimpleRendezvousServer_Respond(sender, token, 1, wshtmlbody, wshtmlBodyLength, ILibAsyncSocket_MemoryOwnership_USER); // Send the HTML to the Browser } } } else if(strcmp(path, "/websocketInit")==0) { printf(green"/websocketInit\n"rst); int v = SimpleRendezvousServer_WebSocket_IsRequest(token); SimpleRendezvousServer_UpgradeWebSocket(token, 65535, &OnWebSocket, &OnWebSocketClosed); } else if(strcmp(path, "/passive")==0) { printf("/passive\n"); char* offer; char* encodedOffer = NULL; int encodedOfferLen; char *h1; if(mConnection != NULL){ ILibWrapper_WebRTC_Connection_Disconnect(mConnection); mConnection = NULL; } mConnection = ILibWrapper_WebRTC_ConnectionFactory_CreateConnection(mConnectionFactory, &WebRTCConnectionSink, &WebRTCDataChannelSink, &WebRTCConnectionSendOkSink); ILibWrapper_WebRTC_Connection_SetStunServers(mConnection, stunServerList, 9); if(useStun==0) { // // If STUN was not enabled, then we just generate an offer, and encode it as Base64 into the HTML file to send to the browser // printf("Generating Offer...\r\n"); offer = ILibWrapper_WebRTC_Connection_GenerateOffer(mConnection, NULL); printf("Encoding Offer...\r\n"); encodedOfferLen = ILibBase64Encode((unsigned char*)offer, strlen(offer),(unsigned char**)&encodedOffer); h1 = ILibString_Replace(passiveHtmlBody, passiveHtmlBodyLength, "/*{{{SDP}}}*/", 13, encodedOffer, encodedOfferLen); printf("Sending Offer...\r\n"); free(offer); free(encodedOffer); SimpleRendezvousServer_Respond(sender, token, 1, h1, strlen(h1), ILibAsyncSocket_MemoryOwnership_CHAIN); // Send the HTML/OFFER to the browser } else { // // If STUN was enabled, to simplify this sample app, we'll generate the offer, but we won't do anything with it, as we'll wait until printf(red"we get called back saying that candidate gathering was done\n"rst); // ILibWrapper_WebRTC_Connection_SetUserData(mConnection, sender, token, NULL); free(ILibWrapper_WebRTC_Connection_GenerateOffer(mConnection, &PassiveCandidateSink)); // We're immediately freeing, becuase we're going to re-generate the offer when we get the candidate callback // It would be better if we sent this offer, and just passed along the candidates separately, but that is for another sample, since that requires more complex logic. } } else { printf(red"If we got a GET request for something other than ACTIVE or PASSIVE, we'll just return an error\n"rst); SimpleRendezvousServer_Respond(sender, token, 0, NULL, 0, ILibAsyncSocket_MemoryOwnership_CHAIN); } }