Skip to content

Commit

Permalink
Check connection before starting broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed Jan 5, 2023
1 parent ecfd173 commit 62deafd
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@
"Someone else is already recording a voice broadcast. Wait for their voice broadcast to end to start a new one.": "Someone else is already recording a voice broadcast. Wait for their voice broadcast to end to start a new one.",
"Can’t start a call": "Can’t start a call",
"You can’t start a call as you are currently recording a live broadcast. Please end your live broadcast in order to start a call.": "You can’t start a call as you are currently recording a live broadcast. Please end your live broadcast in order to start a call.",
"Connection error": "Connection error",
"Unfortunately we're unable to start a recording right now. Please try again later.": "Unfortunately we're unable to start a recording right now. Please try again later.",
"You ended a <a>voice broadcast</a>": "You ended a <a>voice broadcast</a>",
"%(senderName)s ended a <a>voice broadcast</a>": "%(senderName)s ended a <a>voice broadcast</a>",
"You ended a voice broadcast": "You ended a voice broadcast",
Expand Down
1 change: 1 addition & 0 deletions src/voice-broadcast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export * from "./utils/retrieveStartedInfoEvent";
export * from "./utils/shouldDisplayAsVoiceBroadcastRecordingTile";
export * from "./utils/shouldDisplayAsVoiceBroadcastTile";
export * from "./utils/shouldDisplayAsVoiceBroadcastStoppedText";
export * from "./utils/showCantStartRecordingNoConnectionDialog";
export * from "./utils/startNewVoiceBroadcastRecording";
export * from "./utils/textForVoiceBroadcastStoppedEvent";
export * from "./utils/textForVoiceBroadcastStoppedEventWithoutLink";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from "react";

import InfoDialog from "../../components/views/dialogs/InfoDialog";
import { _t } from "../../languageHandler";
import Modal from "../../Modal";

export const showCantStartRecordingNoConnectionDialog = (): void => {
Modal.createDialog(InfoDialog, {
title: _t("Connection error"),
description: <p>{_t("Unfortunately we're unable to start a recording right now. Please try again later.")}</p>,
hasCloseButton: true,
});
};
8 changes: 8 additions & 0 deletions src/voice-broadcast/utils/startNewVoiceBroadcastRecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

import { ISendEventResponse, MatrixClient, Room, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import { SyncState } from "matrix-js-sdk/src/sync";
import { defer } from "matrix-js-sdk/src/utils";

import {
Expand All @@ -25,6 +26,7 @@ import {
VoiceBroadcastRecording,
getChunkLength,
VoiceBroadcastPlaybacksStore,
showCantStartRecordingNoConnectionDialog,
} from "..";
import { checkVoiceBroadcastPreConditions } from "./checkVoiceBroadcastPreConditions";

Expand Down Expand Up @@ -92,6 +94,12 @@ export const startNewVoiceBroadcastRecording = async (
return null;
}

if (client.getSyncState() === SyncState.Error) {
console.log("wuhurst");
showCantStartRecordingNoConnectionDialog();
return null;
}

// pause and clear current playback (if any)
playbacksStore.getCurrent()?.pause();
playbacksStore.clearCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,26 @@ exports[`startNewVoiceBroadcastRecording when the current user is not allowed to
],
}
`;

exports[`startNewVoiceBroadcastRecording when trying to start a broadcast if there is no connection should show an info dialog and not start a recording 1`] = `
[MockFunction] {
"calls": [
[
[Function],
{
"description": <p>
Unfortunately we're unable to start a recording right now. Please try again later.
</p>,
"hasCloseButton": true,
"title": "Connection error",
},
],
],
"results": [
{
"type": "return",
"value": undefined,
},
],
}
`;
13 changes: 13 additions & 0 deletions test/voice-broadcast/utils/startNewVoiceBroadcastRecording-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

import { mocked } from "jest-mock";
import { EventType, ISendEventResponse, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
import { SyncState } from "matrix-js-sdk/src/sync";

import Modal from "../../../src/Modal";
import {
Expand Down Expand Up @@ -103,6 +104,18 @@ describe("startNewVoiceBroadcastRecording", () => {
jest.clearAllMocks();
});

describe("when trying to start a broadcast if there is no connection", () => {
beforeEach(async () => {
mocked(client.getSyncState).mockReturnValue(SyncState.Error);
result = await startNewVoiceBroadcastRecording(room, client, playbacksStore, recordingsStore);
});

it("should show an info dialog and not start a recording", () => {
expect(result).toBeNull();
expect(Modal.createDialog).toMatchSnapshot();
});
});

describe("when the current user is allowed to send voice broadcast info state events", () => {
beforeEach(() => {
mocked(room.currentState.maySendStateEvent).mockReturnValue(true);
Expand Down

0 comments on commit 62deafd

Please sign in to comment.