Exemple #1
0
    async def process_update(self, _, update, users, chats):
        if isinstance(
                update,
                types.UpdatePhoneCallSignalingData) and self.native_instance:
            print('receiveSignalingData')
            self.native_instance.receiveSignalingData([x for x in update.data])

        if not isinstance(update, types.UpdatePhoneCall):
            raise pyrogram.ContinuePropagation

        call = update.phone_call
        if not self.call or not call or call.id != self.call.id:
            raise pyrogram.ContinuePropagation
        self.call = call

        if hasattr(call, 'access_hash') and call.access_hash:
            self.call_access_hash = call.access_hash
            self.call_peer = types.InputPhoneCall(
                id=self.call_id, access_hash=self.call_access_hash)
            try:
                await self.received_call()
            except Exception as e:
                print(e)

        if isinstance(call, types.PhoneCallDiscarded):
            self.call_discarded()
            raise pyrogram.StopPropagation
Exemple #2
0
    async def accept(self) -> bool:
        self.update_state('EXCHANGING_KEYS')

        if not self.call:
            self.call_failed()
            raise RuntimeError('call is not set')

        if isinstance(self.call, types.PhoneCallDiscarded):
            print('Call is already discarded')
            self.call_discarded()
            return False

        await self.get_dhc()
        self.b = randint(2, self.dhc.p - 1)
        self.g_b = pow(self.dhc.g, self.b, self.dhc.p)
        self.g_a_hash = self.call.g_a_hash

        try:
            self.call = (await self.client.send(
                functions.phone.AcceptCall(peer=types.InputPhoneCall(
                    id=self.call_id, access_hash=self.call_access_hash),
                                           g_b=i2b(self.g_b),
                                           protocol=self.get_protocol())
            )).phone_call
        except Exception as e:
            print(e)

            await self.discard_call()

            self.stop()
            self.call_discarded()
            return False

        return True
Exemple #3
0
 async def _():
     await self.client.send(
         functions.phone.SendSignalingData(
             # peer=self.call_peer,
             peer=types.InputPhoneCall(
                 id=self.call_id, access_hash=self.call_access_hash),
             data=bytes(data)))
Exemple #4
0
    async def discard_call(self, reason=None):
        if not reason:
            reason = types.PhoneCallDiscardReasonDisconnect()
        try:
            r = await self.client.send(functions.phone.DiscardCall(
                peer=types.InputPhoneCall(id=self.call_id, access_hash=self.call_access_hash),
                duration=0,   # TODO
                connection_id=0,
                reason=reason
            ))
            print(self.call_id)
        except (errors.CallAlreadyDeclined, errors.CallAlreadyAccepted) as e:
            pass

        self.call_ended()
Exemple #5
0
    async def call_accepted(self) -> None:
        self.update_state('EXCHANGING_KEYS')

        await self.get_dhc()
        self.g_b = b2i(self.call.g_b)
        self.check_g(self.g_b, self.dhc.p)
        self.auth_key = pow(self.g_b, self.a, self.dhc.p)
        self.key_fingerprint = calc_fingerprint(self.auth_key_bytes)

        self.call = (await self.client.send(functions.phone.ConfirmCall(
            key_fingerprint=self.key_fingerprint,
            # peer=self.call_peer,
            peer=types.InputPhoneCall(id=self.call_id, access_hash=self.call_access_hash),
            g_a=i2b(self.g_a),
            protocol=self.get_protocol(),
        ))).phone_call

        await self._initiate_encrypted_call()
Exemple #6
0
 async def received_call(self):
     r = await self.client.send(
         functions.phone.ReceivedCall(peer=types.InputPhoneCall(
             id=self.call_id, access_hash=self.call_access_hash)))
     print(r)