mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Can respond to calls
This commit is contained in:
		@@ -12,6 +12,12 @@ ComunicWeb.components.calls.controller = {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	_is_init: false,
 | 
						_is_init: false,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * This variable contains whether the user is being
 | 
				
			||||||
 | 
						 * notified of a call or not
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						_is_processing_call: false,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Initialize calls component
 | 
						 * Initialize calls component
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@@ -107,11 +113,97 @@ ComunicWeb.components.calls.controller = {
 | 
				
			|||||||
			if(call.error)
 | 
								if(call.error)
 | 
				
			||||||
				return notify("Could not get a call for this conversation!", "danger");
 | 
									return notify("Could not get a call for this conversation!", "danger");
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
 | 
								ComunicWeb.components.calls.controller.open(call);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Call this method to initialize a call for a call we have information about
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {Object} call Information about the call
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						open: function(call){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Add the call to the list of opened calls
 | 
							//Add the call to the list of opened calls
 | 
				
			||||||
		ComunicWeb.components.calls.currentList.addCallToList(call.id);
 | 
							ComunicWeb.components.calls.currentList.addCallToList(call.id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Initialize call
 | 
							//Initialize call
 | 
				
			||||||
		ComunicWeb.components.calls.callWindow.initCall(call);
 | 
							ComunicWeb.components.calls.callWindow.initCall(call);
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * This method is called each time the notification service
 | 
				
			||||||
 | 
						 * detect that the number of pending calls has increased. It
 | 
				
			||||||
 | 
						 * must in fact be "thread-safe" to avoid to do twice things
 | 
				
			||||||
 | 
						 * that should be one only once
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {number} number The number of pending calls
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						newCallsAvailable: function(number){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if user is already processing a call
 | 
				
			||||||
 | 
							if(this._is_processing_call)
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							this._is_processing_call = true;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/**
 | 
				
			||||||
 | 
							 * Switch processing call to false
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							var undoIsProcessing = function(){
 | 
				
			||||||
 | 
								ComunicWeb.components.calls.controller._is_processing_call = false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Get information about the next pending call
 | 
				
			||||||
 | 
							ComunicWeb.components.calls.interface.getNextPendingCall(function(call){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								//Check if there is no pending call
 | 
				
			||||||
 | 
								if(call.notice)
 | 
				
			||||||
 | 
									return undoIsProcessing();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								ComunicWeb.components.conversations.utils.getNameForID(call.conversation_id, function(name){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									//Check for errors
 | 
				
			||||||
 | 
									if(!name){
 | 
				
			||||||
 | 
										ComunicWeb.debug.logMessage("Could not get the name of the conversation for a call, cannot process it!");
 | 
				
			||||||
 | 
										undoIsProcessing();
 | 
				
			||||||
 | 
										return;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									//Show ring screen
 | 
				
			||||||
 | 
									ComunicWeb.components.calls.ringScreen.show(name, 30, function(accept){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										undoIsProcessing();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										ComunicWeb.components.calls.controller.applyReponseForCall(call, accept);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Apply a response for the call
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {Object} call Information about the target call
 | 
				
			||||||
 | 
						 * @param {Boolean} accept TRUE to accept call / FALSE else
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						applyReponseForCall: function(call, accept){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Send response to server
 | 
				
			||||||
 | 
							ComunicWeb.components.calls.interface.respondToCall(call.id, accept, function(r){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//Check for error
 | 
				
			||||||
 | 
								if(r.error)
 | 
				
			||||||
 | 
									return notify("Could not send response to call to server!", "danger");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if(!accept)
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								//We may start the call now
 | 
				
			||||||
 | 
								ComunicWeb.components.calls.controller.open(call);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,5 +31,39 @@ ComunicWeb.components.calls.interface = {
 | 
				
			|||||||
			true,
 | 
								true,
 | 
				
			||||||
			callback
 | 
								callback
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get and return the next pending call for the
 | 
				
			||||||
 | 
						 * user
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {function} callback
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						getNextPendingCall: function(callback){
 | 
				
			||||||
 | 
							ComunicWeb.common.api.makeAPIrequest(
 | 
				
			||||||
 | 
								"calls/nextPending",
 | 
				
			||||||
 | 
								{},
 | 
				
			||||||
 | 
								true,
 | 
				
			||||||
 | 
								callback
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Respond to call
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {number} call_id The ID of the target call
 | 
				
			||||||
 | 
						 * @param {boolean} accept TRUE to accept call / FALSE els
 | 
				
			||||||
 | 
						 * @param {function} callback Function to call once response has been set
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						respondToCall: function(call_id, accept, callback){
 | 
				
			||||||
 | 
							ComunicWeb.common.api.makeAPIrequest(
 | 
				
			||||||
 | 
								"calls/respond",
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									call_id: call_id,
 | 
				
			||||||
 | 
									accept: accept
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								true,
 | 
				
			||||||
 | 
								callback
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -25,14 +25,19 @@ ComunicWeb.components.notifications.interface = {
 | 
				
			|||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get the number of unread news such as notifications or conversations
 | 
						 * Get the number of unread news such as notifications or conversations
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {boolean} get_calls Get the number of pending calls
 | 
				
			||||||
	 * @param {function} callback
 | 
						 * @param {function} callback
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	getAllUnread: function(callback){
 | 
						getAllUnread: function(get_calls, callback){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Perform API request
 | 
							//Perform API request
 | 
				
			||||||
		var apiURI = "notifications/count_all_news";
 | 
							var apiURI = "notifications/count_all_news";
 | 
				
			||||||
		var params = {};
 | 
							var params = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if we have to get the number of pending calls
 | 
				
			||||||
 | 
							if(get_calls)
 | 
				
			||||||
 | 
								params.include_calls = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Perform the request
 | 
							//Perform the request
 | 
				
			||||||
		ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
 | 
							ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,7 +35,8 @@ ComunicWeb.components.notifications.service = {
 | 
				
			|||||||
				
 | 
									
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//Get the number of notifications from the API
 | 
								//Get the number of notifications from the API
 | 
				
			||||||
			ComunicWeb.components.notifications.interface.getAllUnread(function(response){
 | 
								ComunicWeb.components.notifications.interface.getAllUnread(
 | 
				
			||||||
 | 
									ComunicWeb.components.calls.controller.isAvailable(), function(response){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				//Continue in case of success
 | 
									//Continue in case of success
 | 
				
			||||||
				if(response.error)
 | 
									if(response.error)
 | 
				
			||||||
@@ -76,6 +77,11 @@ ComunicWeb.components.notifications.service = {
 | 
				
			|||||||
					ComunicWeb.components.notifications.song.play();
 | 
										ComunicWeb.components.notifications.song.play();
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
					ComunicWeb.components.notifications.service.last_notifs_number = total_number_notifs;
 | 
										ComunicWeb.components.notifications.service.last_notifs_number = total_number_notifs;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									//Process the number of calls if possible
 | 
				
			||||||
 | 
									if(response.calls && response.calls > 0)
 | 
				
			||||||
 | 
										ComunicWeb.components.calls.controller.newCallsAvailable(response.calls);
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}, 2000);
 | 
							}, 2000);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user