Working ! 06/12/2024

This commit is contained in:
2024-12-06 16:27:15 +07:00
parent a4ede5b1f3
commit 819f4a06df
8 changed files with 335 additions and 28 deletions

View File

@@ -1,14 +1,232 @@
let socket;
let index_setinterval;
/**
* Executed when document is ready
*/
$(document).ready(function(){
socket = io(":9092/socketio");
socket.on("connect", () => {console.log("Connected to server")});
socket.on("disconnect", (reason) => {console.log("Disconnected from server because of " + reason)});
});
/**
* Executed when index page is loaded
*/
function indexload(){ function indexload(){
console.log("Index loaded"); console.log("Index loaded");
index_setinterval = setInterval(()=>{
if (socket.connected){
$("#sipStatus").css("color", "green");
$("#cpuStatus").css("color", "green");
$("#ramStatus").css("color", "green");
$("#storageStatus").css("color", "green");
$("#networkStatus").css("color", "green");
$("#dialButton").prop("disabled", false);
$("#hangupButton").prop("disabled", false);
$("#dialNumber").prop("disabled",false);
} else {
$("#sipStatus").text("Not connected to server").css("color", "red");
$("#cpuStatus").text("Not connected to server").css("color", "red");
$("#ramStatus").text("Not connected to server").css("color", "red");
$("#storageStatus").text("Not connected to server").css("color", "red");
$("#networkStatus").text("Not connected to server").css("color", "red");
$("#dialButton").prop("disabled", true);
$("#hangupButton").prop("disabled", true);
$("#dialNumber").prop("disabled", true);
}
}, 2000);
} }
/**
* Executed when index page is unloaded
*/
function indexunload(){
console.log("Index unloaded");
clearInterval(index_setinterval);
}
/**
* Executed when setting page is loaded
*/
function settingload(){ function settingload(){
console.log("Setting loaded"); console.log("Setting loaded");
if (socket.connected){
$("#btnSaveLogin")
.prop("disabled", false)
.on("click", () =>{
let username = $("#webUsername").text();
let password = $("#webPassword").text();
if (isValidString(username) && isValidString(password)){
setLogin(username, password);
} else {
alert("Please enter valid username and password");
}
});
$("#btnSaveSIP")
.prop("disabled", false)
.on("click", () =>{
let server = $("#sipServer").text();
let port = $("#sipPort").text();
let username = $("#sipUsername").text();
let password = $("#sipPassword").text();
if (isValidString(server) && isValidPort(port) && isValidString(username) && isValidString(password)){
setSipSetting(server, port, username, password);
} else {
alert("Please enter valid server, port, username and password");
}
});
getLogin();
getSipSetting();
} else {
$("#webUsername").text("Not connected to server").css("color", "red");
$("#webPassword").text("Not connected to server").css("color", "red");
$("#sipServer").text("Not connected to server").css("color", "red");
$("#sipPort").text("Not connected to server").css("color", "red");
$("#sipUsername").text("Not connected to server").css("color", "red");
$("#sipPassword").text("Not connected to server").css("color", "red");
$("#btnSaveLogin").prop("disabled", true);
$("#btnSaveSIP").prop("disabled", true);
}
/**
* Get LoginUsername and LoginPassword data from server
*/
function getLogin(){
socket.emit(
"command",
{request: "getLogin", data:""},
(reply)=>{
if (reply.response==="success"){
/**
* @type {Object}
* @property {string} Username
* @property {string} Password
*/
let data = JSON.parse(reply.data);
$("#webUsername").text(data.Username).css("color", "black");
$("#webPassword").text(data.Password).css("color", "black");
} else {
$("#webUsername").text("Error").css("color", "red");
$("#webPassword").text("Error").css("color", "red");
}
}
);
}
/**
* Set LoginUsername and LoginPassword data to server
*
* @param {string} username Login Username
* @param {string} password Login Password
*/
function setLogin(username, password){
socket.emit(
"command",
{request: "setLogin", data:JSON.stringify({Username:username, Password:password})},
(reply)=>{
if (reply.response==="success"){
alert("Login saved successfully");
} else {
alert("Failed to save login");
}
});
}
/**
* Get SIP Setting data from server
*/
function getSipSetting(){
socket.emit(
"command",
{request: "getSipSetting", data:""},
(reply)=>{
if (reply.response==="success"){
/**
* @type {Object}
* @property {string} Server
* @property {number} Port
* @property {string} Username
* @property {string} Password
*/
let data = JSON.parse(reply.data);
$("#sipServer").text(data.Server).css("color", "black");
$("#sipPort").text(data.Port).css("color", "black");
$("#sipUsername").text(data.Username).css("color", "black");
$("#sipPassword").text(data.Password).css("color", "black");
} else {
$("#sipServer").text("Error").css("color", "red");
$("#sipPort").text("Error").css("color", "red");
$("#sipUsername").text("Error").css("color", "red");
$("#sipPassword").text("Error").css("color", "red");
}
}
);
}
/**
* Set SIP Setting data to server
* @param {string} server
* @param {number} port
* @param {string} username
* @param {string} password
*/
function setSipSetting(server, port, username, password){
socket.emit(
"command",
{request: "setSipSetting", data:JSON.stringify({Server:server, Port:port, Username:username, Password:password})},
(reply)=>{
if (reply.response==="success"){
alert("SIP setting saved successfully");
} else {
alert("Failed to save SIP setting");
}
}
)
}
} }
/**
* Executed when setting page unloaded
*/
function settingunload(){
console.log("Setting unloaded");
}
/**
* Executed when login page is loaded
*/
function loginload(){ function loginload(){
console.log("Login loaded"); console.log("Login loaded");
} }
/**
* Executed when login page is unloaded
*/
function loginunload(){
console.log("Login unloaded");
}
/**
* Check if the string is valid
* @param {string} str String to check
* @return {boolean} True if the string is not empty
*/
function isValidString(str){
return typeof str === "string" && str.trim().length > 0;
}
/**
* Check if the port is valid
* @param str {string|number} Port to check
* @return {boolean} True if the port is between 0 and 65535
*/
function isValidPort(str){
if (typeof str === "number"){
return str > 0 && str <= 65535;
} else if (typeof str === "string"){
let port = parseInt(str);
return port > 0 && port <= 65535;
}
return false;
}

View File

@@ -17,7 +17,7 @@
<link rel="stylesheet" href="assets/css/Navbar-Centered-Brand-icons.css"> <link rel="stylesheet" href="assets/css/Navbar-Centered-Brand-icons.css">
</head> </head>
<body onload="indexload()"> <body onload="indexload()" onbeforeunload="indexunload()">
<nav class="navbar navbar-expand-md bg-body py-3"> <nav class="navbar navbar-expand-md bg-body py-3">
<div class="container"><a class="navbar-brand d-flex align-items-center" href="#"><span class="bs-icon-sm bs-icon-rounded bs-icon-primary d-flex justify-content-center align-items-center me-2 bs-icon"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bezier"> <div class="container"><a class="navbar-brand d-flex align-items-center" href="#"><span class="bs-icon-sm bs-icon-rounded bs-icon-primary d-flex justify-content-center align-items-center me-2 bs-icon"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bezier">
<path fill-rule="evenodd" d="M0 10.5A1.5 1.5 0 0 1 1.5 9h1A1.5 1.5 0 0 1 4 10.5v1A1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.5z"></path>
@@ -81,7 +81,12 @@
<p>Dial To</p> <p>Dial To</p>
</div> </div>
<div class="col"><input type="text" id="dialNumber" name="dialNumber"></div> <div class="col"><input type="text" id="dialNumber" name="dialNumber"></div>
<div class="col">
<div class="row">
<div class="col"><button class="btn btn-primary btn-lg" id="dialButton" type="button">Dial</button></div> <div class="col"><button class="btn btn-primary btn-lg" id="dialButton" type="button">Dial</button></div>
<div class="col"><button class="btn btn-primary btn-lg" id="hangupButton" type="button">Hangup</button></div>
</div>
</div>
</div> </div>
</div> </div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script> <script src="assets/bootstrap/js/bootstrap.min.js"></script>

View File

@@ -17,7 +17,7 @@
<link rel="stylesheet" href="assets/css/Navbar-Centered-Brand-icons.css"> <link rel="stylesheet" href="assets/css/Navbar-Centered-Brand-icons.css">
</head> </head>
<body onload="loginload()"> <body onload="loginload()" onbeforeunload="loginunload()">
<section class="position-relative py-4 py-xl-5"> <section class="position-relative py-4 py-xl-5">
<div class="container"> <div class="container">
<div class="row mb-5"> <div class="row mb-5">

View File

@@ -17,7 +17,7 @@
<link rel="stylesheet" href="assets/css/Navbar-Centered-Brand-icons.css"> <link rel="stylesheet" href="assets/css/Navbar-Centered-Brand-icons.css">
</head> </head>
<body onload="settingload()"> <body onload="settingload()" onbeforeunload="settingunload()">
<nav class="navbar navbar-expand-md bg-body py-3"> <nav class="navbar navbar-expand-md bg-body py-3">
<div class="container"><a class="navbar-brand d-flex align-items-center" href="#"><span class="bs-icon-sm bs-icon-rounded bs-icon-primary d-flex justify-content-center align-items-center me-2 bs-icon"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-bezier"> <div class="container"><a class="navbar-brand d-flex align-items-center" href="#"><span class="bs-icon-sm bs-icon-rounded bs-icon-primary d-flex justify-content-center align-items-center me-2 bs-icon"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16"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5zM7.5 4a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5z"></path>
@@ -47,7 +47,7 @@
</div> </div>
<div class="col"> <div class="col">
<div class="row"> <div class="row">
<div class="col"><button class="btn btn-primary btn-lg" type="button">Save&nbsp;&nbsp;<svg xmlns="http://www.w3.org/2000/svg" viewBox="-32 0 512 512" width="1em" height="1em" fill="currentColor"> <div class="col"><button class="btn btn-primary btn-lg" id="btnSaveLogin" type="button">Save&nbsp;&nbsp;<svg xmlns="http://www.w3.org/2000/svg" viewBox="-32 0 512 512" width="1em" height="1em" fill="currentColor">
<!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --> <!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. -->
<path d="M48 96V416c0 8.8 7.2 16 16 16H384c8.8 0 16-7.2 16-16V170.5c0-4.2-1.7-8.3-4.7-11.3l33.9-33.9c12 12 18.7 28.3 18.7 45.3V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96C0 60.7 28.7 32 64 32H309.5c17 0 33.3 6.7 45.3 18.7l74.5 74.5-33.9 33.9L320.8 84.7c-.3-.3-.5-.5-.8-.8V184c0 13.3-10.7 24-24 24H104c-13.3 0-24-10.7-24-24V80H64c-8.8 0-16 7.2-16 16zm80-16v80H272V80H128zm32 240a64 64 0 1 1 128 0 64 64 0 1 1 -128 0z"></path> <path d="M48 96V416c0 8.8 7.2 16 16 16H384c8.8 0 16-7.2 16-16V170.5c0-4.2-1.7-8.3-4.7-11.3l33.9-33.9c12 12 18.7 28.3 18.7 45.3V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96C0 60.7 28.7 32 64 32H309.5c17 0 33.3 6.7 45.3 18.7l74.5 74.5-33.9 33.9L320.8 84.7c-.3-.3-.5-.5-.8-.8V184c0 13.3-10.7 24-24 24H104c-13.3 0-24-10.7-24-24V80H64c-8.8 0-16 7.2-16 16zm80-16v80H272V80H128zm32 240a64 64 0 1 1 128 0 64 64 0 1 1 -128 0z"></path>
</svg></button></div> </svg></button></div>
@@ -74,7 +74,7 @@
<div class="col"><input class="form-control" type="text" id="sipPassword" name="sipPassword" placeholder="SIP Password"></div> <div class="col"><input class="form-control" type="text" id="sipPassword" name="sipPassword" placeholder="SIP Password"></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col"><button class="btn btn-primary btn-lg" type="button">Save&nbsp;&nbsp;<svg xmlns="http://www.w3.org/2000/svg" viewBox="-32 0 512 512" width="1em" height="1em" fill="currentColor"> <div class="col"><button class="btn btn-primary btn-lg" id="btnSaveSIP" type="button">Save&nbsp;&nbsp;<svg xmlns="http://www.w3.org/2000/svg" viewBox="-32 0 512 512" width="1em" height="1em" fill="currentColor">
<!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --> <!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. -->
<path d="M48 96V416c0 8.8 7.2 16 16 16H384c8.8 0 16-7.2 16-16V170.5c0-4.2-1.7-8.3-4.7-11.3l33.9-33.9c12 12 18.7 28.3 18.7 45.3V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96C0 60.7 28.7 32 64 32H309.5c17 0 33.3 6.7 45.3 18.7l74.5 74.5-33.9 33.9L320.8 84.7c-.3-.3-.5-.5-.8-.8V184c0 13.3-10.7 24-24 24H104c-13.3 0-24-10.7-24-24V80H64c-8.8 0-16 7.2-16 16zm80-16v80H272V80H128zm32 240a64 64 0 1 1 128 0 64 64 0 1 1 -128 0z"></path> <path d="M48 96V416c0 8.8 7.2 16 16 16H384c8.8 0 16-7.2 16-16V170.5c0-4.2-1.7-8.3-4.7-11.3l33.9-33.9c12 12 18.7 28.3 18.7 45.3V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96C0 60.7 28.7 32 64 32H309.5c17 0 33.3 6.7 45.3 18.7l74.5 74.5-33.9 33.9L320.8 84.7c-.3-.3-.5-.5-.8-.8V184c0 13.3-10.7 24-24 24H104c-13.3 0-24-10.7-24-24V80H64c-8.8 0-16 7.2-16 16zm80-16v80H272V80H128zm32 240a64 64 0 1 1 128 0 64 64 0 1 1 -128 0z"></path>
</svg></button></div> </svg></button></div>

View File

@@ -190,8 +190,9 @@ public class BassSoundManager extends AbstractSoundManager {
if (streamhandle!=0 || recordhandle!=0) close(); if (streamhandle!=0 || recordhandle!=0) close();
if (BASS.BASS_GetVersion()!=0) { if (BASS.BASS_GetVersion()!=0) {
BASS.BASS_Init(play_device, init_freq, play_initflag); boolean init_output = BASS.BASS_Init(play_device, init_freq, play_initflag);
BASS.BASS_RecordInit(record_device); boolean init_input = BASS.BASS_RecordInit(record_device);
Logger.info("BassSoundManager init_output = {}, init_input = {}", init_output, init_input);
recordhandle = BASS.BASS_RecordStart(samplingrate, 1, recordstart_flag,null, null); recordhandle = BASS.BASS_RecordStart(samplingrate, 1, recordstart_flag,null, null);
if (recordhandle!=0) { if (recordhandle!=0) {

View File

@@ -10,6 +10,9 @@ import com.google.gson.JsonSyntaxException;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.io.File; import java.io.File;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.*; import java.util.*;
@@ -86,44 +89,49 @@ public class Main {
client.SetBassSoundManagerEvent(new BassSoundManagerEvent() { client.SetBassSoundManagerEvent(new BassSoundManagerEvent() {
@Override @Override
public void SoundChannelOpened() { public void SoundChannelOpened() {
Logger.info("Sound Channel Opened");
} }
@Override @Override
public void SoundChannelClosed() { public void SoundChannelClosed() {
Logger.info("Sound Channel Closed");
} }
@Override @Override
public void OutputChannelPCMData(int length, byte[] pcmdata) { public void OutputChannelPCMData(int length, byte[] pcmdata) {
// kalau diaktifkan, spam log
//Logger.info("Output Channel PCM Data, Length: {}",length);
} }
@Override @Override
public void InputChannelPCMData(int length, byte[] pcmdata) { public void InputChannelPCMData(int length, byte[] pcmdata) {
// kalau diaktifkan, spam log
//Logger.info("Input Channel PCM Data, Length: {}",length);
} }
@Override @Override
public void DeviceFailure(boolean onOutput, String msg) { public void DeviceFailure(boolean onOutput, String msg) {
Logger.error("Device Failure, on {}, Message: {}",onOutput?"Output":"Input", msg);
} }
@Override @Override
public void BufferingInformation(boolean onOutput, String msg) { public void BufferingInformation(boolean onOutput, String msg) {
// keluar status Resumed atau Stalled
//Logger.info("Buffering Information, on {}, Message: {}",onOutput?"Output":"Input", msg);
} }
@Override @Override
public void ChannelLevel(boolean onOutput, int level) { public void ChannelLevel(boolean onOutput, int level) {
// FIXME somehow level nya 0 terus
//Logger.info("Channel Level, on {}, Level: {}",onOutput?"Output":"Input", level);
} }
}); });
// event dari sisi protocol SIP // event dari sisi protocol SIP
client.SetJavaSipEvent(new javaSipEvents() { client.SetJavaSipEvent(new javaSipEvents() {
@Override @Override
public void Registering(SIP_Request req) { public void Registering(SIP_Request req) {
Logger.info("Registering to SIP Server, Request: {}",req); //Logger.info("Registering to SIP Server, Request: {}",req);
Logger.info("Registering to SIP Server as {}",req.From);
Buzzer_Off(); Buzzer_Off();
callLight_Registering(); callLight_Registering();
SipStatus = "Registering"; SipStatus = "Registering";
@@ -131,7 +139,8 @@ public class Main {
@Override @Override
public void RegisterSuccesful(SIP_Response resp) { public void RegisterSuccesful(SIP_Response resp) {
Logger.info("Registered to SIP Server, Response: {}",resp); //Logger.info("Registered to SIP Server, Response: {}",resp);
Logger.info("Registered to SIP Server as {}",resp.From);
Buzzer_Off(); Buzzer_Off();
callLight_Idle(); callLight_Idle();
SipStatus = "Idle"; SipStatus = "Idle";
@@ -148,14 +157,16 @@ public class Main {
@Override @Override
public void IncomingCall(SIP_Request req, SIP_Response resp) { public void IncomingCall(SIP_Request req, SIP_Response resp) {
Logger.info("Incoming Call, Request: {}, Response: {}",req,resp);
callLight_IncomingCall();
Buzzer_IncomingCall();
incomingRequest = req; incomingRequest = req;
incomingResponse = resp; incomingResponse = resp;
oncallRequest = null; oncallRequest = null;
oncallResponse = null; oncallResponse = null;
SipStatus = "Incoming Call from "+req.CallID; //Logger.info("Incoming Call, Request: {}, Response: {}",req,resp);
Logger.info("Incoming Call from {}",incomingRequest.From);
callLight_IncomingCall();
Buzzer_IncomingCall();
SipStatus = "Incoming Call from "+incomingRequest.From;
//client.AcceptIncomingCall(req); //client.AcceptIncomingCall(req);
} }
@@ -187,7 +198,18 @@ public class Main {
SipStatus = "Communication with "+oncallResponse.CallID; SipStatus = "Communication with "+oncallResponse.CallID;
} }
}); });
client.Connect();
//TODO check network interface, kalau belum ada, mesti detect ulang
List<NetworkInterface> networkinterfaces = DetectNetworkInterfaces();
if (!networkinterfaces.isEmpty()){
Logger.info("Using network interface: {}",networkinterfaces.get(0).getName());
List<InetAddress> ipaddress = GetIpv4Address(networkinterfaces.get(0));
if (!ipaddress.isEmpty()){
Logger.info("Using IP Address: {}",ipaddress.get(0).getHostAddress());
client.Connect(ipaddress.get(0).getHostAddress());
} else Logger.error("No IP Address found, please check your network connection");
} else Logger.error("No network interface found, please check your network connection");
}).start(); }).start();
} }
@@ -304,6 +326,7 @@ public class Main {
* Network light = pin 20 * Network light = pin 20
* Pilot light = pin 16 * Pilot light = pin 16
* Buzzer = pin 18 * Buzzer = pin 18
* Relay = pin ?
*/ */
private static void GPIO_Section(){ private static void GPIO_Section(){
// initialize pakai thread, biar cepat // initialize pakai thread, biar cepat
@@ -374,7 +397,8 @@ public class Main {
* Pickup incoming call * Pickup incoming call
*/ */
private static void pickupCall() { private static void pickupCall() {
if (incomingRequest!=null && incomingResponse!=null){ if (incomingRequest!=null || incomingResponse!=null){
Logger.info("Pickup incoming call from {}",incomingRequest.From);
client.AcceptIncomingCall(incomingRequest); client.AcceptIncomingCall(incomingRequest);
callLight_OnCall(); callLight_OnCall();
Buzzer_OnCall(); Buzzer_OnCall();
@@ -382,7 +406,9 @@ public class Main {
oncallResponse = incomingResponse; oncallResponse = incomingResponse;
incomingRequest = null; incomingRequest = null;
incomingResponse = null; incomingResponse = null;
SipStatus = "Communication with "+oncallRequest.CallID; SipStatus = "Communication with "+oncallRequest.From;
} else {
Logger.error("No incoming call to pickup");
} }
} }
private static String CreateSipCallNumber(String extension){ private static String CreateSipCallNumber(String extension){
@@ -599,4 +625,46 @@ public class Main {
} }
private static List<NetworkInterface> DetectNetworkInterfaces(){
List<NetworkInterface> networkInterfaces = new ArrayList<>();
try {
Enumeration<NetworkInterface> networkInterfaceEnumeration = NetworkInterface.getNetworkInterfaces();
while (networkInterfaceEnumeration.hasMoreElements()) {
NetworkInterface networkInterface = networkInterfaceEnumeration.nextElement();
if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp()) {
continue;
}
if (!GetIpv4Address(networkInterface).isEmpty()) {
{
//Logger.info("Network Interface: {}",networkInterface.getName());
networkInterfaces.add(networkInterface);
}
}
}
} catch (Exception e){
Logger.error(e);
}
return networkInterfaces;
}
private static List<InetAddress> GetIpv4Address(NetworkInterface networkInterface){
List<InetAddress> inetAddresses = new ArrayList<>();
if (networkInterface!=null){
Enumeration<InetAddress> inetAddressEnumeration = networkInterface.getInetAddresses();
while (inetAddressEnumeration.hasMoreElements()){
InetAddress inetAddress = inetAddressEnumeration.nextElement();
if (inetAddress.isLoopbackAddress()) continue;
if (inetAddress.isLinkLocalAddress()) continue;
if (inetAddress.isMulticastAddress()) continue;
if (inetAddress.isAnyLocalAddress()) continue;
if (inetAddress instanceof Inet4Address){
inetAddresses.add(inetAddress);
}
}
}
return inetAddresses;
}
} }

View File

@@ -1,5 +1,6 @@
package SIP; package SIP;
import java.net.InetAddress;
import java.net.SocketException; import java.net.SocketException;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@@ -52,15 +53,18 @@ public class jSIPClient {
/** /**
* Connect to SIP Server * Connect to SIP Server
* @param localip Local IP Address used for RTP
* @return true if parameter completed * @return true if parameter completed
*/ */
public boolean Connect() { public boolean Connect(String localip) {
Disconnect(); Disconnect();
if (cc==null) cc = new CustomConfig(); if (cc==null) cc = new CustomConfig();
cc.setDomain(serverAddress); cc.setDomain(serverAddress);
cc.setUserPart(Username); cc.setUserPart(Username);
cc.setPassword(Password); cc.setPassword(Password);
cc.SetLocalInetAddress("0.0.0.0");
cc.SetLocalInetAddress(localip);
em = new EventManager(cc,bsme); em = new EventManager(cc,bsme);
return false; return false;
@@ -152,6 +156,7 @@ public class jSIPClient {
if (em!=null) { if (em!=null) {
if (em.IsCreated()) { if (em.IsCreated()) {
if (cc!=null) { if (cc!=null) {
//cc.setRtpPort(common.RandomInt(23000,23099));
cc.setMediaFile(filename); cc.setMediaFile(filename);
cc.setMediaMode(MediaMode.file); cc.setMediaMode(MediaMode.file);
em.Call(target); em.Call(target);
@@ -172,7 +177,10 @@ public class jSIPClient {
if (em!=null) { if (em!=null) {
if (em.IsCreated()) { if (em.IsCreated()) {
if (cc!=null) { if (cc!=null) {
//cc.setRtpPort(common.RandomInt(23000,23099));
cc.setMediaMode(MediaMode.captureAndPlayback); cc.setMediaMode(MediaMode.captureAndPlayback);
em.setInputVolume(100);
em.setOutputVolume(100);
em.Call(target); em.Call(target);
return true; return true;
} else raise_log_event("Call failed, Custom Config not created"); } else raise_log_event("Call failed, Custom Config not created");
@@ -190,7 +198,10 @@ public class jSIPClient {
if (em!=null) { if (em!=null) {
if (em.IsCreated()) { if (em.IsCreated()) {
if (req!=null) { if (req!=null) {
//cc.setRtpPort(common.RandomInt(23000,23099));
cc.setMediaMode(MediaMode.captureAndPlayback); cc.setMediaMode(MediaMode.captureAndPlayback);
em.setInputVolume(100);
em.setOutputVolume(100);
em.AcceptCall(req.getReq()); em.AcceptCall(req.getReq());
return true; return true;
} else raise_log_event("AcceptIncomingCall failed, SIP_Request is null"); } else raise_log_event("AcceptIncomingCall failed, SIP_Request is null");

View File

@@ -26,6 +26,10 @@ public class common {
public static final double MB_threshold = 1024.0 * 1024.0; public static final double MB_threshold = 1024.0 * 1024.0;
public static final double GB_threshold = 1024.0 * 1024.0 * 1024.0; public static final double GB_threshold = 1024.0 * 1024.0 * 1024.0;
public static int RandomInt(int min, int max){
return (int) (Math.random() * (max - min + 1) + min);
}
public static boolean GpioExists(int gpionumber){ public static boolean GpioExists(int gpionumber){
Path xx = gpioPath.resolve("gpio"+gpionumber); Path xx = gpioPath.resolve("gpio"+gpionumber);
if (Files.isDirectory(xx)){ if (Files.isDirectory(xx)){