janus-gateway icon indicating copy to clipboard operation
janus-gateway copied to clipboard

[1.x] Wrong username after receiving an attended transfer (Sip Plugin)

Open Jonbeckas opened this issue 1 year ago • 6 comments

What version of Janus is this happening on? version: 1.3.0 commit: dfd86e34112f512b3a15ba6b7b52a3aa01ea347a

Have you tested a more recent version of Janus too? No, most recent release

Was this working before? No, also broken on 1.2.2

Is there a gdb or libasan trace of the issue?

Additional context If someone someone is being transfered to you via attended transfer, the username and displayname are not being updated to the now current callee. I guess the problem lies within janus_sip.c somewhere near line 5445, the callee never gets updated there.

Is this the intended behaviour?

Jonbeckas avatar Nov 28 '24 15:11 Jonbeckas

You mean in the demo UI, or in the events the plugin sends from that point on?

lminiero avatar Nov 28 '24 15:11 lminiero

As a side note, call transfers envisage separate handles (typically with helper sessions in the SIP plugin). As such, even when you are transferred, as far as the plugin is concerned that's an entirely new call on a separate resource (the previous call is closed). This means that we don't reuse callers/callees I think.

lminiero avatar Nov 28 '24 15:11 lminiero

In our own application we use "autoaccept_reinvites": false, if we receicve an attended transfer we just get the 'updatingcall' event with a reinvite from the plugin

Jonbeckas avatar Nov 28 '24 15:11 Jonbeckas

I'm not sure I understand. Transfers are done via the REFER method, so when Janus gets it we'll send a transfer event to the application, not updatingcall, as shown here. As a recipient of the refer, you then need to open another handle (e.g., helper session) to originate the new call: trying to update the existing call will fail. As such, I suspect you're using the plugin API incorrectly.

You can find more info in #1815, which is the PR where we first added support for transfers. I also made a presentation (video here) that should help better understand the process.

lminiero avatar Nov 28 '24 16:11 lminiero

We only get an "update" event via the websocket, not a new call on a helper session. We currently initialize the attended transfer directly using the app client of our phone-system 3cx. We also implement helper sessions to accept calls using the replace attribute. I am currently not sure if I've configured janus incorrectly or if its a behaviour of our phone system. The audio does get transferred correctly, just the user- and displayname seem to be wrong.

Jonbeckas avatar Nov 28 '24 16:11 Jonbeckas

I have mitigated the problem by adding the following

			} else {
				janus_mutex_lock(&session->mutex);
				/* New incoming call */
				g_free(session->callee);
				char *caller_text = url_as_string(session->stack->s_home, sip->sip_from->a_url);
				session->callee = g_strdup(caller_text);
				janus_mutex_unlock(&session->mutex);
				su_free(session->stack->s_home, caller_text);
				janus_mutex_lock(&sessions_mutex);
				if(session->callid) {
					/* Track this call-id and tag as a callee */
					janus_sip_call *call = g_hash_table_lookup(callids, session->callid);
					if(call) {
						/* The caller is in this Janus instance too, update the mapping */
						call->callee = session;
					}
				}
				janus_mutex_unlock(&sessions_mutex);
			}

to the nua_i_invite case of the janus_sip_sofia_callback in line 5420 to update the display and username if it differs in a reinvite. Is this ok, or problematic doing this?

Jonbeckas avatar Dec 12 '24 14:12 Jonbeckas