# 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
        except Exception as e:
            self.sendMessage("ERROR: " + str(e))
            return
        self.sendMessage('SUCCESS')

    def connectionLost(self, reason):
        WebSocketServerProtocol.connectionLost(self, reason)

    def sendMessage(self, payload, isBinary=False, fragmentSize=None, sync=False, doNotCompress=False):
        super(UserInputServerProtocol, self).sendMessage(
            payload=payload,
            isBinary=isBinary,
            fragmentSize=fragmentSize,
            sync=sync,
            doNotCompress=doNotCompress
        )


@implementer(IBroadcaster, interfaces.IConsumer)
class UserInputServerFactory(WebSocketServerFactory):
    _consumer = None
    _clients = None

    def __init__(self, url, consumer):
        super(UserInputServerFactory, self).__init__(url, protocols=[13])
        self._consumer = consumer
        self._consumer.registerProducer(self, True)
        self._clients = []

    def write(self, data):

# 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

        except Exception as e:
            self.sendMessage("ERROR: " + str(e))
            return
        self.sendMessage('SUCCESS')

    def connectionLost(self, reason):
        WebSocketServerProtocol.connectionLost(self, reason)

    def sendMessage(self, payload, isBinary=False, fragmentSize=None, sync=False, doNotCompress=False):
        super(UserInputServerProtocol, self).sendMessage(
            payload=payload,
            isBinary=isBinary,
            fragmentSize=fragmentSize,
            sync=sync,
            doNotCompress=doNotCompress
        )


@implementer(IBroadcaster, interfaces.IConsumer)
class UserInputServerFactory(WebSocketServerFactory):
    _consumer = None
    _clients = None

    def __init__(self, url, consumer):
        super(UserInputServerFactory, self).__init__(url, protocols=[13])
        self._consumer = consumer
        self._consumer.registerProducer(self, True)
        self._clients = []

    def write(self, data):

        self._consumer.write(data)