コード例 #1
0
// This will get called by the javascript in the Browser, to pass us offers
void Rendezvous_OnPost(SimpleRendezvousServer sender, SimpleRendezvousServerToken token, char* path, char* data, int dataLen)
{
	printf(red"onpost\n"rst);
	char *offer;
	if (mConnection == NULL)
	{
		 printf("The browser initiated the SDP offer, so we have to create a connection and set the offer\n");
		mConnection = ILibWrapper_WebRTC_ConnectionFactory_CreateConnection(mConnectionFactory, &WebRTCConnectionSink, &WebRTCDataChannelSink, &WebRTCConnectionSendOkSink);
		ILibWrapper_WebRTC_Connection_SetStunServers(mConnection, stunServerList, 9);

		if (useStun==0)
		{
			printf("stun is null in on post\n");
			offer = ILibWrapper_WebRTC_Connection_SetOffer(mConnection, data, dataLen, NULL);
			SimpleRendezvousServer_Respond(sender, token, 1, offer, strlen(offer), ILibAsyncSocket_MemoryOwnership_CHAIN);
		}
		else
		{
			printf(red"We're freeing this, becuase we'll generate the offer in the candidate callback...\n"rst);
			// The best way, is to return this offer, and update the candidate incrementally, but that is for another sample
			ILibWrapper_WebRTC_Connection_SetUserData(mConnection, sender, token, NULL);
			free(ILibWrapper_WebRTC_Connection_SetOffer(mConnection, data, dataLen, &CandidateSink));
		}
	}
	else
	{
		printf("We inititiated the SDP exchange, so the browser is just giving us a response... Even tho, this will generate a counter-response\n");
		// we don't need to send it back to the browser, so we'll just drop it.
		data[dataLen] = 0;
		printf("Setting Offer...\r\n");
		free(ILibWrapper_WebRTC_Connection_SetOffer(mConnection, data, dataLen, NULL));
		SimpleRendezvousServer_Respond(sender, token, 1, NULL, 0, ILibAsyncSocket_MemoryOwnership_STATIC);		
	}
}
コード例 #2
0
ファイル: libwebrtc.cpp プロジェクト: Terricide/HumbleNet
struct libwebrtc_connection* libwebrtc_create_connection_extended( struct libwebrtc_context* ctx, void* user_data )
{
	ILibWrapper_WebRTC_Connection conn = ILibWrapper_WebRTC_ConnectionFactory_CreateConnection(ctx->factory, &WebRTCConnectionStatus, &WebRTCDataChannelAccept, &WebRTCConnectionSendOk);
	
	std::vector<const char*> stunServers;
	for( std::vector<std::string>::iterator it = ctx->stunServers.begin(); it != ctx->stunServers.end(); ++it ) {
		stunServers.push_back( it->c_str() );
	}
	ILibWrapper_WebRTC_Connection_SetStunServers(conn, (char**)&stunServers[0], stunServers.size());
	
	ILibWrapper_WebRTC_Connection_SetUserData(conn, ctx, NULL, user_data);

	return (libwebrtc_connection*)conn;
}
コード例 #3
0
void OnWebSocket(SimpleRendezvousServerToken sender, int InterruptFlag, struct packetheader *header, char *bodyBuffer,
				 int bodyBufferLen, SimpleRendezvousServer_WebSocket_DataTypes bodyBufferType, SimpleRendezvousServer_DoneFlag done)
{	
	printf(red"on websocket\n"rst);
	
	if(done == SimpleRendezvousServer_DoneFlag_NotDone)
	{
		printf(yellow"We have the entire offer\n"rst);
			char *offer;
		if (mConnection == NULL)
		{
			printf(yellow"The browser initiated the SDP offer, so we have to create a connection and set the offer\n"rst);
			mConnection = ILibWrapper_WebRTC_ConnectionFactory_CreateConnection(mConnectionFactory, 
																				&WebRTCConnectionSink, 
																				&WebRTCDataChannelSink, 
																				&WebRTCConnectionSendOkSink);
			ILibWrapper_WebRTC_Connection_SetStunServers(mConnection, stunServerList, 9);

			if (useStun==0)
			{
				printf(red"stun is 0\n"rst);
				offer = ILibWrapper_WebRTC_Connection_SetOffer(mConnection, bodyBuffer, bodyBufferLen, NULL);
				SimpleRendezvousServer_WebSocket_Send(sender, SimpleRendezvousServer_WebSocket_DataType_TEXT, offer, strlen(offer), ILibAsyncSocket_MemoryOwnership_CHAIN, SimpleRendezvousServer_FragmentFlag_Complete);
			}
			else
			{
				printf(yellow"We're freeing this, becuase we'll generate the offer in the candidate callback...\n"rst);
				// The best way, is to return this offer, and update the candidate incrementally, but that is for another sample
				ILibWrapper_WebRTC_Connection_SetUserData(mConnection, NULL, sender, NULL);
				free(ILibWrapper_WebRTC_Connection_SetOffer(mConnection, bodyBuffer, bodyBufferLen, &CandidateSink));
			}
		}
		else
		{
			printf(yellow"We inititiated the SDP exchange, so the browser is just giving us a response... Even tho, this will generate a counter-response\n"rst);
			// we don't need to send it back to the browser, so we'll just drop it.
			printf(red"Setting Offer...\r\n"rst);
			free(ILibWrapper_WebRTC_Connection_SetOffer(mConnection, bodyBuffer, bodyBufferLen, NULL));	
		}
	}
}
コード例 #4
0
ファイル: WebRTC.cpp プロジェクト: Globik/meshcentwebrtc
	// Set the STUN Servers to use with the WebRTC Connection when gathering candidates
	__declspec(dllexport) void ILibWrapper_DLL_WebRTC_Connection_SetStunServers(ILibWrapper_WebRTC_Connection connection, char** serverList, int serverLength)
	{
		ILibWrapper_WebRTC_Connection_SetStunServers(connection, serverList, serverLength);
	}
コード例 #5
0
// 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); 
	}
}