def _msrp_reader(self): while True: try: chunk = self.msrp.read_chunk() if chunk.method in (None, 'REPORT'): continue elif chunk.method == 'SEND': if chunk.content_type in self.accept_types: self.incoming_queue.send(chunk.data) response = make_response(chunk, 200, 'OK') report = make_report(chunk, 200, 'OK') else: response = make_response(chunk, 415, 'Invalid Content-Type') report = None else: response = make_response(chunk, 501, 'Unknown method') report = None if response is not None: self.msrp.write_chunk(response) if report is not None: self.msrp.write_chunk(report) except Exception as e: self.msrp_reader_thread = None # avoid issues caused by the notification handler killing this greenlet during post_notification if self.shutting_down and isinstance(e, ConnectionDone): break self._failure_reason = str(e) NotificationCenter().post_notification( 'MediaStreamDidFail', sender=self, data=NotificationData(context='reading', reason=self._failure_reason)) break
def _handle_incoming_SEND(self, chunk): error = self._check_incoming_SEND(chunk) if error is None: code, comment = 200, 'OK' else: code, comment = error.code, error.comment response = make_response(chunk, code, comment) if response is not None: self.outgoing.send(OutgoingChunk(response)) if code == 200: self._on_incoming_cb(chunk) if self.automatic_reports: report = make_report(chunk, 200, 'OK') if report is not None: self.outgoing.send(OutgoingChunk(report))
def _handle_incoming_SEND(self, chunk): error = self._check_incoming_SEND(chunk) if error is None: code, comment = 200, 'OK' else: code, comment = error.code, error.comment if chunk.final: response = make_response(chunk, code, comment) if response is not None: self.outgoing.send((response, None)) if code == 200: self._on_incoming_cb(chunk) report = make_report(chunk, 200, 'OK') if report is not None: self.outgoing.send((report, None))
def send_report(self, chunk, code, reason): if chunk.method != 'SEND': raise ValueError('reports may only be sent for SEND chunks') report = make_report(chunk, code, reason) if report is not None: self.send_chunk(report)