Beispiel #1
0
    def hangup_user(self, call_id, user_uuid):
        channel = Channel(call_id, self._ari)
        if not channel.exists() or channel.is_local():
            raise NoSuchCall(call_id)

        if channel.user() != user_uuid:
            raise UserPermissionDenied(user_uuid, {'call': call_id})

        self._ari.channels.hangup(channelId=call_id)
Beispiel #2
0
    def create(self,
               initiator_call,
               destination,
               location,
               completions,
               timeout,
               relocate=None):
        try:
            relocated_channel = Channel(initiator_call,
                                        self.ari).only_connected_channel()
        except TooManyChannels as e:
            raise TooManyChannelCandidates(e.channels)
        except NotEnoughChannels as e:
            raise RelocateCreationError('relocated channel not found')

        initiator_channel = Channel(initiator_call, self.ari)
        if not initiator_channel.exists():
            details = {'initiator_call': initiator_call}
            raise RelocateCreationError('initiator call not found', details)

        try:
            destination = self.destination_factory.from_type(
                destination, location)
        except InvalidDestination:
            details = {'destination': destination, 'location': location}
            raise RelocateCreationError('invalid destination', details)

        with self.duplicate_relocate_lock:
            if self.relocates.find_by_channel(initiator_channel.id):
                raise RelocateAlreadyStarted(initiator_channel.id)

            if not relocate:
                relocate = Relocate(self.state_factory)

            relocate.relocated_channel = relocated_channel.id
            relocate.initiator_channel = initiator_channel.id
            relocate.completions = completions
            relocate.timeout = timeout
            self.relocates.add(relocate)
            self.notifier.observe(relocate)

        with relocate.locked():
            relocate.initiate(destination)

        return relocate