How to receive Messages?

370 views
Skip to first unread message

Michael Sila

unread,
Mar 30, 2021, 11:26:09 AM3/30/21
to SIP.js
There are several guides on how to send messages, but none on how to receive messages.

This doesn't work:

userAgent.on('message',() => {});

That's the most up to date documentation that's a guide vs just a bunch of github definitions.  There doesn't seem to be a good example of receiving messages either.

Has anyone done this in SIP.JS 0.19? This is basic functionality and I'm extremely disappointing there isn't an example. 

Michael Sila

unread,
Apr 1, 2021, 3:06:40 PM4/1/21
to SIP.js
So I ended up putting an issue in github: https://github.com/onsip/SIP.js/issues/922 .

They answered it there. It's a method you put in the UserAgentDelegate in UserAgentOptions

Diego García Arriaza

unread,
May 15, 2021, 3:02:45 AM5/15/21
to SIP.js
Michael, I am like you, I can send a message, but in my configuration of UserAgentOptions I have defined the onMessage delegate but.... onMessage does not receive nothing.

AND, if I use Messager class, close the open session between two clients...


Can you type here an simple example please???


Thank you!

Diego García Arriaza

unread,
May 15, 2021, 3:54:54 AM5/15/21
to SIP.js
The documentation of sip 0.20 does not have example for receive message. I send with messager.message, with generate a sip.message context, but the receptor listen an oninvite() and not an onmessage() delegate.....

Any help??


This is the current code I have, and i can and receive calls, but not messages.

//CONNECTION
async function connect () {
  try {
   extension = document.getElementById('userExtension').value
   const uri = UserAgent.makeURI(`sip:_EXTENSION_B_@_IP_`)

   const userAgentOptions = {
    authorizationPassword: '_PASS_',
    authorizationUsername: _XXX_,
    transportOptions,
     uri,
     delegate: {
      onInvite,
      onConnect,
      onDisconnect,
      onMessage
     },
    contactName: extension,
    logBuiltinEnabled: false
   }

   userAgent = new UserAgent(userAgentOptions)
   registerer = new Registerer(userAgent)

   await userAgent.start()
   await registerer.register()
  } catch (e) {
    console.log(e)
  }
}

This is what im using right now.
 //SEND MESSAGE
async function sendMessage () {
  try {
   const uri = UserAgent.makeURI(`sip:_EXTENSION_A_@_IP_`)
   messager = new Messager(userAgent, uri, 'Hello world')
   const msg = await messager.message()
  } catch (e) {
   console.error(e)
  }
}

//RECEIVE MESSAGE -----> THIS IS NOT REACHABLE FOR NOW
function onMessage (message) {
  console.log('onMessage', message)
}

//DELEGATE OF USERAGENT. ONINVITE -> HERE I RECEIVE THE INVITATION FOR CALLS. OK, BUT ALSO THE MESSAGES!!
async function onInvite (invitation) {
  try {
   session = invitation
   // Handle incoming session state changes.
   session.stateChange.addListener(newState => {

   switch (newState) {
     case SessionState.Establishing:
      ...
      break
     case SessionState.Established:
    console.log('>>>>> SessionState.Established')
     ...
     break
    default:
     console.log('>>>>> incomingSession stateChange unHandled', newState)
    break
   }
  })
 } catch (e) {
  console.log(e)
  }
}


Any help will be very appreciate. THANKS!!!

host-tune-perform - 3D World & Coding Tutorials

unread,
Mar 8, 2024, 1:10:33 PM3/8/24
to SIP.js
Hi team,

Do we have any answer to below. Even I am getting message in OnInvite and not in OnMessage ?

Regards,
anand goel

Michael Sila

unread,
Mar 8, 2024, 1:41:05 PM3/8/24
to sip...@googlegroups.com
Hi all,

I'm sorry, but I have moved to a different position that does not work with sip.js .

--
You received this message because you are subscribed to a topic in the Google Groups "SIP.js" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sip_js/6ldpU1uu1E8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sip_js+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sip_js/ee3ec0b0-cbc6-416d-964f-a8611a5be3b6n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages