diff --git a/browser-interface/packages/config/index.ts b/browser-interface/packages/config/index.ts index a9ad664fa7..41f55e36e4 100644 --- a/browser-interface/packages/config/index.ts +++ b/browser-interface/packages/config/index.ts @@ -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')) diff --git a/browser-interface/packages/shared/comms/index.ts b/browser-interface/packages/shared/comms/index.ts index 1dd368000b..a7852a74d4 100644 --- a/browser-interface/packages/shared/comms/index.ts +++ b/browser-interface/packages/shared/comms/index.ts @@ -15,7 +15,6 @@ export function sendPublicChatMessage(message: string) { export function sendParcelSceneCommsMessage(sceneId: string, data: Uint8Array) { const commsContext = getCommsRoom(store.getState()) - commsContext ?.sendParcelSceneMessage({ data, diff --git a/browser-interface/packages/shared/comms/interface/index.ts b/browser-interface/packages/shared/comms/interface/index.ts index ada64f423b..fe277ce663 100644 --- a/browser-interface/packages/shared/comms/interface/index.ts +++ b/browser-interface/packages/shared/comms/interface/index.ts @@ -16,6 +16,7 @@ export type CommsEvents = CommsAdapterEvents & { } export interface RoomConnection { + id?: string // this operation is non-reversible disconnect(): Promise // @once diff --git a/browser-interface/packages/shared/comms/logic/rfc-4-room-connection.ts b/browser-interface/packages/shared/comms/logic/rfc-4-room-connection.ts index 3f11e03c8e..d7a7e4ef9c 100644 --- a/browser-interface/packages/shared/comms/logic/rfc-4-room-connection.ts +++ b/browser-interface/packages/shared/comms/logic/rfc-4-room-connection.ts @@ -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 { - console.log('[RoomConnection Comms]: connect', this.id) + // console.log('[RoomConnection Comms]: connect', this.id) await this.transport.connect() } createVoiceHandler(): Promise { - console.log('[RoomConnection Comms]: createVoiceHandler', this.id) + // console.log('[RoomConnection Comms]: createVoiceHandler', this.id) return this.transport.createVoiceHandler() } sendPositionMessage(p: Omit): Promise { - console.log('[RoomConnection Comms]: sendPositionMessage', this.id) + // console.log('[RoomConnection Comms]: sendPositionMessage', this.id) return this.sendMessage(false, { message: { $case: 'position', @@ -46,32 +46,32 @@ export class Rfc4RoomConnection implements RoomConnection { }) } sendParcelSceneMessage(scene: proto.Scene): Promise { - 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 { - 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 { - 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 { - 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 { - 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 { - 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() } @@ -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 }) diff --git a/browser-interface/packages/shared/comms/sagas.ts b/browser-interface/packages/shared/comms/sagas.ts index 5deca6eb2c..31d0fa1cf2 100644 --- a/browser-interface/packages/shared/comms/sagas.ts +++ b/browser-interface/packages/shared/comms/sagas.ts @@ -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 @@ -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') { @@ -546,6 +547,8 @@ function* sceneRoomComms() { let currentSceneId: string = '' const commsSceneToRemove = new Map() + if (DISABLE_SCENE_ROOM) return + while (true) { const reason: { timeout?: unknown; newParcel?: { payload: { position: Vector2 } } } = yield race({ newParcel: take(SET_PARCEL_POSITION), @@ -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' }, diff --git a/browser-interface/packages/shared/comms/selectors.ts b/browser-interface/packages/shared/comms/selectors.ts index a8974df1f0..eb7cb9902a 100644 --- a/browser-interface/packages/shared/comms/selectors.ts +++ b/browser-interface/packages/shared/comms/selectors.ts @@ -24,7 +24,9 @@ export const getSceneRooms = (state: RootCommsState): Map { const islandRoom = state.comms.context const sceneRoom = state.comms.scene + if (!islandRoom) return undefined + return { connect: async () => { debugger @@ -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) @@ -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 }