Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gonpombo8 committed Dec 20, 2023
1 parent 0f93827 commit b02aaf6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 22 deletions.
3 changes: 3 additions & 0 deletions browser-interface/packages/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export const WSS_ENABLED = !!ensureSingleString(qs.get('ws'))
export const FORCE_SEND_MESSAGE = location.search.includes('FORCE_SEND_MESSAGE')
export const ALLOW_SWIFT_SHADER = location.search.includes('ALLOW_SWIFT_SHADER')

export const DISABLE_SCENE_ROOM = location.search.includes('DISABLE_SCENE_ROOM')
export const DISABLE_ISLAND_SCENE_MESSAGES = location.search.includes('DISABLE_ISLAND_SCENE_MESSAGES')

const ASSET_BUNDLES_DOMAIN = ensureSingleString(qs.get('ASSET_BUNDLES_DOMAIN'))
export const SOCIAL_SERVER_URL = ensureSingleString(qs.get('SOCIAL_SERVER_URL'))

Expand Down
1 change: 0 additions & 1 deletion browser-interface/packages/shared/comms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function sendPublicChatMessage(message: string) {

export function sendParcelSceneCommsMessage(sceneId: string, data: Uint8Array) {
const commsContext = getCommsRoom(store.getState())

commsContext
?.sendParcelSceneMessage({
data,
Expand Down
1 change: 1 addition & 0 deletions browser-interface/packages/shared/comms/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type CommsEvents = CommsAdapterEvents & {
}

export interface RoomConnection {
id?: string
// this operation is non-reversible
disconnect(): Promise<void>
// @once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ export class Rfc4RoomConnection implements RoomConnection {

private positionIndex: number = 0

constructor(private transport: MinimumCommunicationsAdapter, private id: string = '-') {
constructor(private transport: MinimumCommunicationsAdapter, public id: string = '-') {
this.transport.events.on('message', this.handleMessage.bind(this))
this.transport.events.on('DISCONNECTION', (event) => this.events.emit('DISCONNECTION', event))
this.transport.events.on('PEER_DISCONNECTED', (event) => this.events.emit('PEER_DISCONNECTED', event))
}

async connect(): Promise<void> {
console.log('[RoomConnection Comms]: connect', this.id)
// console.log('[RoomConnection Comms]: connect', this.id)
await this.transport.connect()
}

createVoiceHandler(): Promise<VoiceHandler> {
console.log('[RoomConnection Comms]: createVoiceHandler', this.id)
// console.log('[RoomConnection Comms]: createVoiceHandler', this.id)
return this.transport.createVoiceHandler()
}

sendPositionMessage(p: Omit<proto.Position, 'index'>): Promise<void> {
console.log('[RoomConnection Comms]: sendPositionMessage', this.id)
// console.log('[RoomConnection Comms]: sendPositionMessage', this.id)
return this.sendMessage(false, {
message: {
$case: 'position',
Expand All @@ -46,32 +46,32 @@ export class Rfc4RoomConnection implements RoomConnection {
})
}
sendParcelSceneMessage(scene: proto.Scene): Promise<void> {
console.log('[RoomConnection Comms]: sendParcelSceneMessage', this.id)
// console.log('[RoomConnection Comms]: sendParcelSceneMessage', this.id)
return this.sendMessage(false, { message: { $case: 'scene', scene } })
}
sendProfileMessage(profileVersion: proto.AnnounceProfileVersion): Promise<void> {
console.log('[RoomConnection Comms]: sendProfileMessage', this.id)
// console.log('[RoomConnection Comms]: sendProfileMessage', this.id)
return this.sendMessage(false, { message: { $case: 'profileVersion', profileVersion } })
}
sendProfileRequest(profileRequest: proto.ProfileRequest): Promise<void> {
console.log('[RoomConnection Comms]: sendProfileRequest', this.id)
// console.log('[RoomConnection Comms]: sendProfileRequest', this.id)
return this.sendMessage(false, { message: { $case: 'profileRequest', profileRequest } })
}
sendProfileResponse(profileResponse: proto.ProfileResponse): Promise<void> {
console.log('[RoomConnection Comms]: sendProfileResponse', this.id)
// console.log('[RoomConnection Comms]: sendProfileResponse', this.id)
return this.sendMessage(false, { message: { $case: 'profileResponse', profileResponse } })
}
sendChatMessage(chat: proto.Chat): Promise<void> {
console.log('[RoomConnection Comms]: sendChatMessage', this.id)
// console.log('[RoomConnection Comms]: sendChatMessage', this.id)
return this.sendMessage(true, { message: { $case: 'chat', chat } })
}
sendVoiceMessage(voice: proto.Voice): Promise<void> {
console.log('[RoomConnection Comms]: sendVoiceMessage', this.id)
// console.log('[RoomConnection Comms]: sendVoiceMessage', this.id)
return this.sendMessage(false, { message: { $case: 'voice', voice } })
}

async disconnect() {
console.log('[RoomConnection Comms]: disconnect', this.id)
// console.log('[RoomConnection Comms]: disconnect', this.id)
await this.transport.disconnect()
}

Expand All @@ -82,7 +82,7 @@ export class Rfc4RoomConnection implements RoomConnection {
return
}

console.log('[RoomConnection Comms]: handleMessage', message.$case, this.id)
// console.log('[RoomConnection Comms]: handleMessage', message.$case, this.id)
switch (message.$case) {
case 'position': {
this.events.emit('position', { address, data: message.position })
Expand Down
8 changes: 6 additions & 2 deletions browser-interface/packages/shared/comms/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { isBase64 } from 'lib/encoding/base64ToBlob'
import { SET_PARCEL_POSITION } from 'shared/scene-loader/actions'
import { getSceneLoader } from '../scene-loader/selectors'
import { Vector2 } from '../protocol/decentraland/common/vectors.gen'
import { DISABLE_SCENE_ROOM } from '../../config'

const TIME_BETWEEN_PROFILE_RESPONSES = 1000
// this interval should be fast because this will be the delay other people around
Expand Down Expand Up @@ -266,7 +267,7 @@ async function connectAdapter(
}

if (typeof response.fixedAdapter === 'string' && !response.fixedAdapter.startsWith('signed-login:')) {
return connectAdapter(response.fixedAdapter, identity)
return connectAdapter(response.fixedAdapter, identity, id)
}

if (typeof response.message === 'string') {
Expand Down Expand Up @@ -546,6 +547,8 @@ function* sceneRoomComms() {
let currentSceneId: string = ''
const commsSceneToRemove = new Map<string, NodeJS.Timeout>()

if (DISABLE_SCENE_ROOM) return

while (true) {
const reason: { timeout?: unknown; newParcel?: { payload: { position: Vector2 } } } = yield race({
newParcel: take(SET_PARCEL_POSITION),
Expand Down Expand Up @@ -601,7 +604,8 @@ function* connectSceneToComms(sceneId: string) {
const identity: ExplorerIdentity = yield select(getCurrentIdentity)
// TODO: we should change the adapter control to provide this url
const url = 'https://comms-gatekeeper.decentraland.zone/get-scene-adapter'
const response = yield call(signedFetch,
const response = yield call(
signedFetch,
url,
identity,
{ method: 'POST', responseBodyType: 'json' },
Expand Down
26 changes: 19 additions & 7 deletions browser-interface/packages/shared/comms/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const getSceneRooms = (state: RootCommsState): Map<string, RoomConnection
export const getCommsRoom = (state: RootCommsState): RoomConnection | undefined => {
const islandRoom = state.comms.context
const sceneRoom = state.comms.scene

if (!islandRoom) return undefined

return {
connect: async () => {
debugger
Expand All @@ -34,6 +36,8 @@ export const getCommsRoom = (state: RootCommsState): RoomConnection | undefined
await islandRoom.disconnect()
// TBD: should we disconnect from scenes here too ?
},
// TBD: This should be only be sent by the island ?
// We may remove this before reach production, but to think about it
sendProfileMessage: async (profile: AnnounceProfileVersion) => {
const island = islandRoom.sendProfileMessage(profile)
const scene = sceneRoom?.sendProfileMessage(profile)
Expand All @@ -55,22 +59,30 @@ export const getCommsRoom = (state: RootCommsState): RoomConnection | undefined
await Promise.all([island, scene])
},
sendParcelSceneMessage: async (message: Scene) => {
const island = islandRoom.sendParcelSceneMessage(message)
const scene = sceneRoom?.sendParcelSceneMessage(message)
await Promise.all([island, scene])
if (message.sceneId !== sceneRoom?.id) {
console.warn('Ignoring Scene Message', { sceneId: message.sceneId, connectedSceneId: sceneRoom?.id })
return
}
// const island = islandRoom.sendParcelSceneMessage(message)
await sceneRoom?.sendParcelSceneMessage(message)
},
sendChatMessage: async (message: Chat) => {
const island = islandRoom.sendChatMessage(message)
const scene = sceneRoom?.sendChatMessage(message)
await Promise.all([island, scene])
},
sendVoiceMessage: async (_message: Voice) => {
debugger
// TBD: how voice chat works?
sendVoiceMessage: async (message: Voice) => {
if (!sceneRoom) debugger
return sceneRoom!.sendVoiceMessage(message)
},
createVoiceHandler: async () => {
// TBD: Feature flag for backwards compatibility
if (!sceneRoom) debugger
return sceneRoom!.createVoiceHandler()
if (!sceneRoom) {
debugger
throw new Error('Scene room not avaialble')
}
return sceneRoom.createVoiceHandler()
}
} as any as RoomConnection
}
Expand Down

0 comments on commit b02aaf6

Please sign in to comment.