Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit a2fe442

Browse files
authored
chore: add offline~offline realm for testing (#392)
* wip * lint
1 parent 2f5adfb commit a2fe442

16 files changed

Lines changed: 227 additions & 97 deletions

File tree

package-lock.json

Lines changed: 155 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@
7171
"dependencies": {
7272
"@dcl/catalyst-peer": "^1.0.4",
7373
"@dcl/comms3-transports": "^1.0.0-20220701150400.commit-69b1b53",
74-
"@dcl/crypto": "^3.0.1",
74+
"@dcl/crypto": "^3.1.0",
7575
"@dcl/ecs-math": "^1.0.1",
7676
"@dcl/ecs-quests": "^1.3.1",
77-
"@dcl/feature-flags": "^1.0.1",
77+
"@dcl/feature-flags": "^1.1.0",
7878
"@dcl/hashing": "^1.1.0",
7979
"@dcl/kernel-interface": "^2.0.0-20210922153939.commit-017905d",
8080
"@dcl/legacy-ecs": "^6.10.1-2191620277.commit-7b74643",
8181
"@dcl/protocol": "^1.0.0-2671957171.commit-72389ab",
8282
"@dcl/rpc": "^1.0.1-20220608232056.commit-741737c",
83-
"@dcl/schemas": "^4.7.0",
84-
"@dcl/urn-resolver": "^1.3.2-20220605050328.commit-45a2981",
83+
"@dcl/schemas": "^5.4.6",
84+
"@dcl/urn-resolver": "^1.4.0",
8585
"@redux-saga/simple-saga-monitor": "^1.1.2",
8686
"@types/redux-logger": "^3.0.9",
8787
"blob-to-buffer": "^1.2.8",
88-
"dcl-catalyst-client": "^12.0.1",
88+
"dcl-catalyst-client": "^12.0.8",
8989
"dcl-quests-client": "^2.10.0",
9090
"dcl-scene-writer": "^1.1.2",
9191
"dcl-social-client": "^1.4.1",

packages/shared/comms/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import { InstanceConnection as V3InstanceConnection } from './v3/InstanceConnect
2121
import { removePeerByUUID, removeMissingPeers } from './peers'
2222
import { lastPlayerPositionReport } from 'shared/world/positionThings'
2323
import { ProfileType } from 'shared/profiles/types'
24+
import { OfflineRoomConnection } from './offline-room-connection'
2425

25-
export type CommsVersion = 'v1' | 'v2' | 'v3' | 'v4'
26+
export type CommsVersion = 'v1' | 'v2' | 'v3' | 'v4' | 'offline'
2627
export type CommsMode = CommsV1Mode | CommsV2Mode
2728
export type CommsV1Mode = 'local' | 'remote'
2829
export type CommsV2Mode = 'p2p' | 'server'
@@ -186,6 +187,11 @@ export async function connectComms(realm: Realm): Promise<CommsContext | null> {
186187

187188
break
188189
}
190+
case 'offline': {
191+
connection = new OfflineRoomConnection()
192+
193+
break
194+
}
189195
default: {
190196
throw new Error(`unrecognized comms mode "${COMMS}" "${protocol}"`)
191197
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { CommsEvents, RoomConnection } from '../comms/interface/index'
2+
import mitt from 'mitt'
3+
4+
export class OfflineRoomConnection implements RoomConnection {
5+
events = mitt<CommsEvents>()
6+
7+
constructor() {}
8+
async connect(): Promise<void> {}
9+
async sendPositionMessage() {}
10+
async sendParcelUpdateMessage() {}
11+
async sendProfileMessage() {}
12+
async sendProfileRequest() {}
13+
async sendProfileResponse() {}
14+
async sendInitialMessage() {}
15+
async sendParcelSceneCommsMessage() {}
16+
async sendChatMessage() {}
17+
sendTopicMessage() {}
18+
sendTopicIdentityMessage() {}
19+
async setTopics() {}
20+
async disconnect() {}
21+
async sendVoiceMessage() {}
22+
}

packages/shared/dao/sagas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function* initializeCatalystCandidates() {
217217
}
218218

219219
export async function checkValidRealm(realm: Realm) {
220-
if (realm.protocol === 'v1') {
220+
if (realm.protocol === 'v1' || realm.protocol === 'offline') {
221221
return true
222222
} else if (realm.protocol === 'v2') {
223223
const realmHasValues = realm && realm.hostname

packages/shared/profiles/sagas.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
ProfileSuccessAction,
2424
profileFailure
2525
} from './actions'
26-
import { getCurrentUserProfile, getProfileFromStore } from './selectors'
26+
import { getCurrentUserProfileDirty, getProfileFromStore } from './selectors'
2727
import { buildServerMetadata, ensureAvatarCompatibilityFormat } from './transformations/profileToServerFormat'
2828
import { ContentFile, ProfileType, ProfileUserInfo } from './types'
2929
import { ExplorerIdentity } from 'shared/session/types'
@@ -258,13 +258,18 @@ function* handleSaveLocalAvatar(saveAvatar: SaveProfileDelta) {
258258
const userId: string = yield select(getCurrentUserId)
259259

260260
try {
261-
const savedProfile: Avatar | null = yield select(getCurrentUserProfile)
261+
// get the avatar, no matter if it is in a loading or dirty state
262+
const savedProfile: Avatar | null = yield select(getCurrentUserProfileDirty)
262263
const currentVersion: number = Math.max(savedProfile?.version || 0, 0)
263264

264265
const identity: ExplorerIdentity = yield select(getCurrentIdentity)
265266
const network: ETHEREUM_NETWORK = yield select(getCurrentNetwork)
266267

267-
const profile = {
268+
const profile: Avatar = {
269+
hasClaimedName: false,
270+
name: createFakeName(),
271+
description: '',
272+
tutorialStep: 0,
268273
...savedProfile,
269274
...saveAvatar.payload.profile,
270275
userId,
@@ -281,7 +286,7 @@ function* handleSaveLocalAvatar(saveAvatar: SaveProfileDelta) {
281286
}
282287

283288
// save the profile in the local storage
284-
yield localProfilesRepo.persist(profile.ethAddress, network, profile)
289+
yield apply(localProfilesRepo, 'persist', [profile.ethAddress, network, profile])
285290

286291
// save the profile in the store
287292
yield put(profileSuccess(profile))

packages/shared/profiles/schemaValidation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Avatar, AvatarInfo, generateValidator, JSONSchema } from '@dcl/schemas'
1+
import { Avatar, AvatarInfo, generateLazyValidator, JSONSchema } from '@dcl/schemas'
22

33
/**
44
* The schema validation requires strict IPFS "snapshots"
@@ -20,4 +20,4 @@ const stringSnapshotAvatarSchema: JSONSchema<Avatar> = {
2020
}
2121
} as any
2222

23-
export const validateAvatar = generateValidator<Avatar>(stringSnapshotAvatarSchema)
23+
export const validateAvatar = generateLazyValidator<Avatar>(stringSnapshotAvatarSchema)

packages/shared/profiles/selectors.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ export const getCurrentUserProfile = (store: RootProfileState & RootSessionState
3333
return currentUserId ? getProfile(store, currentUserId) : null
3434
}
3535

36+
export const getCurrentUserProfileDirty = (store: RootProfileState & RootSessionState): Avatar | null => {
37+
const currentUserId = getCurrentUserId(store)
38+
if (!currentUserId) return null
39+
const [_status, data] = getProfileStatusAndData(store, currentUserId)
40+
return data || null
41+
}
42+
3643
export const getCurrentUserProfileStatusAndData = (
3744
store: RootProfileState & RootSessionState
3845
): [ProfileStatus | undefined, Avatar | undefined] => {

packages/shared/quests/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function questsClient() {
1111
const servers = getServerConfigurations(net)
1212
return new QuestsClient({
1313
baseUrl: servers.questsUrl,
14-
authChainProvider: (payload) => Authenticator.signPayload(identity!, payload)
14+
authChainProvider: (payload) => Authenticator.signPayload(identity!, payload) as any
1515
})
1616
}
1717

packages/shared/session/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const authenticate = (provider: IEthereumProvider, isGuest: boolean) =>
1515
export type AuthenticateAction = ReturnType<typeof authenticate>
1616

1717
export const SIGNUP = '[SESSION] SignUp'
18-
export const signUp = (email: string) => action(SIGNUP, { email })
18+
export const signUp = (email: string, name: string) => action(SIGNUP, { email, name })
1919
export type SignUpAction = ReturnType<typeof signUp>
2020

2121
export const USER_AUTHENTIFIED = '[SESSION] User authentified'

0 commit comments

Comments
 (0)