versatica / JsSIP

JsSIP, the JavaScript SIP library
https://jssip.net
Other
2.42k stars 744 forks source link

I want to send and Receive message using JSSIP #847

Closed PMCME closed 8 months ago

PMCME commented 8 months ago

import React, { useEffect } from 'react'; import JsSIP from 'jssip';

const SIPComponent = () => { useEffect(() => { const configuration = { uri: 'sip:example@example.com', password: 'your_password', ws_servers: 'wss://your_sip_server_address', };

const userAgent = new JsSIP.UA(configuration);

// Start SIP stack
userAgent.start();

// Register callbacks
userAgent.on('registered', () => {
  console.log('SIP User Agent Registered');
});

userAgent.on('newMessage', (e) => {
  const message = e.data.message;
  console.log('New SIP message received:', message);
});

// Handle errors
userAgent.on('disconnected', (e) => {
  console.log('SIP User Agent Disconnected:', e);
});

// Sending a SIP message
const sendMessage = () => {
  const destination = 'sip:recipient@example.com';
  const message = 'Hello, this is a SIP message!';
  userAgent.sendMessage(destination, message);
};

// Clean up
return () => {
  userAgent.stop();
};

}, []); // Run effect only once on component mount

return (

); };

export default SIPComponent;

Send message is working but another side newMessage event is not triggering.