ARI: Fix endpoint/channel subscription issues; allow for subscriptions to tech
[asterisk/asterisk.git] / channels / chan_pjsip.c
index 5812360..f638a1e 100644 (file)
@@ -371,8 +371,12 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s
                return NULL;
        }
 
-       if (!(chan = ast_channel_alloc(1, state, S_OR(session->id.number.str, ""), S_OR(session->id.name.str, ""), session->endpoint->accountcode, "", "", assignedids, requestor, 0, "PJSIP/%s-%08x", ast_sorcery_object_get_id(session->endpoint),
-               (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1)))) {
+       chan = ast_channel_alloc_with_endpoint(1, state, S_OR(session->id.number.str, ""),
+                                S_OR(session->id.name.str, ""), session->endpoint->accountcode, "",
+                                "", assignedids, requestor, 0, session->endpoint->persistent,
+                                "PJSIP/%s-%08x", ast_sorcery_object_get_id(session->endpoint),
+                                (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1));
+       if (!chan) {
                ao2_ref(caps, -1);
                return NULL;
        }
@@ -455,8 +459,6 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s
                ast_rtp_instance_set_channel_id(pvt->media[SIP_MEDIA_VIDEO]->rtp, ast_channel_uniqueid(chan));
        }
 
-       ast_endpoint_add_channel(session->endpoint->persistent, chan);
-
        return chan;
 }