Skip to content

Commit

Permalink
Major improvements to call management
Browse files Browse the repository at this point in the history
  • Loading branch information
tsbarnes committed Feb 15, 2016
1 parent 13e534a commit 1938dfb
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 81 deletions.
34 changes: 17 additions & 17 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 24,14 @@ var popupOptions = {
var client = new SIP();
var notifySound = new Audio('wav/phone-ringing.wav');

function sendUpdate() {
chrome.runtime.sendMessage({
type: 'update',
connected: client.connected(),
calls: client.calls()
});
}

chrome.browserAction.setPopup({
popup: "popup.html"
});
Expand Down Expand Up @@ -105,13 113,12 @@ client.addListener('connected', function(type, event) {
});
}, 5000);
});
} else if(type == 'call') {
chrome.runtime.sendMessage({
type: 'update',
connected: client.connected(),
calls: client.calls()
});
}
sendUpdate();
});

client.addListener('terminating', function(type, event) {
sendUpdate();
});

client.addListener('stopped', function(type, event) {
Expand All @@ -121,6 128,7 @@ client.addListener('stopped', function(type, event) {
});
chrome.notifications.clear('sip_connected', function(wasCleared) {
});
sendUpdate();
});

client.addListener('i_new_call', function(type, event) {
Expand All @@ -142,6 150,7 @@ client.addListener('i_new_call', function(type, event) {
notifySound.load();
notifySound.play();
}
sendUpdate();
});

chrome.storage.local.get(options, function(items) {
Expand Down Expand Up @@ -175,7 184,6 @@ chrome.runtime.onConnect.addListener(function(port) {
});

chrome.runtime.onMessage.addListener(function(message) {
console.log('Message:', message);
if(message.type == 'call') {
console.log('Calling ' message.toaddr);
client.sipCall(message.toaddr);
Expand All @@ -198,17 206,9 @@ chrome.runtime.onMessage.addListener(function(message) {
client.dtmf(message.session, message.digit);
} else if(message.type == 'connect') {
client.setOptions(options);
connected = true;
} else if(message.type == 'disconnect') {
client.stack.stop();
connected = false;
}

if(message.type !== 'update') {
chrome.runtime.sendMessage({
type: 'update',
connected: client.connected(),
calls: client.calls()
});
} else if(message.type == 'noop') {
sendUpdate();
}
});
69 changes: 67 additions & 2 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 5,73 @@
function SIPClientCtrl($scope) {
$scope.toaddr = '';
$scope.connected = false;
$scope.dialpad = [1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'];
$scope.calls = {};
$scope.dialpad = [
{
sort: 1,
digit: 1,
letters: ' '
},
{
sort: 2,
digit: 2,
letters: 'abc'
},
{
sort: 3,
digit: 3,
letters: 'def'
},
{
sort: 4,
digit: 4,
letters: 'ghi'
},
{
sort: 5,
digit: 5,
letters: 'jkl'
},
{
sort: 6,
digit: 6,
letters: 'mno'
},
{
sort: 7,
digit: 7,
letters: 'pqrs'
},
{
sort: 8,
digit: 8,
letters: 'tuv'
},
{
sort: 9,
digit: 9,
letters: 'wxyz'
},
{
sort: 10,
digit: '*',
letters: ' '
},
{
sort: 11,
digit: 0,
letters: ' '
},
{
sort: 12,
digit: '#',
letters: ' '
},
];
$scope.calls = {
0: {
session: 0
}
};

chrome.runtime.onMessage.addListener(function(message) {
if(message.type == 'update') {
Expand Down
71 changes: 39 additions & 32 deletions js/sip.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 124,33 @@ SIP.prototype.sendMessage = function(toAddr, message) {
SIP.prototype.sipCall = function(toaddr) {
var self = this;
var callSession = this.stack.newSession('call-audio', {
audio_remote : this.output,
sip_caps : [ {
name : ' g.oma.sip-im'
}, {
name : ' sip.ice'
}, {
name : 'language',
value : '\"en\"'
} ],
expires : 100,
events_listener : {
events : '*',
listener : function(event) {
console.info('call session event = ' event.type);
if (event.description) {
console.info(' ** ' event.description ' ** ');
}
if (self.callbacks[event.type]) {
for (var loop = 0; loop < self.callbacks[event.type].length; loop ) {
self.callbacks[event.type][loop]('call', event);
}
}
}
audio_remote: this.output,
sip_caps: [
{
name: ' g.oma.sip-im'
},
{
name: ' sip.ice'
},
{
name: 'language',
value: '\"en\"'
}
],
expires: 100,
events_listener: {
events: '*',
listener: function(event) {
console.info('call session event = ' event.type);
if (event.description) {
console.info(' ** ' event.description ' ** ');
}
if (self.callbacks[event.type]) {
for (var loop = 0; loop < self.callbacks[event.type].length; loop ) {
self.callbacks[event.type][loop]('call', event);
}
}
}
}
// optional: '*' means all events
});
Expand Down Expand Up @@ -191,10 195,11 @@ SIP.prototype.setOptions = function(options) {
enable_early_ims: true,
enable_media_stream_cache: false,
sip_headers: [ // optional
{
name: 'User-Agent',
value: 'IM-client/OMA1.0 sipML5-v1.0.0.0'
}]
{
name: 'User-Agent',
value: 'IM-client/OMA1.0 sipML5-v1.0.0.0'
}
]
}, options);
if (!this.configuration.realm) {
console.log("SIP realm not set, not connecting");
Expand Down Expand Up @@ -239,10 244,12 @@ SIP.prototype.calls = function() {
if(this.stack && this.stack.ao_sessions) {
for(var id in this.stack.ao_sessions) {
if(this.stack.ao_sessions[id] !== undefined) {
if(this.stack.ao_sessions[id].call !== undefined) {
calls[this.stack.ao_sessions[id].getId()] = {
'session': this.stack.ao_sessions[id].getId()
};
if(this.stack.ao_sessions[id] instanceof SIPml.Session.Call) {
if(this.stack.ao_sessions[id].o_session.o_stream_remote !== null) {
calls[this.stack.ao_sessions[id].getId()] = {
'session': this.stack.ao_sessions[id].getId()
};
}
}
}
}
Expand All @@ -254,7 261,7 @@ SIP.prototype.connected = function() {
if(this.stack && this.stack.ao_sessions) {
for(var id in this.stack.ao_sessions) {
if(this.stack.ao_sessions[id] !== undefined) {
if(this.stack.ao_sessions[id].call === undefined) {
if(this.stack.ao_sessions[id] instanceof SIPml.Session.Registration) {
return true;
}
}
Expand Down
10 changes: 10 additions & 0 deletions less/popup.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 20,16 @@ body {
&.dialpad > button {
flex: 1 0 auto;
width: 33%;
text-align: center;

pre {
margin: auto;
text-align: center;

&.letters {
font-size: 0.8em;
}
}
}
}
> button {
Expand Down
69 changes: 39 additions & 30 deletions popup.html
Original file line number Diff line number Diff line change
@@ -1,37 1,46 @@
<!DOCTYPE html>
<html ng-app="SIPClient">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="bower_components/angular/angular-csp.css">
<link rel="stylesheet/less" type="text/css" href="less/popup.less">
<script type="text/javascript" src="bower_components/less/dist/less.js"></script>
<title>Chrome SIP Client</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="bower_components/angular/angular-csp.css">
<link rel="stylesheet/less" type="text/css" href="less/popup.less">
<script type="text/javascript" src="bower_components/less/dist/less.js"></script>
<title>Chrome SIP Client</title>
</head>
<body>
<form ng-controller="SIPClientCtrl" ng-submit="startCall()">
<fieldset id="connection">
<button type="button" ng-hide="connected" ng-click="connect()">Connect</button>
<button type="button" ng-show="connected" ng-click="disconnect()">Disconnect</button>
</fieldset>
<fieldset id="new_call" ng-show="connected">
<label for="toaddr">New call to:</label>
<div>
<input type="text" id="toaddr" name="toaddr" ng-model="toaddr">
<button type="submit">Call</button>
</div>
</fieldset>
<fieldset ng-repeat="sipCall in calls">
<output>{{ sipCall.session }}</output>
<button type="button" ng-click="answer(sipCall)">Answer</button>
<button type="button" ng-click="hangup(sipCall)">Hang up</button>
<div class="dialpad">
<button type="button" ng-repeat="digit in dialpad" ng-click="dtmf(sipCall, digit)">{{ digit }}</button>
</div>
</fieldset>
</form>
<script type="text/javascript" src="bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="js/popup.js"></script>
<form ng-controller="SIPClientCtrl" ng-submit="startCall()">
<fieldset id="connection">
<button type="button" ng-hide="connected" ng-click="connect()">Connect</button>
<button type="button" ng-show="connected" ng-click="disconnect()">Disconnect</button>
</fieldset>
<fieldset id="new_call" ng-show="connected">
<div>
<label for="toaddr">New call to:</label>
<input type="text" id="toaddr" name="toaddr" ng-model="toaddr">
</div>
<div class="dialpad">
<button type="button" class="dialbtn" ng-repeat="dialbtn in dialpad" ng-click="dialToAddr(sipCall, dialbtn.digit)">
<pre>{{ dialbtn.digit }}</pre>
<pre class="letters">{{ dialbtn.letters }}</pre>
</button>
</div>
<button type="submit">Call</button>
</fieldset>
<fieldset ng-repeat="sipCall in calls">
<output>{{ sipCall.session }}</output>
<div class="dialpad">
<button type="button" class="dialbtn" ng-repeat="dialbtn in dialpad" ng-click="dtmf(sipCall, dialbtn.digit)">
<pre>{{ dialbtn.digit }}</pre>
<pre class="letters">{{ dialbtn.letters }}</pre>
</button>
</div>
<button type="button" ng-click="answer(sipCall)">Answer</button>
<button type="button" ng-click="hangup(sipCall)">Hang up</button>
</fieldset>
</form>
<script type="text/javascript" src="bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="js/popup.js"></script>
</body>
</html>

0 comments on commit 1938dfb

Please sign in to comment.