Beispiel #1
0
// this is called for each ice candidate. if candidate is null, no additional candidates could be found.
void WebRTCOnIceCandidate(ILibWrapper_WebRTC_Connection webRTCConnection, struct sockaddr_in6* candidate) {
	assert(webRTCConnection != NULL);
	
	void* user_data = NULL;
	libwebrtc_context* ctx = NULL;
	libwebrtc_connection* conn = (libwebrtc_connection*)webRTCConnection;

	ILibWrapper_WebRTC_Connection_GetUserData(webRTCConnection, (void**)&ctx, NULL, &user_data);
	
	// no additional candidates found.
	if( candidate == NULL )
		return;
	
	char* offer = ILibWrapper_WebRTC_Connection_AddServerReflexiveCandidateToLocalSDP( webRTCConnection, candidate );
	if( offer == NULL ) {
		ctx->callback(ctx, conn, NULL, LWRTC_CALLBACK_ERROR, user_data, NULL, 0 );
		LOG("Offer failed, closing socket\n");
		return;
	}
	free(offer);
	
	char address[225];
	
	ILibInet_ntop2((struct sockaddr*)candidate, address, 255);
	
	const char* candidateFormat = "candidate:%d %d UDP %d %s %u typ host";
	char buf[255] = {0};
	
	snprintf(buf, sizeof(buf), candidateFormat, 0, 1, 2128609535-1, address, ntohs(candidate->sin6_port));
	buf[sizeof(buf)-1] = 0;
	
	ctx->callback(ctx, conn, NULL, LWRTC_CALLBACK_ICE_CANDIDATE, user_data, buf, strlen(buf) );
}
// If we launched this sample with "STUN", then this is called when a STUN candidate is found while setting an offer
void CandidateSink(ILibWrapper_WebRTC_Connection connection, struct sockaddr_in6* candidate)
{
	printf(red"candidatesink!\n"rst);
	SimpleRendezvousServer sender;
	SimpleRendezvousServerToken token;
	char *sdp = ILibWrapper_WebRTC_Connection_AddServerReflexiveCandidateToLocalSDP(connection, candidate);
	
	ILibWrapper_WebRTC_Connection_GetUserData(connection, &sender, &token, NULL);
	if(SimpleRendezvousServer_WebSocket_IsWebSocket(token)==0)
	{
		printf(red"ws is ws(token?)\n"rst);
		SimpleRendezvousServer_Respond(sender, token, 1, sdp, strlen(sdp), ILibAsyncSocket_MemoryOwnership_CHAIN); // Send the SDP to the remote side
	}
	else
	{
		printf(red"not token?\n"rst);
		SimpleRendezvousServer_WebSocket_Send(token, SimpleRendezvousServer_WebSocket_DataType_TEXT, sdp, strlen(sdp), ILibAsyncSocket_MemoryOwnership_CHAIN, SimpleRendezvousServer_FragmentFlag_Complete);
	}
}
void PassiveCandidateSink(ILibWrapper_WebRTC_Connection connection, struct sockaddr_in6* candidate)
{
	printf("While generating an offer?\n"rst);
	SimpleRendezvousServer sender;
	SimpleRendezvousServerToken token;
	char *offer;
	char *encodedOffer;
	int encodedOfferLen;
	char *h1;

	ILibWrapper_WebRTC_Connection_GetUserData(connection, &sender, &token, (void**)&h1);

	offer = ILibWrapper_WebRTC_Connection_AddServerReflexiveCandidateToLocalSDP(connection, candidate);
	printf(green"ofer: \n %s\n"rst,offer);
	encodedOfferLen = ILibBase64Encode((unsigned char*)offer, strlen(offer),(unsigned char**)&encodedOffer);

	h1 = ILibString_Replace(passiveHtmlBody, passiveHtmlBodyLength, "/*{{{SDP}}}*/", 13, encodedOffer, encodedOfferLen);

	free(offer);
	free(encodedOffer);
	SimpleRendezvousServer_Respond(sender, token, 1, h1, strlen(h1), ILibAsyncSocket_MemoryOwnership_CHAIN); // Send the SDP to the remote side
}
Beispiel #4
0
	// Generate an udpated SDP offer containing the candidate specified
	__declspec(dllexport) char* ILibWrapper_DLL_WebRTC_Connection_AddServerReflexiveCandidateToLocalSDP(ILibWrapper_WebRTC_Connection connection, struct sockaddr_in6* candidate)
	{
		return(ILibWrapper_WebRTC_Connection_AddServerReflexiveCandidateToLocalSDP(connection, candidate));
	}