pari: branch 2.0 r3698 - /branches/2.0/config/js/pbx.js

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Sat Aug 23 00:27:59 CDT 2008


Author: pari
Date: Sat Aug 23 00:27:58 2008
New Revision: 3698

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=3698
Log:


  Using 'action = status' instead of 'command = core show channels'
  as the later does not output the complete channel name.

  This can be improved/optimized further, later.




Modified:
    branches/2.0/config/js/pbx.js

Modified: branches/2.0/config/js/pbx.js
URL: http://svn.digium.com/view/asterisk-gui/branches/2.0/config/js/pbx.js?view=diff&rev=3698&r1=3697&r2=3698
==============================================================================
--- branches/2.0/config/js/pbx.js (original)
+++ branches/2.0/config/js/pbx.js Sat Aug 23 00:27:58 2008
@@ -688,18 +688,66 @@
 	},
 
 	listOfChannels: function() { // returns an array of current active channels
-		var raw_chan_output = ASTGUI.cliCommand('core show channels');	
+		var raw_chan_staus = makeSyncRequest ( { action :'status' } );
+		var to_return = [];
 		try {
-			raw_chan_output = raw_chan_output.split('\n'); /* Split into each individual line  */
-			raw_chan_output.splice(0,3); /* Get rid of headers */
-			raw_chan_output = raw_chan_output.reverse(); /* reverse array */
-			raw_chan_output.splice(0,5); /* get rid of the ---end command--- footer */
-			raw_chan_output = raw_chan_output.reverse(); /* back to the top */ 
+			raw_chan_staus = raw_chan_staus.replace(/Response: Success/, "");
+			raw_chan_staus = raw_chan_staus.replace(/Message: Channel status will follow/, "");
+			raw_chan_staus = raw_chan_staus.replace(/Event: StatusComplete/, "");
+
+			raw_chan_staus = raw_chan_staus.trim();
+			var chunks = raw_chan_staus.split('Event: Status');
+
+			chunks.each( function(this_chunk){
+				// Privilege: Call
+				// Channel: Console/dsp
+				// CallerID: <unknown>
+				// CallerIDNum: <unknown>
+				// CallerIDName: <unknown>
+				// Account: 
+				// State: Up
+				// Context: default
+				// Extension: 6050
+				// Priority: 1
+				// Seconds: 66
+				// Uniqueid: 1219466028.58
+				if( !this_chunk.contains('Channel:') ){ return; }
+				var this_chunk_lines = this_chunk.split('\n');
+				var tmp_Channel = '', tmp_state = '', tmp_application='', tmp_Location ='', tmp_context = '', tmp_extension = '', tmp_priority = '';
+
+				for ( var r =0 ; r < this_chunk_lines.length ; r++ ){
+
+					var this_chunk_line = this_chunk_lines[r];
+					//console.log(this_chunk_line);
+					if(this_chunk_line.contains('Channel:')){
+						tmp_Channel = this_chunk_line.afterStr('Channel:').trim(); continue;
+					}
+
+					if(this_chunk_line.contains('Context:')){
+						tmp_context = this_chunk_line.afterStr('Context:').trim();continue;
+					}
+
+					if(this_chunk_line.contains('Extension:')){
+						tmp_extension = this_chunk_line.afterStr('Extension:').trim();continue;
+					}
+
+					if(this_chunk_line.contains('Priority:')){
+						tmp_priority = this_chunk_line.afterStr('Priority:').trim();continue;
+					}
+					if(this_chunk_line.contains('State:')){
+						tmp_state = this_chunk_line.afterStr('State:').trim(); continue;
+					}
+				}
+
+				var tmp_line = tmp_Channel + '   ' +  tmp_extension + '@' + tmp_context + ':' + tmp_priority + '   ' + tmp_state + '   ' + 'VoiceMailMain(@default)' ;
+				to_return.push(tmp_line);
+			});
+
 		} catch(e) {
 			ASTGUI.debugLog("Error listOfChannels: " + e);
-			return false;
-		}
-		return raw_chan_output;
+			return [];
+		}
+		return to_return;
 	},
 
 	getUserDetails: function(user){ // returns an object with the specified user details, if the specified user is not found returns null ;




More information about the asterisk-gui-commits mailing list