mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Can detect if a call was rejected
This commit is contained in:
		@@ -18,9 +18,24 @@ ComunicWeb.components.calls.callWindow = {
 | 
			
		||||
		 */
 | 
			
		||||
		var call = {
 | 
			
		||||
			info: info,
 | 
			
		||||
 | 
			
		||||
			/**
 | 
			
		||||
			 * @type {String}
 | 
			
		||||
			 */
 | 
			
		||||
			localPeerID: undefined,
 | 
			
		||||
 | 
			
		||||
			/**
 | 
			
		||||
			 * @type {Boolean}
 | 
			
		||||
			 */
 | 
			
		||||
			open: true,
 | 
			
		||||
 | 
			
		||||
			window: {},
 | 
			
		||||
			streams: {}
 | 
			
		||||
			streams: {},
 | 
			
		||||
 | 
			
		||||
			/**
 | 
			
		||||
			 * @type {SignalExchangerClient}
 | 
			
		||||
			 */
 | 
			
		||||
			signalClient: undefined
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		//We have to begin to draw conversation UI
 | 
			
		||||
@@ -102,6 +117,9 @@ ComunicWeb.components.calls.callWindow = {
 | 
			
		||||
		call.close = function(){
 | 
			
		||||
			call.open = false;
 | 
			
		||||
			callContainer.remove();
 | 
			
		||||
 | 
			
		||||
			//Close sockets connections too
 | 
			
		||||
			ComunicWeb.components.calls.callWindow.stop(call);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		call.window.closeButton.addEventListener("click", function(){
 | 
			
		||||
@@ -122,7 +140,8 @@ ComunicWeb.components.calls.callWindow = {
 | 
			
		||||
		//Load user media
 | 
			
		||||
		call.setLoadingMessage("Waiting for your microphone and camera...");
 | 
			
		||||
 | 
			
		||||
		ComunicWeb.components.calls.userMedia.get().then(function(stream){
 | 
			
		||||
		ComunicWeb.components.calls.userMedia.get()
 | 
			
		||||
		.then(function(stream){
 | 
			
		||||
 | 
			
		||||
			//Mark as connecting
 | 
			
		||||
			call.setLoadingMessage("Connecting...");
 | 
			
		||||
@@ -131,11 +150,111 @@ ComunicWeb.components.calls.callWindow = {
 | 
			
		||||
 | 
			
		||||
			return true;
 | 
			
		||||
 | 
			
		||||
		}).catch(function(e){
 | 
			
		||||
		})
 | 
			
		||||
		
 | 
			
		||||
		//Start to automaticaly refresh information the call
 | 
			
		||||
		.then(function(){
 | 
			
		||||
			
 | 
			
		||||
			var interval = setInterval(function(){
 | 
			
		||||
 | 
			
		||||
				if(!call.open)
 | 
			
		||||
					return clearInterval(interval);
 | 
			
		||||
 | 
			
		||||
				ComunicWeb.components.calls.callWindow.refreshInfo(call);
 | 
			
		||||
 | 
			
		||||
			}, 4000);
 | 
			
		||||
 | 
			
		||||
			return true;
 | 
			
		||||
 | 
			
		||||
		})
 | 
			
		||||
		
 | 
			
		||||
		.catch(function(e){
 | 
			
		||||
			console.error("Get user media error: ", e);
 | 
			
		||||
			call.setLoadingMessageVisibility(false);
 | 
			
		||||
			return notify("Could not get your microphone and camera!", "danger");
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		//Initialize connection to signaling server
 | 
			
		||||
 | 
			
		||||
		//Get current user call ID
 | 
			
		||||
		call.info.members.forEach(function(member){
 | 
			
		||||
 | 
			
		||||
			if(member.userID == userID())
 | 
			
		||||
				call.localPeerID = member.user_call_id;
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		var config = ComunicWeb.components.calls.controller.getConfig();
 | 
			
		||||
		call.signalClient = new SignalExchangerClient(
 | 
			
		||||
			config.signal_server_name,
 | 
			
		||||
			config.signal_server_port,
 | 
			
		||||
			call.localPeerID
 | 
			
		||||
		);
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Refresh at a regular interval information about the call
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {Object} call Call Root object
 | 
			
		||||
	 */
 | 
			
		||||
	refreshInfo: function(call){
 | 
			
		||||
 | 
			
		||||
		ComunicWeb.components.calls.interface.getInfo(call.info.id, function(result){
 | 
			
		||||
 | 
			
		||||
			if(result.error)
 | 
			
		||||
				return notify("Could not get information about the call!", "danger");
 | 
			
		||||
 | 
			
		||||
			call.info = result;
 | 
			
		||||
 | 
			
		||||
			ComunicWeb.components.calls.callWindow.gotNewCallInfo(call);
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * This method get called each time information about the call
 | 
			
		||||
	 * are refreshed on the server
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {Object} call Information about the call
 | 
			
		||||
	 */
 | 
			
		||||
	gotNewCallInfo: function(call) {
 | 
			
		||||
 | 
			
		||||
		//Check if we are connected to signaling server
 | 
			
		||||
		if(!call.signalClient.isConnected())
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		//Check if all other members rejected call
 | 
			
		||||
		var allRejected = true;
 | 
			
		||||
		call.info.members.forEach(function(member){
 | 
			
		||||
			if(member.accepted != "rejected" && member.userID != userID())
 | 
			
		||||
				allRejected = false;
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		//Check if all call peer rejected the call
 | 
			
		||||
		if(allRejected){
 | 
			
		||||
			call.setLoadingMessage("All other peers rejected the call !");
 | 
			
		||||
 | 
			
		||||
			setTimeout(function(){
 | 
			
		||||
				call.close();
 | 
			
		||||
			}, 20000);
 | 
			
		||||
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Stop the ongoing call
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {Object} call Information about the call
 | 
			
		||||
	 */
 | 
			
		||||
	stop: function(call){
 | 
			
		||||
 | 
			
		||||
		//Remove the call from the opened list
 | 
			
		||||
		ComunicWeb.components.calls.currentList.removeCallFromList(call.info.id);
 | 
			
		||||
 | 
			
		||||
		//Close the connection to the server
 | 
			
		||||
		if(call.signalClient.isConnected())
 | 
			
		||||
			call.signalClient.close();
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user