mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 12:08:02 -05:00
fix: don't allow message sending before both sides are ready
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
57f7734f7f
commit
233fb263c7
1 changed files with 24 additions and 0 deletions
|
@ -42,6 +42,14 @@ export class MessageTransporter extends EventEmitter2<MessageEventPayloadMap> {
|
|||
* @throws Error if no transport adapter has been set
|
||||
*/
|
||||
public sendMessage<M extends MessageType>(content: Message<M>): void {
|
||||
if (this.transportAdapter === undefined) {
|
||||
console.debug(
|
||||
"Can't send message without transport adapter. Message that couldn't be sent was",
|
||||
content
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.isConnected()) {
|
||||
this.onDisconnecting()
|
||||
console.debug(
|
||||
|
@ -51,6 +59,22 @@ export class MessageTransporter extends EventEmitter2<MessageEventPayloadMap> {
|
|||
return
|
||||
}
|
||||
|
||||
if (
|
||||
!this.thisSideReady &&
|
||||
content.type !== MessageType.READY_REQUEST &&
|
||||
content.type !== MessageType.READY_ANSWER
|
||||
) {
|
||||
throw new Error("Can't send message. This side isn't ready")
|
||||
}
|
||||
|
||||
if (
|
||||
!this.otherSideReady &&
|
||||
content.type !== MessageType.READY_REQUEST &&
|
||||
content.type !== MessageType.READY_ANSWER
|
||||
) {
|
||||
throw new Error("Can't send message. Other side isn't ready")
|
||||
}
|
||||
|
||||
try {
|
||||
this.transportAdapter.send(content)
|
||||
} catch (error: unknown) {
|
||||
|
|
Loading…
Reference in a new issue