WebsocketContext.fromRequest constructor
WebsocketContext.fromRequest(
- ServerMessage msg
Implementation
factory WebsocketContext.fromRequest($wp.ServerMessage msg) {
var eventType = WebsocketEvent.connect;
if (msg.websocketEventRequest.hasDisconnection()) {
eventType = WebsocketEvent.disconnect;
} else if (msg.websocketEventRequest.hasMessage()) {
eventType = WebsocketEvent.message;
}
var message = "";
if (msg.websocketEventRequest.hasMessage()) {
message = utf8.decode(msg.websocketEventRequest.message.body);
}
Map<String, List<String>> queryParams = {};
if (msg.websocketEventRequest.hasConnection()) {
queryParams = msg.websocketEventRequest.connection.queryParams
.map((key, value) => MapEntry(key, value.value));
}
return WebsocketContext(
msg.id,
WebsocketRequest(
msg.websocketEventRequest.socketName,
msg.websocketEventRequest.connectionId,
eventType,
queryParams,
message),
WebsocketResponse(),
);
}