Beispiel #1
0
void ILibWrapper_WebRTC_OnConnectSink(void *StunModule, void* module, int connected)
{
	ILibWrapper_WebRTC_ConnectionStruct *obj = (ILibWrapper_WebRTC_ConnectionStruct*) ILibWebRTC_GetUserObjectFromDtlsSession(module);
	if(obj==NULL) {return;}

	obj->dtlsSession = module;
	obj->isConnected = connected;

	obj->isDtlsClient = ILibWebRTC_IsDtlsInitiator(module);

	if(obj->OnConnected!=NULL)
	{
		obj->OnConnected(obj, connected);
	}

	if(connected==0)
	{
		if(ILibIsChainBeingDestroyed(obj->mFactory->mChain)==0)
		{
			// Connection was closed, so let's clean up, but only if the chain is still running. It's possible that the previous callback caused the layer above
			// us to initiate a chain shutdown. In that case, skip this method call, becuase otherwise we may end up calling it twice, which will cause a crash.
			ILibWrapper_WebRTC_Connection_DestroyConnection(obj);
		}
	}
}
// 
// Internal method dispatched by the OnDisconnect event of the underlying ILibAsyncSocket
// 
// <param name="socketModule"></param>
// <param name="user"></param>
void ILibAsyncServerSocket_OnDisconnectSink(ILibAsyncSocket_SocketModule socketModule, void *user)
{
	struct ILibAsyncServerSocket_Data *data = (struct ILibAsyncServerSocket_Data*)user;

	// Pass this Disconnect event up
	if (data->module->OnDisconnect != NULL) data->module->OnDisconnect(data->module, socketModule, data->user);

	// If the chain is shutting down, we need to free some resources
	if (ILibIsChainBeingDestroyed(data->module->Chain) == 0) free(data);
}
void ILibAsyncServerSocket_OnDisconnect(void* socketModule, void *user)
{
	struct AsyncServerSocket_Data *data = (struct AsyncServerSocket_Data*)user;

	if(data->module->OnDisconnect!=NULL)
	{
		data->module->OnDisconnect(data->module,socketModule,data->user);
	}
	if(ILibIsChainBeingDestroyed(data->module->Chain)==0)
	{
		FREE(data);
	}
}
void Run()
{
	char temp[1024];
	char* line;

	while(ILibIsChainBeingDestroyed(chain)==0)
	{
		line = fgets(temp, 1024, stdin);

		if (mDataChannel != NULL && line!=NULL)
		{
			ILibWrapper_WebRTC_DataChannel_Close(mDataChannel);
			//ILibWrapper_WebRTC_DataChannel_SendString(mDataChannel, line, strlen(line)); // Send string data over the WebRTC Data Channel
		}
	}
}
Beispiel #5
0
	__declspec(dllexport) int ILibWrapper_DLL_IsChainDisposing(void *chain)
	{
		return(ILibIsChainBeingDestroyed(chain));
	}
Beispiel #6
0
void ILibWrapper_WebRTC_Connection_DestroyConnection(ILibWrapper_WebRTC_Connection connection)
{
	ILibWrapper_WebRTC_ConnectionStruct *obj = (ILibWrapper_WebRTC_ConnectionStruct*)connection;

	if(obj==NULL) {return;}

	
	if(ILibIsChainBeingDestroyed(obj->mFactory->mChain)==0)
	{
		ILibSparseArray_Remove(obj->mFactory->Connections, obj->id);

		// Chain is not being destroyed, so we can disconnect DTLS		
		if(obj->dtlsSession!=NULL)
		{
			ILibSCTP_Close(obj->dtlsSession);
		}
		else
		{
			if(obj->offerBlock!=NULL && obj->offerBlockLen>0)
			{
				// Clear the ICE State for the local Offer
				ILibStun_ClearIceState(obj->mFactory->mStunModule, ILibStun_CharToSlot(obj->offerBlock[7]));
			}
			if(obj->remoteOfferBlock!=NULL && obj->remoteOfferBlockLen>0)
			{
				// Clear the ICE State for the remote Offer
				ILibStun_ClearIceState(obj->mFactory->mStunModule, ILibStun_CharToSlot(obj->remoteOfferBlock[7]));
			}
		}
	}

	ILibWebRTC_SetUserObject(obj->mFactory->mStunModule, obj->localUsername, NULL);

	if(obj->stunServerList!=NULL && obj->stunServerListLength>0)
	{
		int i;
		for(i=0;i<obj->stunServerListLength;++i)
		{
			free(obj->stunServerList[i]);
		}
		free(obj->stunServerList);
		obj->stunServerList = NULL;
	}

	if(obj->offerBlock!=NULL)
	{
		free(obj->offerBlock);
		obj->offerBlock = NULL;
	}

	if(obj->remoteOfferBlock!=NULL)
	{
		free(obj->remoteOfferBlock);
		obj->remoteOfferBlock = NULL;
	}

	ILibSparseArray_DestroyEx(obj->DataChannels, &ILibWrapper_WebRTC_Connection_DestroyConnectionEx, obj);
	if(obj->stunServerFlags!=NULL)
	{
		free(obj->stunServerFlags);
	}

	free(obj);
}