diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 952dba4590..cbefb01830 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -650,6 +650,8 @@ "You are already recording a voice broadcast. Please end your current voice broadcast to start a new one.": "You are already recording a voice broadcast. Please end your current voice broadcast to start a new one.", "You don't have the required permissions to start a voice broadcast in this room. Contact a room administrator to upgrade your permissions.": "You don't have the required permissions to start a voice broadcast in this room. Contact a room administrator to upgrade your permissions.", "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.", + "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.", "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.", "You ended a voice broadcast": "You ended a voice broadcast", diff --git a/src/voice-broadcast/utils/checkVoiceBroadcastPreConditions.tsx b/src/voice-broadcast/utils/checkVoiceBroadcastPreConditions.tsx index ffc525006d..8605ef72f8 100644 --- a/src/voice-broadcast/utils/checkVoiceBroadcastPreConditions.tsx +++ b/src/voice-broadcast/utils/checkVoiceBroadcastPreConditions.tsx @@ -16,6 +16,7 @@ limitations under the License. import React from "react"; import { MatrixClient, Room } from "matrix-js-sdk/src/matrix"; +import { SyncState } from "matrix-js-sdk/src/sync"; import { hasRoomLiveVoiceBroadcast, VoiceBroadcastInfoEventType, VoiceBroadcastRecordingsStore } from ".."; import InfoDialog from "../../components/views/dialogs/InfoDialog"; @@ -67,6 +68,14 @@ const showOthersAlreadyRecordingDialog = () => { }); }; +const showNoConnectionDialog = (): void => { + Modal.createDialog(InfoDialog, { + title: _t("Connection error"), + description:

{_t("Unfortunately we're unable to start a recording right now. Please try again later.")}

, + hasCloseButton: true, + }); +}; + export const checkVoiceBroadcastPreConditions = async ( room: Room, client: MatrixClient, @@ -86,6 +95,11 @@ export const checkVoiceBroadcastPreConditions = async ( return false; } + if (client.getSyncState() === SyncState.Error) { + showNoConnectionDialog(); + return false; + } + const { hasBroadcast, startedByUser } = await hasRoomLiveVoiceBroadcast(client, room, currentUserId); if (hasBroadcast && startedByUser) { diff --git a/test/voice-broadcast/utils/__snapshots__/setUpVoiceBroadcastPreRecording-test.ts.snap b/test/voice-broadcast/utils/__snapshots__/setUpVoiceBroadcastPreRecording-test.ts.snap new file mode 100644 index 0000000000..2d6ba0a409 --- /dev/null +++ b/test/voice-broadcast/utils/__snapshots__/setUpVoiceBroadcastPreRecording-test.ts.snap @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`setUpVoiceBroadcastPreRecording when trying to start a broadcast if there is no connection should show an info dialog and not set up a pre-recording 1`] = ` +[MockFunction] { + "calls": [ + [ + [Function], + { + "description":

+ Unfortunately we're unable to start a recording right now. Please try again later. +

, + "hasCloseButton": true, + "title": "Connection error", + }, + ], + ], + "results": [ + { + "type": "return", + "value": undefined, + }, + ], +} +`; diff --git a/test/voice-broadcast/utils/__snapshots__/startNewVoiceBroadcastRecording-test.ts.snap b/test/voice-broadcast/utils/__snapshots__/startNewVoiceBroadcastRecording-test.ts.snap index fdc7985c88..dd5aa15305 100644 --- a/test/voice-broadcast/utils/__snapshots__/startNewVoiceBroadcastRecording-test.ts.snap +++ b/test/voice-broadcast/utils/__snapshots__/startNewVoiceBroadcastRecording-test.ts.snap @@ -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":

+ Unfortunately we're unable to start a recording right now. Please try again later. +

, + "hasCloseButton": true, + "title": "Connection error", + }, + ], + ], + "results": [ + { + "type": "return", + "value": undefined, + }, + ], +} +`; diff --git a/test/voice-broadcast/utils/setUpVoiceBroadcastPreRecording-test.ts b/test/voice-broadcast/utils/setUpVoiceBroadcastPreRecording-test.ts index 224207f95c..68b5c0ef94 100644 --- a/test/voice-broadcast/utils/setUpVoiceBroadcastPreRecording-test.ts +++ b/test/voice-broadcast/utils/setUpVoiceBroadcastPreRecording-test.ts @@ -16,9 +16,10 @@ limitations under the License. import { mocked } from "jest-mock"; import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; +import { SyncState } from "matrix-js-sdk/src/sync"; +import Modal from "../../../src/Modal"; import { - checkVoiceBroadcastPreConditions, VoiceBroadcastInfoState, VoiceBroadcastPlayback, VoiceBroadcastPlaybacksStore, @@ -30,7 +31,7 @@ import { setUpVoiceBroadcastPreRecording } from "../../../src/voice-broadcast/ut import { mkRoomMemberJoinEvent, stubClient } from "../../test-utils"; import { mkVoiceBroadcastInfoStateEvent } from "./test-utils"; -jest.mock("../../../src/voice-broadcast/utils/checkVoiceBroadcastPreConditions"); +jest.mock("../../../src/Modal"); describe("setUpVoiceBroadcastPreRecording", () => { const roomId = "!room:example.com"; @@ -86,20 +87,19 @@ describe("setUpVoiceBroadcastPreRecording", () => { playbacksStore = new VoiceBroadcastPlaybacksStore(recordingsStore); }); - describe("when the preconditions fail", () => { + describe("when trying to start a broadcast if there is no connection", () => { beforeEach(async () => { - mocked(checkVoiceBroadcastPreConditions).mockResolvedValue(false); + mocked(client.getSyncState).mockReturnValue(SyncState.Error); await setUpPreRecording(); }); - itShouldNotCreateAPreRecording(); + it("should show an info dialog and not set up a pre-recording", () => { + expect(preRecordingStore.getCurrent()).toBeNull(); + expect(Modal.createDialog).toMatchSnapshot(); + }); }); - describe("when the preconditions pass", () => { - beforeEach(() => { - mocked(checkVoiceBroadcastPreConditions).mockResolvedValue(true); - }); - + describe("when setting up a pre-recording", () => { describe("and there is no user id", () => { beforeEach(async () => { mocked(client.getUserId).mockReturnValue(null); @@ -120,17 +120,15 @@ describe("setUpVoiceBroadcastPreRecording", () => { }); describe("and there is a room member and listening to another broadcast", () => { - beforeEach(() => { + beforeEach(async () => { playbacksStore.setCurrent(playback); room.currentState.setStateEvents([mkRoomMemberJoinEvent(userId, roomId)]); - setUpPreRecording(); + await setUpPreRecording(); }); it("should pause the current playback and create a voice broadcast pre-recording", () => { expect(playback.pause).toHaveBeenCalled(); expect(playbacksStore.getCurrent()).toBeNull(); - - expect(checkVoiceBroadcastPreConditions).toHaveBeenCalledWith(room, client, recordingsStore); expect(preRecording).toBeInstanceOf(VoiceBroadcastPreRecording); }); }); diff --git a/test/voice-broadcast/utils/startNewVoiceBroadcastRecording-test.ts b/test/voice-broadcast/utils/startNewVoiceBroadcastRecording-test.ts index afab8278df..5f2447d858 100644 --- a/test/voice-broadcast/utils/startNewVoiceBroadcastRecording-test.ts +++ b/test/voice-broadcast/utils/startNewVoiceBroadcastRecording-test.ts @@ -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 { @@ -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);