diff --git a/matrix_client/api.py b/matrix_client/api.py index 4ff54f69..77f14806 100644 --- a/matrix_client/api.py +++ b/matrix_client/api.py @@ -254,6 +254,76 @@ def send_message_event(self, room_id, event_type, content, txn_id=None, params["ts"] = timestamp return self._send("PUT", path, content, query_params=params) + def send_call_invite(self, room_id, call_id, sdp, version, lifetime, + msgtype="m.call.invite", timestamp=None): + """Perform PUT /rooms/$room_id/send/m.room.call.invite + + Args: + room_id (str): The room ID to send the event in. + call_id (str): Call identifier string. + sdp (dict): Session Description Protocol dict. + version (int): The version of the VoIP specification this messages adheres to. + lifetime (int): The time in milliseconds that the invite is valid for. + timestamp (int): Set origin_server_ts (For application services only) + """ + return self.send_message_event( + room_id, "m.call.invite", + self.get_call_invite_content(call_id, sdp, version, lifetime), + timestamp=timestamp + ) + + def send_call_answer(self, room_id, call_id, sdp, version, lifetime, + msgtype="m.call.answer", timestamp=None): + """Perform PUT /rooms/$room_id/send/m.room.call.answer + + Args: + room_id (str): The room ID to send the event in. + call_id (str): Call identifier string. + sdp (dict): Session Description Protocol dict. + version (int): The version of the VoIP specification this messages adheres to. + lifetime (int): The time in milliseconds that the answer is valid for. + timestamp (int): Set origin_server_ts (For application services only) + """ + return self.send_message_event( + room_id, "m.call.answer", + self.get_call_answer_content(call_id, sdp, lifetime, version), + timestamp=timestamp + ) + + def send_call_candidates(self, room_id, call_id, candidates, version, + msgtype="m.call.candidates", timestamp=None): + """Perform PUT /rooms/$room_id/send/m.room.call.candidates + + Args: + room_id (str): The room ID to send the event in. + call_id (str): The call identifier string. + candidates (array of dicts): The candidates to send: + each array element contains 'candidate', 'sdpMLineIndex', and 'sdpMid' + version (int): The version of the VoIP specification this messages adheres to. + timestamp (int): Set origin_server_ts (For application services only) + """ + return self.send_message_event( + room_id, "m.call.candidates", + self.get_call_candidates_content(call_id, candidates, version), + timestamp=timestamp + ) + + def send_call_hangup(self, room_id, call_id, version, + msgtype="m.call.hangup", timestamp=None): + """Perform PUT /rooms/$room_id/send/m.room.call.hangup + + Args: + room_id (str): The room ID to send the event in. + call_id (str): The call identifier string. + version (int): The version of the VoIP specification this messages adheres to. + timestamp (int): Set origin_server_ts (For application services only) + """ + return self.send_message_event( + room_id, "m.call.hangup", + self.get_call_hangup_content(call_id, version), + timestamp=timestamp + ) + def redact_event(self, room_id, event_id, reason=None, txn_id=None, timestamp=None): """Perform PUT /rooms/$room_id/redact/$event_id/$txn_id/ @@ -621,6 +691,41 @@ def get_text_body(self, text, msgtype="m.text"): "body": text } + def get_call_invite_content(self, call_id, sdp, version, lifetime, types="offer"): + return{ + "call_id": call_id, + "lifetime": lifetime, + "offer": { + "spd": sdp, + "type": types + }, + "version": version + } + + def get_call_answer_content(self, call_id, sdp, lifetime, version, types="answer"): + return{ + "call_id": call_id, + "lifetime": lifetime, + "answer": { + "sdp": sdp, + "type": types + }, + "version": version + } + + def get_call_candidates_content(self, call_id, candidates, version): + return{ + "call_id": call_id, + "candidates": candidates, + "version": version + } + + def get_call_hangup_content(self, call_id, version): + return{ + "call_id": call_id, + "version": version + } + def get_emote_body(self, text): return { "msgtype": "m.emote", diff --git a/matrix_client/room.py b/matrix_client/room.py index 20b8ca01..239d0bce 100644 --- a/matrix_client/room.py +++ b/matrix_client/room.py @@ -222,6 +222,50 @@ def send_audio(self, url, name, **audioinfo): return self.client.api.send_content(self.room_id, url, name, "m.audio", extra_information=audioinfo) + def send_call_invite(self, call_id, sdp, version, lifetime): + """ Send a call invite event to the room. + + Args: + call_id (str): Random call identifier string. + sdp (dict): Invite Session Description Protocol dict. + version (int): The version of the VoIP specification this message adheres to. + lifetime (int): The time in milliseconds that the invite is valid for. + """ + return self.client.api.send_call_invite(self.room_id, call_id, + sdp, version, lifetime) + + def send_call_answer(self, call_id, sdp, version, lifetime): + """ Send a call answer event to the room. + + Args: + call_id (str): The call identifier string. + sdp (dict): Session Description Protocol dict. + version (int): The version of the VoIP specification this messages adheres to. + lifetime (int): The time in milliseconds that the answer is valid for. + """ + return self.client.api.send_call_answer(self.room_id, call_id, + sdp, version, lifetime) + + def send_call_candidates(self, call_id, candidates, version): + """ Send a call candidates event to the room. + + Args: + call_id (str): The call identifier string. + candidates (dict): The candidates to send + version (int): The version of the VoIP specification this messages adheres to. + """ + return self.client.api.send_call_candidates(self.room_id, call_id, + candidates, version) + + def send_call_hangup(self, call_id, version): + """ Send a call hangup event to the room. + + Args: + call_id (str): The call identifier string. + version (int): The version of the VoIP specification this messages adheres to. + """ + return self.client.api.send_call_hangup(self.room_id, call_id, version) + def redact_message(self, event_id, reason=None): """ Redacts the message with specified event_id in the room. See https://matrix.org/docs/spec/r0.0.1/client_server.html#id112