First commit merge
This commit is contained in:
101
server.js
Normal file
101
server.js
Normal file
@@ -0,0 +1,101 @@
|
||||
import Srf from "drachtio-srf";
|
||||
import logger from "./utils/logger.js";
|
||||
import config from "./config/default.json" with { type: "json" };
|
||||
|
||||
/**
|
||||
* NexusVoice SIP Border Controller - Drachtio Implementation
|
||||
*
|
||||
* This server provides equivalent functionality to the Kamailio configuration:
|
||||
* - SIP request validation and security filtering
|
||||
* - User registration and location management
|
||||
* - Call routing and media handling
|
||||
* - Integration with external systems (Asterisk, RTP proxy)
|
||||
*/
|
||||
class SipServer {
|
||||
/**
|
||||
* Ctor
|
||||
*/
|
||||
constructor() {
|
||||
this.srf = new Srf();
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the SIP server
|
||||
*/
|
||||
async initialize() {
|
||||
try {
|
||||
logger.info("Initializing NexusVoice SBC...");
|
||||
|
||||
// Configure SIP listening parameters
|
||||
const sipConfig = this.config.sip;
|
||||
|
||||
// Connect to drachtio server
|
||||
await this.srf.connect({
|
||||
host: sipConfig.host,
|
||||
port: sipConfig.port,
|
||||
transport: sipConfig.transport,
|
||||
});
|
||||
|
||||
logger.info(
|
||||
"Connected to drachtio server on %s:%s",
|
||||
sipConfig.host,
|
||||
sipConfig.port,
|
||||
);
|
||||
|
||||
logger.info("NexusVoice SBC initialized successfully");
|
||||
} catch (error) {
|
||||
logger.error("Failed to initialize SBC: %s", error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the server
|
||||
*/
|
||||
async start() {
|
||||
try {
|
||||
await this.initialize();
|
||||
logger.info("NexusVoice SBC started successfully");
|
||||
} catch (error) {
|
||||
logger.error("Failed to start SBC: %s", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Graceful shutdown
|
||||
*/
|
||||
async shutdown() {
|
||||
logger.info("Shutting down NexusVoice SBC...");
|
||||
|
||||
try {
|
||||
await this.srf.disconnect();
|
||||
logger.info("NexusVoice SBC shutdown complete");
|
||||
} catch (error) {
|
||||
logger.error("Error during shutdown: %s", error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create and start the server instance
|
||||
const server = new SipServer();
|
||||
|
||||
// Handle graceful shutdown
|
||||
process.on("SIGTERM", async () => {
|
||||
await server.shutdown();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on("SIGINT", async () => {
|
||||
await server.shutdown();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// Start the server
|
||||
server.start().catch((error) => {
|
||||
logger.error("Failed to start server: %s", error.message);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
export default SipServer;
|
||||
Reference in New Issue
Block a user