Skip to content

On Message Event #11

@bharat-gera

Description

@bharat-gera

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions