Commit 1a6c79e9 authored by Dele Olajide's avatar Dele Olajide Committed by dele

Rayo plugin work-in-progress

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13756 b35dd754-fafc-0310-a699-88a17e54d16e
parent dc855d85
...@@ -17,10 +17,8 @@ ...@@ -17,10 +17,8 @@
<script> <script>
var avatar = 'unknown.jpg'; var avatar = 'unknown.jpg';
var callerId = "unknown";
var domain = "81.201.82.25"; var domain = "81.201.82.25";
var prefix = "sip:"; var prefix = "sip:";
var handsetOffhook = false;
var ringtone; var ringtone;
window.dialer = new Dialpad({ window.dialer = new Dialpad({
...@@ -65,6 +63,7 @@ ...@@ -65,6 +63,7 @@
if (domain == "81.201.82.25" && prefix == "sip:") prefix = "sip:883510"; if (domain == "81.201.82.25" && prefix == "sip:") prefix = "sip:883510";
if (prefix == "tel:") domain = ""; if (prefix == "tel:") domain = "";
if (prefix == "xmpp:") domain = window.location.hostname;
var iNum = urlParam("inum"); var iNum = urlParam("inum");
...@@ -74,7 +73,6 @@ ...@@ -74,7 +73,6 @@
} }
window.connection = new Openfire.Connection(window.location.protocol + '//' + window.location.host + '/http-bind/'); window.connection = new Openfire.Connection(window.location.protocol + '//' + window.location.host + '/http-bind/');
window.connection.resource = iNum; window.connection.resource = iNum;
window.connection.addHandler(handlePresence, null,"presence", null, null, null);
window.connection.connect(window.location.hostname, null, function (status) window.connection.connect(window.location.hostname, null, function (status)
{ {
...@@ -84,16 +82,13 @@ ...@@ -84,16 +82,13 @@
if (status === Strophe.Status.CONNECTED) if (status === Strophe.Status.CONNECTED)
{ {
$("#status").html("Ready"); $("#status").html("Ready");
setPresence(); window.connection.send($pres());
$(window).unload( function() { $(window).unload( function() {
onhook();
window.connection.disconnect(); window.connection.disconnect();
}); });
setPresence(); setPhone();
getContacts();
offhook();
} }
}); });
...@@ -105,184 +100,109 @@ ...@@ -105,184 +100,109 @@
} }
}) })
function setPresence(chat)
{
//console.log("setPresence");
if (window.connection)
{
var presence = $pres();
if (chat) presence.c('show').t(chat).up();
window.connection.send(presence);
}
}
function offhook() function setPhone()
{ {
console.log("offhook()"); console.log("setPhone()");
if (window.connection) if (window.connection)
{ {
window.connection.rayo.offhook( window.connection.rayo.phone(
{ {
codec: "OPUS",
stereo: "0",
onReady: function() { onReady: function() {
console.log('Handset is off hook'); console.log('Handset is off hook');
$("#status").html("Off Hook"); $("#status").html("Off Hook");
handsetOffhook = true;
}, },
onUnready: function() { onUnready: function() {
console.log('Handset is on hook'); console.log('Handset is on hook');
$("#status").html("On Hook"); $("#status").html("On Hook");
handsetOffhook = false;
}, },
onEnd: function() { onOffer: function(call, headers) {
console.log('Handset is disconnected'); console.log('onOffer ' + call.from);
$("#status").html("On Hook"); console.log(headers);
handsetOffhook = false;
},
onError: function(e) {
console.error(e);
}
});
}
}
function toggleHook()
{
console.log("onhook()");
if (window.connection) if (window.candybar.call == null) // ignore when user has active call
{
if (handsetOffhook)
window.connection.rayo.onhook();
else
offhook()
}
}
function handlePresence(presence)
{
//console.log("handlePresence");
//console.log(presence);
var from = $(presence).attr('from');
var iNum = Strophe.getResourceFromJid(from);
var xquery = presence.getElementsByTagName("x");
if (xquery.length == 0)
{
var type = $(presence).attr('type');
if (type == "unavailable")
{ {
window.candybar.setUser({
name: call.from,
number: call.to,
picUrl: 'unknown.jpg'
});
window.candybar.call = call;
} else { window.candybar.setState('incoming');
//var status = $(presence).find('status').text(); window.dialer.setCallLabel('Answer');
}
} }
},
return true; onEnd: function(callId, headers) {
}; console.log('onEnd ' + callId);
console.log(headers);
function getContacts ()
{
//console.log("getContacts ");
};
function makeCall(destination)
{
console.log("makeCall " + destination);
var sipUri = prefix + destination + "@" + domain
if (prefix == "tel:") sipUri = prefix + destination
window.candybar.call = window.connection.rayo.dial(
{
from: 'unknown',
to: sipUri,
onEnd: function() {
//console.log('ended...............');
window.candybar.endGently(); window.candybar.endGently();
window.candybar.call = null; window.candybar.call = null;
window.dialer.setCallLabel('Call'); window.dialer.setCallLabel('Call');
}, },
onAnswer: function() { onAnswer: function(callId, headers) {
//console.log('answered...............'); console.log('onAnswer ' + callId);
console.log(headers);
window.candybar.setState('active'); window.candybar.setState('active');
window.dialer.setCallLabel('Hangup'); window.dialer.setCallLabel('Hangup');
stopTone(); stopTone();
}, },
onRing: function() { onRing: function(callId, headers) {
//console.log('ringing...............'); console.log('onRing ' + callId);
console.log(headers);
window.candybar.setState('calling'); window.candybar.setState('calling');
startTone("ringback-uk"); startTone("ringback-uk");
}, },
onError: function(e) { onError: function(e) {
//console.log('dial error ' + e); console.error(e);
window.candybar.endGently();
window.candybar.call = null;
} }
}); });
}
}
function makeCall(destination)
{
console.log("makeCall " + destination);
var sipUri = prefix + destination + "@" + domain
if (prefix == "tel:") sipUri = prefix + destination
window.candybar.call = window.connection.rayo.dial("xmpp:" + window.connection.jid, sipUri);
window.candybar.setUser({ window.candybar.setUser({
name: callerId, name: sipUri,
number: destination, number: destination,
picUrl: 'unknown.jpg' picUrl: 'unknown.jpg'
}); });
} }
function onIncomingCall(event) function onIncomingCall(call)
{ {
console.log(' call from ' + event.call.initiator); console.log(' call from ' + call.from);
if (window.candybar.call == null) // ignore when user has active call if (window.candybar.call == null) // ignore when user has active call
{ {
var destination = Strophe.getNodeFromJid(event.call.initiator);
window.candybar.setUser({ window.candybar.setUser({
name: destination, name: call.from,
number: destination, number: call.to,
picUrl: 'http://placekitten.com/100/100' picUrl: 'unknown.jpg'
}); });
window.candybar.call = event.call; window.candybar.call = call;
window.candybar.setState('incoming'); window.candybar.setState('incoming');
window.dialer.setCallLabel('Answer'); window.dialer.setCallLabel('Answer');
/*
window.candybar.call.bind(
{
onHangup: function(event)
{
window.candybar.endGently();
//window.candybar.call = null;
window.dialer.setCallLabel('Call');
},
onAnswer: function(event)
{
window.candybar.setState('active');
window.dialer.setCallLabel('Hangup');
},
onError: function(event)
{
console.log('call error ' + event.reason);
}
});
*/
} }
} }
...@@ -303,15 +223,18 @@ ...@@ -303,15 +223,18 @@
} }
function stopTone() function stopTone()
{
if (ringtone)
{ {
ringtone.pause(); ringtone.pause();
ringtone = null; ringtone = null;
} }
}
</script> </script>
</head> </head>
<body> <body>
<div id="dialpadDiv" style="position: absolute; width: 500px: height: 300px;"/> <div id="dialpadDiv" style="position: absolute; width: 500px: height: 300px;"/>
<span id="status" onClick="toggleHook()">Loading...</span> <span id="status">Loading...</span>
</body> </body>
</html> </html>
\ No newline at end of file
This diff is collapsed.
...@@ -27,6 +27,7 @@ import java.net.InetSocketAddress; ...@@ -27,6 +27,7 @@ import java.net.InetSocketAddress;
import org.voicebridge.*; import org.voicebridge.*;
import org.xmpp.jnodes.RelayChannel; import org.xmpp.jnodes.RelayChannel;
import java.util.*;
/** /**
* A Class to represent a call participant - a party in a call. * A Class to represent a call participant - a party in a call.
...@@ -90,6 +91,9 @@ public class CallParticipant { ...@@ -90,6 +91,9 @@ public class CallParticipant {
private ProxyCredentials proxyCredentials = null; private ProxyCredentials proxyCredentials = null;
private RelayChannel relayChannel = null; private RelayChannel relayChannel = null;
private boolean autoAnswer = true; private boolean autoAnswer = true;
private long startTimestamp = 0;
private long endTimestamp = 0;
private Map<String, String> headers = new HashMap<String, String>();
/* /*
* Second party in a two party call or target of migration * Second party in a two party call or target of migration
...@@ -123,9 +127,7 @@ public class CallParticipant { ...@@ -123,9 +127,7 @@ public class CallParticipant {
this.proxyCredentials = proxyCredentials; this.proxyCredentials = proxyCredentials;
} }
/**
* Get/Set proxy credentials
*/
public RelayChannel getRelayChannel() public RelayChannel getRelayChannel()
{ {
return relayChannel; return relayChannel;
...@@ -136,6 +138,35 @@ public class CallParticipant { ...@@ -136,6 +138,35 @@ public class CallParticipant {
this.relayChannel = relayChannel; this.relayChannel = relayChannel;
} }
public long getStartTimestamp()
{
return startTimestamp;
}
public void setStartTimestamp(long startTimestamp)
{
this.startTimestamp = startTimestamp;
}
public long getEndTimestamp()
{
return endTimestamp;
}
public void setEndTimestamp(long endTimestamp)
{
this.endTimestamp = endTimestamp;
}
public Map<String, String> getHeaders()
{
return headers;
}
public void setHeaders(Map<String, String> headers)
{
this.headers = headers;
}
/** /**
* Get call answer timeout * Get call answer timeout
......
...@@ -159,7 +159,7 @@ public class RayoPlugin implements Plugin, SessionEventListener { ...@@ -159,7 +159,7 @@ public class RayoPlugin implements Plugin, SessionEventListener {
try { try {
rc = RelayChannel.createLocalRelayChannel(bindAllInterfaces ? "0.0.0.0" : LocalIPResolver.getLocalIP(), 30000, 50000); rc = RelayChannel.createLocalRelayChannel(bindAllInterfaces ? "0.0.0.0" : LocalIPResolver.getLocalIP(), 30000, 50000);
final int id = ids.incrementAndGet(); final int id = ids.incrementAndGet();
final String sId = "rayo-handset-" + String.valueOf(id); final String sId = JID.escapeNode(jid.toString());
rc.setAttachment(sId); rc.setAttachment(sId);
rc.setFrom(jid, component); rc.setFrom(jid, component);
rc.setCrypto(handset); rc.setCrypto(handset);
......
...@@ -4,6 +4,9 @@ import java.util.*; ...@@ -4,6 +4,9 @@ import java.util.*;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -20,6 +23,8 @@ import org.xmpp.packet.*; ...@@ -20,6 +23,8 @@ import org.xmpp.packet.*;
public class Config implements MUCEventListener { public class Config implements MUCEventListener {
private static final Logger Log = LoggerFactory.getLogger(Config.class);
private MultiUserChatManager mucManager; private MultiUserChatManager mucManager;
private HashMap<String, Conference> conferences; private HashMap<String, Conference> conferences;
private HashMap<String, Conference> confExtensions; private HashMap<String, Conference> confExtensions;
...@@ -59,7 +64,7 @@ public class Config implements MUCEventListener { ...@@ -59,7 +64,7 @@ public class Config implements MUCEventListener {
MUCEventDispatcher.addListener(this); MUCEventDispatcher.addListener(this);
try { try {
System.out.println(String.format("VoiceBridge read site configuration")); Log.info(String.format("VoiceBridge read site configuration"));
mucManager = XMPPServer.getInstance().getMultiUserChatManager(); mucManager = XMPPServer.getInstance().getMultiUserChatManager();
...@@ -87,14 +92,15 @@ public class Config implements MUCEventListener { ...@@ -87,14 +92,15 @@ public class Config implements MUCEventListener {
processDefaultRegistration(username); processDefaultRegistration(username);
} }
Log.info(String.format("VoiceBridge sip plugin assumed available"));
sipPlugin = true;
} else { } else {
registerWithDefaultProxy(); registerWithDefaultProxy();
} }
} }
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
...@@ -147,10 +153,10 @@ public class Config implements MUCEventListener { ...@@ -147,10 +153,10 @@ public class Config implements MUCEventListener {
registrars.add(sipAccount.getHost()); registrars.add(sipAccount.getHost());
registrations.add(sipAccount); registrations.add(sipAccount);
System.out.println(String.format("VoiceBridge adding SIP registration: %s with user %s host %s", sipAccount.getXmppUserName(), sipAccount.getUserName(), sipAccount.getHost())); Log.info(String.format("VoiceBridge adding SIP registration: %s with user %s host %s", sipAccount.getXmppUserName(), sipAccount.getUserName(), sipAccount.getHost()));
} catch (Exception e) { } catch (Exception e) {
System.out.println("registerWithDefaultProxy " + e); Log.info("registerWithDefaultProxy " + e);
} }
} }
...@@ -176,20 +182,18 @@ public class Config implements MUCEventListener { ...@@ -176,20 +182,18 @@ public class Config implements MUCEventListener {
registrars.add(credentials.getHost()); registrars.add(credentials.getHost());
registrations.add(credentials); registrations.add(credentials);
System.out.println(String.format("VoiceBridge adding SIP registration: %s with user %s host %s", credentials.getXmppUserName(), credentials.getUserName(), credentials.getHost())); Log.info(String.format("VoiceBridge adding SIP registration: %s with user %s host %s", credentials.getXmppUserName(), credentials.getUserName(), credentials.getHost()));
} catch (Exception e) { } catch (Exception e) {
System.out.println(String.format("processDefaultRegistration Bad Address %s ", credentials.getHost())); Log.info(String.format("processDefaultRegistration Bad Address %s ", credentials.getHost()));
} }
} }
rs.close(); rs.close();
pstmt.close(); pstmt.close();
con.close(); con.close();
sipPlugin = true;
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("processDefaultRegistration " + e); Log.info("processDefaultRegistration " + e);
} }
} }
...@@ -214,21 +218,19 @@ public class Config implements MUCEventListener { ...@@ -214,21 +218,19 @@ public class Config implements MUCEventListener {
registrars.add(credentials.getHost()); registrars.add(credentials.getHost());
registrations.add(credentials); registrations.add(credentials);
System.out.println(String.format("VoiceBridge adding SIP registration: %s with user %s host %s", credentials.getXmppUserName(), credentials.getUserName(), credentials.getHost())); Log.info(String.format("VoiceBridge adding SIP registration: %s with user %s host %s", credentials.getXmppUserName(), credentials.getUserName(), credentials.getHost()));
} catch (Exception e) { } catch (Exception e) {
System.out.println(String.format("processRegistrations Bad Address %s ", credentials.getHost())); Log.info(String.format("processRegistrations Bad Address %s ", credentials.getHost()));
} }
} }
rs.close(); rs.close();
pstmt.close(); pstmt.close();
con.close(); con.close();
sipPlugin = true;
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("processRegistrations " + e); Log.info("processRegistrations " + e);
} }
} }
...@@ -261,7 +263,7 @@ public class Config implements MUCEventListener { ...@@ -261,7 +263,7 @@ public class Config implements MUCEventListener {
sipExtensions.put(username, sipAccount); sipExtensions.put(username, sipAccount);
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("ProxyCredentials " + e); Log.info("ProxyCredentials " + e);
} }
return sipAccount; return sipAccount;
...@@ -289,7 +291,7 @@ public class Config implements MUCEventListener { ...@@ -289,7 +291,7 @@ public class Config implements MUCEventListener {
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("updateStatus " + e); Log.info("updateStatus " + e);
} finally { } finally {
DbConnectionManager.closeConnection(psmt, con); DbConnectionManager.closeConnection(psmt, con);
...@@ -297,7 +299,11 @@ public class Config implements MUCEventListener { ...@@ -297,7 +299,11 @@ public class Config implements MUCEventListener {
} }
} }
public static void recordCall(String username, String addressFrom, String addressTo, long datetime, int duration, String calltype) { public static void createCallRecord(String username, String addressFrom, String addressTo, long datetime, int duration, String calltype) {
if (sipPlugin)
{
Log.info("createCallRecord " + username + " " + addressFrom + " " + addressTo + " " + datetime);
String sql = "INSERT INTO ofSipPhoneLog (username, addressFrom, addressTo, datetime, duration, calltype) values (?, ?, ?, ?, ?, ?)"; String sql = "INSERT INTO ofSipPhoneLog (username, addressFrom, addressTo, datetime, duration, calltype) values (?, ?, ?, ?, ?, ?)";
...@@ -318,11 +324,41 @@ public class Config implements MUCEventListener { ...@@ -318,11 +324,41 @@ public class Config implements MUCEventListener {
psmt.executeUpdate(); psmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
Log.debug(e.getMessage(), e); Log.error(e.getMessage(), e);
} finally { } finally {
DbConnectionManager.closeConnection(rs, psmt, con); DbConnectionManager.closeConnection(rs, psmt, con);
} }
}
}
public static void updateCallRecord(long datetime, int duration) {
if (sipPlugin)
{
Log.info("updateCallRecord " + datetime + " " + duration);
String sql = "UPDATE ofSipPhoneLog SET duration = ? WHERE datetime = ?";
Connection con = null;
PreparedStatement psmt = null;
try {
con = DbConnectionManager.getConnection();
psmt = con.prepareStatement(sql);
psmt.setInt(1, duration);
psmt.setLong(2, datetime);
psmt.executeUpdate();
} catch (SQLException e) {
Log.error(e.getMessage(), e);
} finally {
DbConnectionManager.closeConnection(psmt, con);
}
}
} }
public ProxyCredentials getProxyCredentialsByUser(String username) public ProxyCredentials getProxyCredentialsByUser(String username)
...@@ -370,7 +406,7 @@ public class Config implements MUCEventListener { ...@@ -370,7 +406,7 @@ public class Config implements MUCEventListener {
conferences.put(conference.id, conference); conferences.put(conference.id, conference);
System.out.println(String.format("VoiceBridge create conference: %s with pin %s extension %s", conference.id, conference.pin, conference.exten)); Log.info(String.format("VoiceBridge create conference: %s with pin %s extension %s", conference.id, conference.pin, conference.exten));
} }
private void destroyConference(MUCRoom room) private void destroyConference(MUCRoom room)
...@@ -383,7 +419,7 @@ public class Config implements MUCEventListener { ...@@ -383,7 +419,7 @@ public class Config implements MUCEventListener {
Conference conference2 = confExtensions.remove(room.getName()); Conference conference2 = confExtensions.remove(room.getName());
conference2 = null; conference2 = null;
System.out.println(String.format("VoiceBridge destroy conference: %s", room.getName())); Log.info(String.format("VoiceBridge destroy conference: %s", room.getName()));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment