Пример #1
0
    def cleanup(self):
        """ Close pipes, remove files and temp dir and
            kills the transcoding process.
        """
        if self.__cleanup_executed:
            return

        s = Suppress(Exception)

        # Stop timer if any
        if self.timer is not None:
            self.timer.cancel()

        # Stop all threads
        with s: self.audio.stop()
        with s: self.video.stop()
        with s: self.data_processing.stop()

        # Remove entry from database
        if self._id:
            db.mobile.update({'_id': self._id}, {'$set': {'active': False}})

        # Remove temp directory and thumbnail
        with s: shutil.rmtree(self.tmpdir)
        with s: os.remove(self.thumbnail_path)

        WebsocketBroadcast.select('mobile_location').cls.broadcast_message({
            'name': self.get_stream_name(),
            'info': 'finished'
        })

        self.__cleanup_executed = True
        if s.errors:
            show.warn('Errors during cleanup:', *s.errors, sep='\n', end='\n\n')
        show('Mobile stream "{0}" has ended'.format(self._id))
Пример #2
0
    def _handle_coord(self, data):

        obj = {'time': datetime.datetime.utcnow(),
               'coord': [data['latitude'], data['longitude']]}
        self.latest_position = obj
        db.mobile.update({'_id': self.parent._id},
                         {'$push': {'position': obj}})

        WebsocketBroadcast.select('mobile_location').cls.broadcast_message({
            'name': self.parent.get_stream_name(),
            'info': obj
        })

        show('Stream: {0} | {1} | {2}'.format(
            self.parent._id, obj['time'], obj['coord'])
        )
Пример #3
0
            stream['name'] = MediaHandler.stream_name(stream.pop('_id'))
            stream['position'] = stream['position'][-1] \
                if stream.get('position') else None
            streams.append(stream)

        self.write_message(json_util.dumps({
            'request': 'all',
            'content': streams,
        }))

    def on_message(self, message):
        pass

    def on_close(self):
        with self.lock:
            self.clients.remove(self)

    @classmethod
    def broadcast_message(cls, message, request='update'):
        if request is not None:
            message = {
                'request': request,
                'content': message,
            }
        cls.broadcaster.add_message(json_util.dumps(message))


# Register Broadcaster
MobileStreamLocation.broadcaster = \
    WebsocketBroadcast.register('mobile_location', MobileStreamLocation)