# Path: ebu_tt_live/strings.py
# ERR_WS_INVALID_ACTION = gettext('Invalid action: {action}')
# 
# ERR_WS_NOT_CONSUMER = gettext('This socket does not belong to a consumer')
# 
# ERR_WS_NOT_PRODUCER = gettext('This socket does not belong to a producer.')
# 
# ERR_WS_RECEIVE_VIA_PRODUCER = gettext('Producer socket cannot be used to receive data')
# 
# ERR_WS_SEND_VIA_CONSUMER = gettext('Consumer socket cannot be used to send data')
# 
# Path: ebu_tt_live/errors.py
# class UnexpectedSequenceIdentifierError(Exception):
#     pass


from autobahn.twisted.websocket import WebSocketClientProtocol, WebSocketServerFactory, WebSocketServerProtocol, \
    listenWS, WebSocketClientFactory, connectWS
from twisted.internet import interfaces, reactor
from hyperlink import URL
from zope.interface import implementer
from logging import getLogger
from ebu_tt_live.strings import ERR_WS_INVALID_ACTION, ERR_WS_NOT_CONSUMER, ERR_WS_NOT_PRODUCER, \
    ERR_WS_RECEIVE_VIA_PRODUCER, ERR_WS_SEND_VIA_CONSUMER
from ebu_tt_live.errors import UnexpectedSequenceIdentifierError
from .base import IBroadcaster
import json
import six
            self, sequence_identifier, payload, isBinary=False, fragmentSize=None, sync=False, doNotCompress=False
    ):
        if self.action == 'publish':
            self._send_sequence_message(
                sequence_identifier=sequence_identifier,
                payload=payload,
                isBinary=isBinary,
                fragmentSize=fragmentSize,
                sync=sync,
                doNotCompress=doNotCompress
            )
        else:
            log.error(ERR_WS_SEND_VIA_CONSUMER)
            self.dropConnection(abort=True)

    def connectionLost(self, reason):
        WebSocketClientProtocol.connectionLost(self, reason)
        self.factory.unregister(self)


class BroadcastClientFactory(BroadcastFactoryCommon, WebSocketClientFactory):

    def __init__(self, url, consumer=None, producer=None, *args, **kwargs):
        super(BroadcastClientFactory, self).__init__(url=url, *args, **kwargs)
        self.producer = producer
        self.consumer = consumer

    def register(self, client):
        if client.action == 'subscribe':
            if self.consumer is None:

# Path: ebu_tt_live/strings.py
# ERR_WS_INVALID_ACTION = gettext('Invalid action: {action}')
# 
# ERR_WS_NOT_CONSUMER = gettext('This socket does not belong to a consumer')
# 
# ERR_WS_NOT_PRODUCER = gettext('This socket does not belong to a producer.')
# 
# ERR_WS_RECEIVE_VIA_PRODUCER = gettext('Producer socket cannot be used to receive data')
# 
# ERR_WS_SEND_VIA_CONSUMER = gettext('Consumer socket cannot be used to send data')
# 
# Path: ebu_tt_live/errors.py
# class UnexpectedSequenceIdentifierError(Exception):
#     pass


# Path: ebu_tt_live/twisted/websocket.py
from autobahn.twisted.websocket import WebSocketClientProtocol, WebSocketServerFactory, WebSocketServerProtocol, \
    listenWS, WebSocketClientFactory, connectWS
from twisted.internet import interfaces, reactor
from hyperlink import URL
from zope.interface import implementer
from logging import getLogger
from ebu_tt_live.strings import ERR_WS_INVALID_ACTION, ERR_WS_NOT_CONSUMER, ERR_WS_NOT_PRODUCER, \
    ERR_WS_RECEIVE_VIA_PRODUCER, ERR_WS_SEND_VIA_CONSUMER
from ebu_tt_live.errors import UnexpectedSequenceIdentifierError
from .base import IBroadcaster
import json
import six

            self, sequence_identifier, payload, isBinary=False, fragmentSize=None, sync=False, doNotCompress=False
    ):
        if self.action == 'publish':
            self._send_sequence_message(
                sequence_identifier=sequence_identifier,
                payload=payload,
                isBinary=isBinary,
                fragmentSize=fragmentSize,
                sync=sync,
                doNotCompress=doNotCompress
            )
        else:
            log.error(ERR_WS_SEND_VIA_CONSUMER)
            self.dropConnection(abort=True)

    def connectionLost(self, reason):
        WebSocketClientProtocol.connectionLost(self, reason)
        self.factory.unregister(self)


class BroadcastClientFactory(BroadcastFactoryCommon, WebSocketClientFactory):

    def __init__(self, url, consumer=None, producer=None, *args, **kwargs):
        super(BroadcastClientFactory, self).__init__(url=url, *args, **kwargs)
        self.producer = producer
        self.consumer = consumer

    def register(self, client):
        if client.action == 'subscribe':
            if self.consumer is None:

                log.error(ERR_WS_NOT_CONSUMER)