Как реализовать приложение автоответчика для SIP с помощью Mizu sdkJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Как реализовать приложение автоответчика для SIP с помощью Mizu sdk

Сообщение Anonymous »

Я пытаюсь разработать SIP-приложение в Java-окружении с помощью Mizu JVoIP SDK.
Я загружаю del JVOIP.jar с сайта, помещаю его в библиотеку и связываю его.
Я пишу ниже исходный код как простое приложение с автоответчиком, но не получилось.
Я заметил, что мое приложение не прослушивает порт 5060!!!

Нет звонка мероприятие?!!!
Есть предложения?
import webphone.*;

/**
* MizuTech VoIP Application
* This application registers with a SIP server and automatically answers incoming calls
*
* Note: If you get compilation errors, run FindMizuPackage.java to see the exact
* class names in the webphone package, as they may differ slightly from what's used here.
*/
public class App {
private static webphone webphoneobj;
private static boolean isRegistered = false;

// SIP Configuration - Update these with your SIP server details
private static final String SIP_SERVER = "127.0.0.1";
private static final String USERNAME = "mtz5060";
private static final String PASSWORD = "password";
private static final int SIP_PORT = 5060;

public static void main(String[] args) throws Exception {
System.out.println("MizuTech VoIP Application - Starting...");

try {
// Initialize the WebPhone object
webphoneobj = new webphone();

// Set up notification listener for incoming calls
SIPNotificationListener sipNotificationListener= new IncomingCallListener();
webphoneobj.API_SetNotificationListener(sipNotificationListener);

// Configure SIP settings
configureSIP();

// Register with SIP server
registerWithSIP();

// Keep the application running
System.out.println("Application is running. Waiting for incoming calls...");
System.out.println("Press Ctrl+C to exit.");

// Keep the main thread alive
while (true) {
Thread.sleep(1000);

// Check registration status periodically
if (!isRegistered) {
System.out.println("Re-registering with SIP server...");
registerWithSIP();
}
}

} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
}

/**
* Configure SIP server settings
*/
private static void configureSIP() {
try {
// Set SIP server address
webphoneobj.API_SetParameter("serveraddress", SIP_SERVER);

// Set SIP port
webphoneobj.API_SetParameter("serverport", String.valueOf(SIP_PORT));

// Set username
webphoneobj.API_SetParameter("username", USERNAME);

// Set password
webphoneobj.API_SetParameter("password", PASSWORD);

System.out.println("SIP configuration completed.");
System.out.println("Server: " + SIP_SERVER);
System.out.println("Username: " + USERNAME);

} catch (Exception e) {
System.err.println("Error configuring SIP: " + e.getMessage());
throw e;
}
}

/**
* Register with the SIP server
*/
private static void registerWithSIP() {
try {
System.out.println("Registering with SIP server...");

// Register with SIP server
boolean result = webphoneobj.API_Register();

if (result ) {
isRegistered = true;
System.out.println("Successfully registered with SIP server!");
} else {
isRegistered = false;
System.err.println("Failed to register with SIP server. Error code: " + result);
}

} catch (Exception e) {
isRegistered = false;
System.err.println("Error during registration: " + e.getMessage());
}
}

/**
* Listener class to handle incoming call notifications
*/
static class IncomingCallListener extends SIPNotificationListener {

@Override
public void onStatus(SIPNotification.Status e) {
try {
System.out.println(">>>>>>"+e.getStatusText());
// Check if this is an incoming call that is ringing
if (e.getStatus() == SIPNotification.Status.STATUS_CALL_RINGING &&
e.getEndpointType() == SIPNotification.Status.DIRECTION_IN) {

int line = e.getLine();
String callerId = e.getPeer();
String displayName = e.getPeerDisplayname();
String callId = e.getCallID();

System.out.println("\n=== INCOMING CALL DETECTED ===");
System.out.println("Line: " + line);
System.out.println("Caller ID: " + callerId);
System.out.println("Display Name: " + (displayName != null ? displayName : "Unknown"));
System.out.println("Call ID: " + callId);

// Get additional call details
try {
String callerDetails = webphoneobj.API_GetCallerID(line);
String incomingDisplay = webphoneobj.API_GetIncomingDisplay(line);

if (callerDetails != null && !callerDetails.isEmpty()) {
System.out.println("Caller Details: " + callerDetails);
}
if (incomingDisplay != null && !incomingDisplay.isEmpty()) {
System.out.println("Incoming Display: " + incomingDisplay);
}
} catch (Exception ex) {
// Ignore errors when getting additional details
}

// Answer the incoming call
System.out.println("Answering call...");
boolean acceptResult = webphoneobj.API_Accept(line);

if (acceptResult) {
System.out.println("Call answered successfully!");
System.out.println("Call is now active on line " + line);
} else {
System.err.println("Failed to answer call. Error code: " + acceptResult);
}

System.out.println("==============================\n");
}

// Handle call connected status
else if (e.getStatus() == SIPNotification.Status.STATUS_CALL_CONNECT) {
System.out.println("Call connected on line " + e.getLine());
}

// Handle call ended status
else if (e.getStatus() == SIPNotification.Status.STATUS_CALL_FINISHED) {
System.out.println("Call ended on line " + e.getLine());
}

// Handle registration status
else if (e.getStatus() == SIPNotification.Status.STATUS_REGISTERED) {
isRegistered = true;
System.out.println("Registration confirmed with SIP server.");
}

else if (e.getStatus() == SIPNotification.Status.STATUS_REGISTERFAILED) {
isRegistered = false;
System.err.println("Unregistered from SIP server.");
}

} catch (Exception ex) {
System.err.println("Error in notification listener: " + ex.getMessage());
ex.printStackTrace();
}
}

// @Override
// public void onMessage(SIPNotification.essage e) {
// // Handle SIP messages if needed
// System.out.println("SIP Message received: " + e.getMessage());
// }
}
}


Подробнее здесь: https://stackoverflow.com/questions/798 ... h-mizu-sdk
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»