Add join and leave sounds
This commit is contained in:
@@ -134,6 +134,15 @@ const onActiveSpeakersChanged = (participants: {identity: string}[]) => {
|
|||||||
speakingPubkeys.set(new Set(participants.map(p => p.identity)))
|
speakingPubkeys.set(new Set(participants.map(p => p.identity)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const playJoinSound = () => {
|
||||||
|
const audio = new Audio("/join-voice-room.mp3")
|
||||||
|
audio.play().catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
const onParticipantConnected = () => {
|
||||||
|
playJoinSound()
|
||||||
|
}
|
||||||
|
|
||||||
export const joinVoiceRoom = async (
|
export const joinVoiceRoom = async (
|
||||||
url: string,
|
url: string,
|
||||||
h: string,
|
h: string,
|
||||||
@@ -150,6 +159,7 @@ export const joinVoiceRoom = async (
|
|||||||
const room = new Room({adaptiveStream: true, dynacast: true})
|
const room = new Room({adaptiveStream: true, dynacast: true})
|
||||||
|
|
||||||
room.on(RoomEvent.Disconnected, onRoomDisconnected)
|
room.on(RoomEvent.Disconnected, onRoomDisconnected)
|
||||||
|
room.on(RoomEvent.ParticipantConnected, onParticipantConnected)
|
||||||
room.on(RoomEvent.TrackSubscribed, onTrackSubscribed)
|
room.on(RoomEvent.TrackSubscribed, onTrackSubscribed)
|
||||||
room.on(RoomEvent.TrackUnsubscribed, onTrackUnsubscribed)
|
room.on(RoomEvent.TrackUnsubscribed, onTrackUnsubscribed)
|
||||||
room.on(RoomEvent.ActiveSpeakersChanged, onActiveSpeakersChanged)
|
room.on(RoomEvent.ActiveSpeakersChanged, onActiveSpeakersChanged)
|
||||||
@@ -179,12 +189,17 @@ export const joinVoiceRoom = async (
|
|||||||
currentVoiceSession.set({url, h, room, muted})
|
currentVoiceSession.set({url, h, room, muted})
|
||||||
|
|
||||||
startPresenceHeartbeat(url, h)
|
startPresenceHeartbeat(url, h)
|
||||||
|
|
||||||
|
playJoinSound()
|
||||||
}
|
}
|
||||||
|
|
||||||
export const leaveVoiceRoom = async () => {
|
export const leaveVoiceRoom = async () => {
|
||||||
const session = get(currentVoiceSession)
|
const session = get(currentVoiceSession)
|
||||||
if (!session) return
|
if (!session) return
|
||||||
|
|
||||||
|
const audio = new Audio("/leave-voice-room.mp3")
|
||||||
|
audio.play().catch(() => {})
|
||||||
|
|
||||||
speakingPubkeys.set(new Set())
|
speakingPubkeys.set(new Set())
|
||||||
stopPresenceHeartbeat()
|
stopPresenceHeartbeat()
|
||||||
session.room.disconnect()
|
session.room.disconnect()
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user