Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify voice chat #6033

Merged
merged 14 commits into from
Jan 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {

private disposed = false
private readonly room: Room
private voiceHandler: VoiceHandler
private voiceHandler: VoiceHandler | undefined = undefined

constructor(private config: LivekitConfig) {
this.room = new Room()

this.voiceHandler = createLiveKitVoiceHandler(this.room, this.config.globalAudioStream)

this.room
.on(RoomEvent.ParticipantConnected, (_: RemoteParticipant) => {
this.config.logger.log(this.room.name, 'remote participant joined', _.identity)
Expand Down Expand Up @@ -79,7 +77,11 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {
})
}

async createVoiceHandler(): Promise<VoiceHandler> {
async getVoiceHandler(): Promise<VoiceHandler> {
if (!this.voiceHandler) {
this.voiceHandler = createLiveKitVoiceHandler(this.room, this.config.globalAudioStream)
}

return this.voiceHandler
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import mitt from 'mitt'
import { VoiceHandler } from 'shared/voiceChat/VoiceHandler'
import { CommsAdapterEvents, MinimumCommunicationsAdapter, SendHints } from './types'
import { createOpusVoiceHandler } from './voice/opusVoiceHandler'

export class OfflineAdapter implements MinimumCommunicationsAdapter {
events = mitt<CommsAdapterEvents>()

constructor() {}
async createVoiceHandler(): Promise<VoiceHandler> {
return createOpusVoiceHandler()
async getVoiceHandler(): Promise<VoiceHandler | undefined> {
return undefined
}
async disconnect(_error?: Error | undefined): Promise<void> {}
send(_data: Uint8Array, _hints: SendHints): void {}
async connect(): Promise<void> {}
async getParticipants() { return [] }
async getParticipants() {
return []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ import {
Position,
ProfileRequest,
ProfileResponse,
Scene,
Voice
Scene
} from 'shared/protocol/decentraland/kernel/comms/rfc4/comms.gen'
import { lastPlayerPosition } from 'shared/world/positionThings'
import { CommsEvents, RoomConnection } from '../interface'
import { Rfc4RoomConnection } from '../logic/rfc-4-room-connection'
import { CommsAdapterEvents, SendHints } from './types'
import { VoiceHandler } from 'shared/voiceChat/VoiceHandler'
import { createOpusVoiceHandler } from './voice/opusVoiceHandler'

export class SimulationRoom implements RoomConnection {
events = mitt<CommsEvents>()
Expand Down Expand Up @@ -51,17 +49,17 @@ export class SimulationRoom implements RoomConnection {
send(_data: Uint8Array, _hints: SendHints): void {},
async connect(): Promise<void> {},
async disconnect(_error?: Error): Promise<void> {},
async createVoiceHandler() {
throw new Error('not implemented')
async getVoiceHandler(): Promise<VoiceHandler | undefined> {
return undefined
},
async getParticipants() {
return Array.from(peers.keys())
}
})
}

async createVoiceHandler(): Promise<VoiceHandler> {
return createOpusVoiceHandler()
async getVoiceHandler(): Promise<VoiceHandler | undefined> {
return this.roomConnection.getVoiceHandler()
}

async spawnPeer(): Promise<string> {
Expand Down Expand Up @@ -135,9 +133,6 @@ export class SimulationRoom implements RoomConnection {
async sendChatMessage(message: Chat): Promise<void> {
await this.roomConnection.sendChatMessage(message)
}
async sendVoiceMessage(message: Voice): Promise<void> {
await this.roomConnection.sendVoiceMessage(message)
}

update() {
let i = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ExplorerIdentity } from 'shared/session/types'
import { Authenticator } from '@dcl/crypto'
import mitt from 'mitt'
import { CommsAdapterEvents, MinimumCommunicationsAdapter, SendHints } from './types'
import { createOpusVoiceHandler } from './voice/opusVoiceHandler'
import { VoiceHandler } from 'shared/voiceChat/VoiceHandler'
import { notifyStatusThroughChat } from 'shared/chat'
import { wsAsAsyncChannel } from '../logic/ws-async-channel'
Expand Down Expand Up @@ -36,7 +35,10 @@ export class WebSocketAdapter implements MinimumCommunicationsAdapter {

private ws: WebSocket | null = null

constructor(public url: string, private identity: ExplorerIdentity) {}
constructor(
public url: string,
private identity: ExplorerIdentity
) {}

async connect(): Promise<void> {
if (this.ws) throw new Error('Cannot call connect twice per IBrokerTransport')
Expand Down Expand Up @@ -131,8 +133,8 @@ export class WebSocketAdapter implements MinimumCommunicationsAdapter {
}
}

async createVoiceHandler(): Promise<VoiceHandler> {
return createOpusVoiceHandler()
async getVoiceHandler(): Promise<VoiceHandler | undefined> {
return undefined
}

handleWelcomeMessage(welcomeMessage: rfc5.WsWelcome, socket: WebSocket) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface MinimumCommunicationsAdapter {
*/
events: Emitter<CommsAdapterEvents>

createVoiceHandler(): Promise<VoiceHandler>
getVoiceHandler(): Promise<VoiceHandler | undefined>

getParticipants(): Promise<string[]>
}
Expand Down
12 changes: 0 additions & 12 deletions browser-interface/packages/shared/comms/adapters/voice/Html.ts

This file was deleted.

Loading
Loading