servatrice/webclient/src/websocket/commands/RoomCommands.tsx
Jeremy Letto 8db9475804
Cleanup and refactor (#4361)
* fix three panel layout height issue

* rename websocket/services to websocket/persistence, implement LeaveRoom

* cleanup

* add new line eof

* move route components from /components to /containers

* remove duplicate style

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
2021-05-18 23:06:41 -04:00

48 lines
1.1 KiB
TypeScript

import * as _ from 'lodash';
import { WebClient } from "../WebClient";
export default class RoomCommands {
private webClient: WebClient;
constructor(webClient) {
this.webClient = webClient;
}
roomSay(roomId, message) {
const trimmed = _.trim(message);
if (!trimmed) return;
var CmdRoomSay = this.webClient.pb.Command_RoomSay.create({
"message" : trimmed
});
var rc = this.webClient.pb.RoomCommand.create({
".Command_RoomSay.ext" : CmdRoomSay
});
this.webClient.sendRoomCommand(roomId, rc);
}
leaveRoom(roomId) {
var CmdLeaveRoom = this.webClient.pb.Command_LeaveRoom.create();
var rc = this.webClient.pb.RoomCommand.create({
".Command_LeaveRoom.ext" : CmdLeaveRoom
});
this.webClient.sendRoomCommand(roomId, rc, (raw) => {
const { responseCode } = raw;
switch (responseCode) {
case this.webClient.pb.Response.ResponseCode.RespOk:
this.webClient.persistence.room.leaveRoom(roomId);
break;
default:
console.log(`Failed to leave Room ${roomId} [${responseCode}] : `, raw);
}
});
}
}