ARI and bridging media before Dial

Hi, i’m using ARI and bridge app, to combine video…
The purpose, i have a video intercom, that only sends out black screen video, and i want to replace the incoming call with another media
Below dialplan to 900 works, fine, 6001 is ringing, when 6001 picksup, i can see the video from “999”

Almost perfect, but the media bridging is only joined after i pickup, i want it todo before, so i can see video in early media

exten = 999,1,Answer()
same = n,RTSP-SIP(rtsp://admin:XXX@192.168.0.70:554/Streaming/Channels/102,0,asterisk,5060)

exten => 900,1,Stasis(doorbell-bridge-dial,inbound,PJSIP/6001,Local/999@default)

Is there a way to change this the python app below? Or can it be done in dialplan? So there is somekind of answer, so the video is bridged, and then a new call to 6001?

Script:

import logging
import requests
import ari

logging.basicConfig(level=logging.ERROR)

client = ari.connect('http://localhost:8088', 'xxx', 'xxx')

def safe_hangup(channel):
    """Safely hang up the specified channel"""
    try:
        channel.hangup()
        print "Hung up {}".format(channel.json.get('name'))
    except requests.HTTPError as e:
        if e.response.status_code != requests.codes.not_found:
            raise e

def safe_bridge_destroy(bridge):
    """Safely destroy the specified bridge"""
    try:
        bridge.destroy()
    except requests.HTTPError as e:
        if e.response.status_code != requests.codes.not_found:
            raise e
def stasis_start_cb(channel_obj, ev):
    """Handler for StasisStart"""
    channel = channel_obj.get('channel')
    channel_name = channel.json.get('name')
    args = ev.get('args')
 
    if not args:
        print "Error: {} didn't provide any arguments!".format(channel_name)
        return
 
    if args and args[0] != 'inbound':
        # Only handle inbound channels here
        return

    if len(args) != 3:
        print "Error: {} didn't tell us who to dial".format(channel_name)
        channel.hangup()
        return

    print "{} entered our application".format(channel_name)
    channel.ring()

    try:
        print "Starting video channel {}".format(args[2])
        video = client.channels.originate(endpoint=args[2],
                                             app='doorbell-bridge-dial',
                                             appArgs='dialed',
                                             formats='g722,h264')
    except requests.HTTPError:
        print "Whoops, couldn't add %s for video" % args[2]
        channel.hangup()
        return

    video.on_event('StasisEnd', lambda *args: safe_hangup(channel))
    channel.on_event('StasisEnd', lambda *args: safe_hangup(video))

    bridge = client.bridges.create(type='mixing')
    channel.on_event('StasisEnd', lambda *args: safe_bridge_destroy(bridge))

    try:
        print "Dialing {}".format(args[1])
        outgoing = client.channels.originate(endpoint=args[1],
                                             app='doorbell-bridge-dial',
                                             appArgs='dialed',
                                             callerId=channel.json.get('caller').get('name'),
                                             originator=video.id)
    except requests.HTTPError:
        print "Whoops, pretty sure %s wasn't valid" % args[1]
        channel.hangup()
        return

    channel.on_event('StasisEnd', lambda *args: safe_hangup(outgoing))
    outgoing.on_event('StasisEnd', lambda *args: safe_hangup(channel))

    def outgoing_start_cb(channel_obj, ev):
        """StasisStart handler for our dialed channel"""

        print "{} answered; bridging with {}".format(outgoing.json.get('name'),
                                                     channel.json.get('name'))
        channel.answer()

        bridge.addChannel(channel=[channel.id, outgoing.id, video.id])
        bridge.setVideoSource(channelId=video.id)

    outgoing.on_event('StasisStart', outgoing_start_cb)

client.on_channel_event('StasisStart', stasis_start_cb)
client.run(apps='doorbell-bridge-dial')

Fixed with AMI instead :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.