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 @@
<script>
var avatar = 'unknown.jpg';
var callerId = "unknown";
var domain = "81.201.82.25";
var prefix = "sip:";
var handsetOffhook = false;
var ringtone;
window.dialer = new Dialpad({
......@@ -65,6 +63,7 @@
if (domain == "81.201.82.25" && prefix == "sip:") prefix = "sip:883510";
if (prefix == "tel:") domain = "";
if (prefix == "xmpp:") domain = window.location.hostname;
var iNum = urlParam("inum");
......@@ -74,7 +73,6 @@
}
window.connection = new Openfire.Connection(window.location.protocol + '//' + window.location.host + '/http-bind/');
window.connection.resource = iNum;
window.connection.addHandler(handlePresence, null,"presence", null, null, null);
window.connection.connect(window.location.hostname, null, function (status)
{
......@@ -84,16 +82,13 @@
if (status === Strophe.Status.CONNECTED)
{
$("#status").html("Ready");
setPresence();
window.connection.send($pres());
$(window).unload( function() {
onhook();
window.connection.disconnect();
});
setPresence();
getContacts();
offhook();
setPhone();
}
});
......@@ -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)
{
window.connection.rayo.offhook(
window.connection.rayo.phone(
{
codec: "OPUS",
stereo: "0",
onReady: function() {
console.log('Handset is off hook');
$("#status").html("Off Hook");
handsetOffhook = true;
},
onUnready: function() {
console.log('Handset is on hook');
$("#status").html("On Hook");
handsetOffhook = false;
},
onEnd: function() {
console.log('Handset is disconnected');
$("#status").html("On Hook");
handsetOffhook = false;
},
onError: function(e) {
console.error(e);
}
});
}
}
function toggleHook()
{
console.log("onhook()");
onOffer: function(call, headers) {
console.log('onOffer ' + call.from);
console.log(headers);
if (window.connection)
{
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")
if (window.candybar.call == null) // ignore when user has active call
{
window.candybar.setUser({
name: call.from,
number: call.to,
picUrl: 'unknown.jpg'
});
} else {
//var status = $(presence).find('status').text();
}
window.candybar.call = call;
window.candybar.setState('incoming');
window.dialer.setCallLabel('Answer');
}
},
return true;
};
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(callId, headers) {
console.log('onEnd ' + callId);
console.log(headers);
onEnd: function() {
//console.log('ended...............');
window.candybar.endGently();
window.candybar.call = null;
window.dialer.setCallLabel('Call');
},
onAnswer: function() {
//console.log('answered...............');
onAnswer: function(callId, headers) {
console.log('onAnswer ' + callId);
console.log(headers);
window.candybar.setState('active');
window.dialer.setCallLabel('Hangup');
stopTone();
},
onRing: function() {
//console.log('ringing...............');
onRing: function(callId, headers) {
console.log('onRing ' + callId);
console.log(headers);
window.candybar.setState('calling');
startTone("ringback-uk");
},
onError: function(e) {
//console.log('dial error ' + e);
window.candybar.endGently();
window.candybar.call = null;
console.error(e);
}
});
}
}
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({
name: callerId,
name: sipUri,
number: destination,
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
{
var destination = Strophe.getNodeFromJid(event.call.initiator);
window.candybar.setUser({
name: destination,
number: destination,
picUrl: 'http://placekitten.com/100/100'
name: call.from,
number: call.to,
picUrl: 'unknown.jpg'
});
window.candybar.call = event.call;
window.candybar.call = call;
window.candybar.setState('incoming');
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 @@
}
function stopTone()
{
if (ringtone)
{
ringtone.pause();
ringtone = null;
}
}
</script>
</head>
<body>
<div id="dialpadDiv" style="position: absolute; width: 500px: height: 300px;"/>
<span id="status" onClick="toggleHook()">Loading...</span>
<span id="status">Loading...</span>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
......@@ -27,6 +27,7 @@ import java.net.InetSocketAddress;
import org.voicebridge.*;
import org.xmpp.jnodes.RelayChannel;
import java.util.*;
/**
* A Class to represent a call participant - a party in a call.
......@@ -90,6 +91,9 @@ public class CallParticipant {
private ProxyCredentials proxyCredentials = null;
private RelayChannel relayChannel = null;
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
......@@ -123,9 +127,7 @@ public class CallParticipant {
this.proxyCredentials = proxyCredentials;
}
/**
* Get/Set proxy credentials
*/
public RelayChannel getRelayChannel()
{
return relayChannel;
......@@ -136,6 +138,35 @@ public class CallParticipant {
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
......
......@@ -159,7 +159,7 @@ public class RayoPlugin implements Plugin, SessionEventListener {
try {
rc = RelayChannel.createLocalRelayChannel(bindAllInterfaces ? "0.0.0.0" : LocalIPResolver.getLocalIP(), 30000, 50000);
final int id = ids.incrementAndGet();
final String sId = "rayo-handset-" + String.valueOf(id);
final String sId = JID.escapeNode(jid.toString());
rc.setAttachment(sId);
rc.setFrom(jid, component);
rc.setCrypto(handset);
......
......@@ -4,6 +4,9 @@ import java.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......@@ -20,6 +23,8 @@ import org.xmpp.packet.*;
public class Config implements MUCEventListener {
private static final Logger Log = LoggerFactory.getLogger(Config.class);
private MultiUserChatManager mucManager;
private HashMap<String, Conference> conferences;
private HashMap<String, Conference> confExtensions;
......@@ -59,7 +64,7 @@ public class Config implements MUCEventListener {
MUCEventDispatcher.addListener(this);
try {
System.out.println(String.format("VoiceBridge read site configuration"));
Log.info(String.format("VoiceBridge read site configuration"));
mucManager = XMPPServer.getInstance().getMultiUserChatManager();
......@@ -87,14 +92,15 @@ public class Config implements MUCEventListener {
processDefaultRegistration(username);
}
Log.info(String.format("VoiceBridge sip plugin assumed available"));
sipPlugin = true;
} else {
registerWithDefaultProxy();
}
}
} catch (Throwable t) {
t.printStackTrace();
}
......@@ -147,10 +153,10 @@ public class Config implements MUCEventListener {
registrars.add(sipAccount.getHost());
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) {
System.out.println("registerWithDefaultProxy " + e);
Log.info("registerWithDefaultProxy " + e);
}
}
......@@ -176,20 +182,18 @@ public class Config implements MUCEventListener {
registrars.add(credentials.getHost());
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) {
System.out.println(String.format("processDefaultRegistration Bad Address %s ", credentials.getHost()));
Log.info(String.format("processDefaultRegistration Bad Address %s ", credentials.getHost()));
}
}
rs.close();
pstmt.close();
con.close();
sipPlugin = true;
} catch (SQLException e) {
System.out.println("processDefaultRegistration " + e);
Log.info("processDefaultRegistration " + e);
}
}
......@@ -214,21 +218,19 @@ public class Config implements MUCEventListener {
registrars.add(credentials.getHost());
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) {
System.out.println(String.format("processRegistrations Bad Address %s ", credentials.getHost()));
Log.info(String.format("processRegistrations Bad Address %s ", credentials.getHost()));
}
}
rs.close();
pstmt.close();
con.close();
sipPlugin = true;
} catch (SQLException e) {
System.out.println("processRegistrations " + e);
Log.info("processRegistrations " + e);
}
}
......@@ -261,7 +263,7 @@ public class Config implements MUCEventListener {
sipExtensions.put(username, sipAccount);
} catch (SQLException e) {
System.out.println("ProxyCredentials " + e);
Log.info("ProxyCredentials " + e);
}
return sipAccount;
......@@ -289,7 +291,7 @@ public class Config implements MUCEventListener {
} catch (SQLException e) {
System.out.println("updateStatus " + e);
Log.info("updateStatus " + e);
} finally {
DbConnectionManager.closeConnection(psmt, con);
......@@ -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 (?, ?, ?, ?, ?, ?)";
......@@ -318,11 +324,41 @@ public class Config implements MUCEventListener {
psmt.executeUpdate();
} catch (SQLException e) {
Log.debug(e.getMessage(), e);
Log.error(e.getMessage(), e);
} finally {
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)
......@@ -370,7 +406,7 @@ public class Config implements MUCEventListener {
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)
......@@ -383,7 +419,7 @@ public class Config implements MUCEventListener {
Conference conference2 = confExtensions.remove(room.getName());
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