// 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); } }
int libwebrtc_set_offer( struct libwebrtc_connection* conn, const char* sdp ) { 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 ); // Microstack requires at least one candidate std::string tmp; if( strstr(sdp, "a=candidate") == NULL ) { tmp = sdp; tmp += "a=candidate:0 1 UDP 2128609534 0.0.0.0 0 typ host\n"; sdp = tmp.c_str(); } char* offer = ILibWrapper_WebRTC_Connection_SetOffer(connection, (char*)sdp, strlen(sdp), &WebRTCOnIceCandidate); if( offer == NULL ) return 0; // always send this offer, as the callback will only send additianal candidates ctx->callback(ctx, conn, NULL, LWRTC_CALLBACK_LOCAL_DESCRIPTION, user_data, offer, strlen(offer)); return 1; }
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)); } } }
int libwebrtc_set_answer( struct libwebrtc_connection* conn, const char* sdp ) { 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 ); // Microstack requires at least one candidate std::string tmp; if( strstr(sdp, "a=candidate") == NULL ) { tmp = sdp; tmp += "a=candidate:0 1 UDP 2128609534 0.0.0.0 0 typ host\n"; sdp = tmp.c_str(); } char* offer = ILibWrapper_WebRTC_Connection_SetOffer(connection, (char*)sdp, strlen(sdp), NULL); // no CB as this is the answer if( offer == NULL ) return 0; return 1; }
// Set an SDP Answer/Offer (WebRTC Receiver) __declspec(dllexport) char* ILibWrapper_DLL_WebRTC_Connection_SetOffer(ILibWrapper_WebRTC_Connection connection, char* offer, int offerLen, ILibWrapper_WebRTC_OnConnectionCandidate onCandidates) { return(ILibWrapper_WebRTC_Connection_SetOffer(connection, offer, offerLen, onCandidates)); }