Fitblip/wsstat

On Message Event

Opened this issue · 0 comments

I have number of websocket connections connected,what if I want to send message on that connection from using some function. Do we have any utility function in the library for the same?
I was trying to something like this:

import json
from .clients import WebsocketTestingClient
messageTypes = {
'handshake': 'hello',
'chan_register': 'register'
}
class WPushClient(WebsocketTestingClient):

def _construct_event_payload(self, request_type, **kwargs):
    data = dict()
    data['messageType'] = messageTypes[request_type]
    data.update(**kwargs)
    return json.dumps(data)

def _handshake_request(self):
    payload =  self._construct_event_payload('handshake', use_webpush=True)
    return payload

def after_connect(self, statedict):
    msg = self._handshake_request()
    self.logger.log(msg)
    statedict['connected_websocket'].ws.sendMessage(msg)

I was unable to send the "msg" on the websocket connection?