This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add voice broadcast playback pip (#9603)
- Loading branch information
1 parent
eacaa34
commit cf7d9e3
Showing
13 changed files
with
372 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/voice-broadcast/hooks/useCurrentVoiceBroadcastPlayback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2022 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 { useState } from "react"; | ||
|
||
import { useTypedEventEmitter } from "../../hooks/useEventEmitter"; | ||
import { VoiceBroadcastPlayback } from "../models/VoiceBroadcastPlayback"; | ||
import { | ||
VoiceBroadcastPlaybacksStore, | ||
VoiceBroadcastPlaybacksStoreEvent, | ||
} from "../stores/VoiceBroadcastPlaybacksStore"; | ||
|
||
export const useCurrentVoiceBroadcastPlayback = ( | ||
voiceBroadcastPlaybackStore: VoiceBroadcastPlaybacksStore, | ||
) => { | ||
const [currentVoiceBroadcastPlayback, setVoiceBroadcastPlayback] = useState( | ||
voiceBroadcastPlaybackStore.getCurrent(), | ||
); | ||
|
||
useTypedEventEmitter( | ||
voiceBroadcastPlaybackStore, | ||
VoiceBroadcastPlaybacksStoreEvent.CurrentChanged, | ||
(playback: VoiceBroadcastPlayback) => { | ||
setVoiceBroadcastPlayback(playback); | ||
}, | ||
); | ||
|
||
return { | ||
currentVoiceBroadcastPlayback, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/voice-broadcast/utils/doClearCurrentVoiceBroadcastPlaybackIfStopped.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2022 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 { VoiceBroadcastPlaybacksStore, VoiceBroadcastPlaybackState } from ".."; | ||
|
||
export const doClearCurrentVoiceBroadcastPlaybackIfStopped = ( | ||
voiceBroadcastPlaybacksStore: VoiceBroadcastPlaybacksStore, | ||
) => { | ||
if (voiceBroadcastPlaybacksStore.getCurrent()?.getState() === VoiceBroadcastPlaybackState.Stopped) { | ||
// clear current if stopped | ||
return; | ||
} | ||
}; |
64 changes: 64 additions & 0 deletions
64
src/voice-broadcast/utils/doMaybeSetCurrentVoiceBroadcastPlayback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright 2022 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 { MatrixClient, Room } from "matrix-js-sdk/src/matrix"; | ||
|
||
import { | ||
hasRoomLiveVoiceBroadcast, | ||
VoiceBroadcastPlaybacksStore, | ||
VoiceBroadcastPlaybackState, | ||
VoiceBroadcastRecordingsStore, | ||
} from ".."; | ||
|
||
/** | ||
* When a live voice broadcast is in the room and | ||
* another voice broadcast is not currently being listened to or recorded | ||
* the live broadcast in the room is set as the current broadcast to listen to. | ||
* When there is no live broadcast in the room: clear current broadcast. | ||
* | ||
* @param {Room} room The room to check for a live voice broadcast | ||
* @param {MatrixClient} client | ||
* @param {VoiceBroadcastPlaybacksStore} voiceBroadcastPlaybacksStore | ||
* @param {VoiceBroadcastRecordingsStore} voiceBroadcastRecordingsStore | ||
*/ | ||
export const doMaybeSetCurrentVoiceBroadcastPlayback = ( | ||
room: Room, | ||
client: MatrixClient, | ||
voiceBroadcastPlaybacksStore: VoiceBroadcastPlaybacksStore, | ||
voiceBroadcastRecordingsStore: VoiceBroadcastRecordingsStore, | ||
): void => { | ||
// do not disturb the current recording | ||
if (voiceBroadcastRecordingsStore.hasCurrent()) return; | ||
|
||
const currentPlayback = voiceBroadcastPlaybacksStore.getCurrent(); | ||
|
||
if (currentPlayback && currentPlayback.getState() !== VoiceBroadcastPlaybackState.Stopped) { | ||
// do not disturb the current playback | ||
return; | ||
} | ||
|
||
const { infoEvent } = hasRoomLiveVoiceBroadcast(room); | ||
|
||
if (infoEvent) { | ||
// live broadcast in the room + no recording + not listening yet: set the current broadcast | ||
const voiceBroadcastPlayback = voiceBroadcastPlaybacksStore.getByInfoEvent(infoEvent, client); | ||
voiceBroadcastPlaybacksStore.setCurrent(voiceBroadcastPlayback); | ||
return; | ||
} | ||
|
||
// no broadcast; not listening: clear current | ||
voiceBroadcastPlaybacksStore.clearCurrent(); | ||
}; |
Oops, something went wrong.