@react-three/viverse 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -69
- package/dist/index.js +1 -154
- package/dist/simple.js +1 -1
- package/dist/utils.js +1 -1
- package/dist/viverse.d.ts +69 -0
- package/dist/viverse.js +154 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,72 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import AvatarClient from '@viverse/sdk/avatar-client';
|
|
3
|
-
import { ReactNode } from 'react';
|
|
4
|
-
declare global {
|
|
5
|
-
interface ImportMeta {
|
|
6
|
-
readonly env: {
|
|
7
|
-
readonly VITE_VIVERSE_APP_ID?: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* provides the BvhPhysicsWorld context and the viverse context necassary for accessing any viverse content
|
|
13
|
-
* @param props.loginRequired forces the user to login before playing
|
|
14
|
-
*/
|
|
15
|
-
export declare function Viverse({ children, loginRequired, checkAuth, ...options }: Partial<ClientOptions> & {
|
|
16
|
-
children?: ReactNode;
|
|
17
|
-
loginRequired?: boolean;
|
|
18
|
-
checkAuth?: checkAuthOptions;
|
|
19
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
20
|
-
/**
|
|
21
|
-
* Hook to access the Viverse client instance for making API calls.
|
|
22
|
-
*/
|
|
23
|
-
export declare function useViverseClient(): Client | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Hook to access the current authentication state.
|
|
26
|
-
*/
|
|
27
|
-
export declare function useViverseAuth(): {
|
|
28
|
-
access_token?: string;
|
|
29
|
-
account_id?: string;
|
|
30
|
-
expires_in?: number;
|
|
31
|
-
state?: string;
|
|
32
|
-
} | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Hook to access the Viverse avatar client for avatar-related operations.
|
|
35
|
-
*/
|
|
36
|
-
export declare function useViverseAvatarClient(): AvatarClient | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Hook to fetch and access the user's Viverse profile information.
|
|
39
|
-
* Uses React Suspense for data fetching.
|
|
40
|
-
*/
|
|
41
|
-
export declare function useViverseProfile(): Awaited<ReturnType<AvatarClient['getProfile']>> | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Hook that returns a function to initiate Viverse login flow.
|
|
44
|
-
*/
|
|
45
|
-
export declare function useViverseLogin(): (options?: import("@viverse/sdk").iframeLoginOptions | undefined) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Hook that returns a function to initiate Viverse logout flow.
|
|
48
|
-
*/
|
|
49
|
-
export declare function useViverseLogout(): () => void;
|
|
50
|
-
/**
|
|
51
|
-
* Hook to fetch the user's personal avatar collection.
|
|
52
|
-
* Uses React Suspense for data fetching.
|
|
53
|
-
*/
|
|
54
|
-
export declare function useViverseAvatarList(): Awaited<ReturnType<AvatarClient['getAvatarList']>> | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* Hook to fetch the user's currently active/selected avatar.
|
|
57
|
-
* Uses React Suspense for data fetching.
|
|
58
|
-
*/
|
|
59
|
-
export declare function useViverseActiveAvatar(): Awaited<ReturnType<AvatarClient['getActiveAvatar']>> | undefined;
|
|
60
|
-
/**
|
|
61
|
-
* Hook to fetch the list of publicly available avatars in Viverse.
|
|
62
|
-
* Uses React Suspense for data fetching.
|
|
63
|
-
*/
|
|
64
|
-
export declare function useViversePublicAvatarList(): Awaited<ReturnType<AvatarClient['getPublicAvatarList']>> | undefined;
|
|
65
|
-
/**
|
|
66
|
-
* Hook to fetch a specific public avatar by its ID.
|
|
67
|
-
* Uses React Suspense for data fetching.
|
|
68
|
-
*/
|
|
69
|
-
export declare function useViversePublicAvatarByID(id: string): Awaited<ReturnType<AvatarClient['getPublicAvatarByID']>> | undefined;
|
|
1
|
+
export * from './viverse.js';
|
|
70
2
|
export * from './material.js';
|
|
71
3
|
export * as Vanilla from '@pmndrs/viverse';
|
|
72
4
|
export { EventAction, StateAction, BooleanOr, PointerLockRotateZoomActionBindings, KeyboardLocomotionActionBindings, updateSimpleCharacterVelocity, MoveRightAction, MoveLeftAction, MoveForwardAction, MoveBackwardAction, RunAction, JumpAction, ZoomAction, RotateYawAction, RotatePitchAction, shouldJump, lowerBody, upperBody, WalkAnimationUrl, RunAnimationUrl, IdleAnimationUrl, JumpUpAnimationUrl, JumpLoopAnimationUrl, JumpDownAnimationUrl, FirstPersonCharacterCameraBehavior, BvhCharacterPhysics, type BvhCharacterPhysicsOptions, bvhBoneMap, CharacterCameraBehavior, } from '@pmndrs/viverse';
|
package/dist/index.js
CHANGED
|
@@ -1,157 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { Client } from '@viverse/sdk';
|
|
3
|
-
import AvatarClient from '@viverse/sdk/avatar-client';
|
|
4
|
-
import { createContext, useCallback, useContext } from 'react';
|
|
5
|
-
import { suspend, clear } from 'suspend-react';
|
|
6
|
-
import { BvhPhysicsWorld } from './physics.js';
|
|
7
|
-
// auth
|
|
8
|
-
const viverseCheckAuthSymbol = Symbol('viverse-check-auth');
|
|
9
|
-
const authSuspenseKeys = [];
|
|
10
|
-
function clearViverseAuthCheck() {
|
|
11
|
-
for (const keys of authSuspenseKeys) {
|
|
12
|
-
clear(keys);
|
|
13
|
-
}
|
|
14
|
-
authSuspenseKeys.length = 0;
|
|
15
|
-
}
|
|
16
|
-
function useViverseAuthCheck(client, options) {
|
|
17
|
-
const keys = [viverseCheckAuthSymbol, client, options?.allowedOrigin];
|
|
18
|
-
return suspend(async () => {
|
|
19
|
-
authSuspenseKeys.push(keys);
|
|
20
|
-
return client?.checkAuth({ allowedOrigin: options?.allowedOrigin });
|
|
21
|
-
}, keys);
|
|
22
|
-
}
|
|
23
|
-
// main viverse component
|
|
24
|
-
const ViverseClientContext = createContext(undefined);
|
|
25
|
-
const ViverseAuthContext = createContext(undefined);
|
|
26
|
-
const ViverseAvatarClientContext = createContext(undefined);
|
|
27
|
-
const viverseClientSymbol = Symbol('viverse-client');
|
|
28
|
-
const viverseAvatarClientSymbol = Symbol('viverse-avatar-client');
|
|
29
|
-
/**
|
|
30
|
-
* provides the BvhPhysicsWorld context and the viverse context necassary for accessing any viverse content
|
|
31
|
-
* @param props.loginRequired forces the user to login before playing
|
|
32
|
-
*/
|
|
33
|
-
export function Viverse({ children, loginRequired = false, checkAuth, ...options }) {
|
|
34
|
-
const clientId = options.clientId;
|
|
35
|
-
const client = suspend(async () => clientId == null
|
|
36
|
-
? undefined
|
|
37
|
-
: new Client({
|
|
38
|
-
domain: options.domain ?? 'account.htcvive.com',
|
|
39
|
-
authorizationParams: options.authorizationParams,
|
|
40
|
-
cookieDomain: options.cookieDomain,
|
|
41
|
-
httpTimeoutInMS: options.httpTimeoutInMS,
|
|
42
|
-
clientId,
|
|
43
|
-
}), [
|
|
44
|
-
viverseClientSymbol,
|
|
45
|
-
clientId,
|
|
46
|
-
options.authorizationParams,
|
|
47
|
-
options.cookieDomain,
|
|
48
|
-
options.domain,
|
|
49
|
-
options.httpTimeoutInMS,
|
|
50
|
-
]);
|
|
51
|
-
const auth = useViverseAuthCheck(client);
|
|
52
|
-
if (clientId != null && auth == null && loginRequired) {
|
|
53
|
-
clearViverseAuthCheck();
|
|
54
|
-
client?.loginWithWorlds().catch(console.error);
|
|
55
|
-
}
|
|
56
|
-
const avatarClient = suspend(async () => auth?.access_token != null
|
|
57
|
-
? new AvatarClient({ token: auth.access_token, baseURL: 'https://sdk-api.viverse.com/' })
|
|
58
|
-
: undefined, [viverseAvatarClientSymbol, auth?.access_token]);
|
|
59
|
-
if (client == null) {
|
|
60
|
-
return _jsx(BvhPhysicsWorld, { children: children });
|
|
61
|
-
}
|
|
62
|
-
return (_jsx(ViverseClientContext.Provider, { value: client, children: _jsx(ViverseAuthContext.Provider, { value: auth, children: _jsx(ViverseAvatarClientContext.Provider, { value: avatarClient, children: _jsx(BvhPhysicsWorld, { children: children }) }) }) }));
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Hook to access the Viverse client instance for making API calls.
|
|
66
|
-
*/
|
|
67
|
-
export function useViverseClient() {
|
|
68
|
-
return useContext(ViverseClientContext);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Hook to access the current authentication state.
|
|
72
|
-
*/
|
|
73
|
-
export function useViverseAuth() {
|
|
74
|
-
return useContext(ViverseAuthContext);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Hook to access the Viverse avatar client for avatar-related operations.
|
|
78
|
-
*/
|
|
79
|
-
export function useViverseAvatarClient() {
|
|
80
|
-
return useContext(ViverseAvatarClientContext);
|
|
81
|
-
}
|
|
82
|
-
const viverseProfileSymbol = Symbol('viverse-profile');
|
|
83
|
-
/**
|
|
84
|
-
* Hook to fetch and access the user's Viverse profile information.
|
|
85
|
-
* Uses React Suspense for data fetching.
|
|
86
|
-
*/
|
|
87
|
-
export function useViverseProfile() {
|
|
88
|
-
const avatarClient = useViverseAvatarClient();
|
|
89
|
-
return suspend(async () => avatarClient?.getProfile(), [viverseProfileSymbol, avatarClient]);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Hook that returns a function to initiate Viverse login flow.
|
|
93
|
-
*/
|
|
94
|
-
export function useViverseLogin() {
|
|
95
|
-
const client = useViverseClient();
|
|
96
|
-
return useCallback((...params) => {
|
|
97
|
-
if (client == null) {
|
|
98
|
-
console.warn(`useViverseLogin was called without an available client either because not Viverse provider is available or because no client id was provided to the Viverse provider`);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
clearViverseAuthCheck();
|
|
102
|
-
client.loginWithWorlds(...params);
|
|
103
|
-
}, [client]);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Hook that returns a function to initiate Viverse logout flow.
|
|
107
|
-
*/
|
|
108
|
-
export function useViverseLogout() {
|
|
109
|
-
const client = useViverseClient();
|
|
110
|
-
return useCallback((...params) => {
|
|
111
|
-
if (client == null) {
|
|
112
|
-
console.warn(`useViverseLogout was called without an available client either because not Viverse provider is available or because no client id was provided to the Viverse provider`);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
clearViverseAuthCheck();
|
|
116
|
-
client.logoutWithWorlds(...params);
|
|
117
|
-
}, [client]);
|
|
118
|
-
}
|
|
119
|
-
const viverseAvatarListSymbol = Symbol('viverse-avatar-list');
|
|
120
|
-
/**
|
|
121
|
-
* Hook to fetch the user's personal avatar collection.
|
|
122
|
-
* Uses React Suspense for data fetching.
|
|
123
|
-
*/
|
|
124
|
-
export function useViverseAvatarList() {
|
|
125
|
-
const avatarClient = useViverseAvatarClient();
|
|
126
|
-
return suspend(async () => avatarClient?.getAvatarList(), [viverseAvatarListSymbol, avatarClient]);
|
|
127
|
-
}
|
|
128
|
-
const viverseActiveAvatarSymbol = Symbol('viverse-active-avatar');
|
|
129
|
-
/**
|
|
130
|
-
* Hook to fetch the user's currently active/selected avatar.
|
|
131
|
-
* Uses React Suspense for data fetching.
|
|
132
|
-
*/
|
|
133
|
-
export function useViverseActiveAvatar() {
|
|
134
|
-
const avatarClient = useViverseAvatarClient();
|
|
135
|
-
return suspend(async () => avatarClient?.getActiveAvatar(), [viverseActiveAvatarSymbol, avatarClient]);
|
|
136
|
-
}
|
|
137
|
-
const viversePublicAvatarListSymbol = Symbol('viverse-public-avatar-list');
|
|
138
|
-
/**
|
|
139
|
-
* Hook to fetch the list of publicly available avatars in Viverse.
|
|
140
|
-
* Uses React Suspense for data fetching.
|
|
141
|
-
*/
|
|
142
|
-
export function useViversePublicAvatarList() {
|
|
143
|
-
const avatarClient = useViverseAvatarClient();
|
|
144
|
-
return suspend(async () => avatarClient?.getPublicAvatarList(), [viversePublicAvatarListSymbol, avatarClient]);
|
|
145
|
-
}
|
|
146
|
-
const viversePublicAvatarByIDSymbol = Symbol('viverse-public-avatar-by-id');
|
|
147
|
-
/**
|
|
148
|
-
* Hook to fetch a specific public avatar by its ID.
|
|
149
|
-
* Uses React Suspense for data fetching.
|
|
150
|
-
*/
|
|
151
|
-
export function useViversePublicAvatarByID(id) {
|
|
152
|
-
const avatarClient = useViverseAvatarClient();
|
|
153
|
-
return suspend(async () => avatarClient?.getPublicAvatarByID(id), [viversePublicAvatarByIDSymbol, avatarClient, id]);
|
|
154
|
-
}
|
|
1
|
+
export * from './viverse.js';
|
|
155
2
|
export * from './material.js';
|
|
156
3
|
export * as Vanilla from '@pmndrs/viverse';
|
|
157
4
|
// Direct re-exports from @pmndrs/viverse used in examples and docs
|
package/dist/simple.js
CHANGED
|
@@ -5,10 +5,10 @@ import { Graph, GrapthState, Parallel, RunTimeline, Switch, SwitchCase, timePass
|
|
|
5
5
|
import { forwardRef, Suspense, useImperativeHandle, useRef } from 'react';
|
|
6
6
|
import { LoopOnce, Vector3 } from 'three';
|
|
7
7
|
import { CharacterAnimationAction } from './animation.js';
|
|
8
|
-
import { useViverseActiveAvatar } from './index.js';
|
|
9
8
|
import { CharacterModelProvider } from './model.js';
|
|
10
9
|
import { useBvhCharacterPhysics } from './physics.js';
|
|
11
10
|
import { useCharacterCameraBehavior, useCharacterModelLoader, useSimpleCharacterActionBindings } from './utils.js';
|
|
11
|
+
import { useViverseActiveAvatar } from './viverse.js';
|
|
12
12
|
export const SimpleCharacter = forwardRef(({ input, actionBindings, inputOptions, actionBindingOptions, cameraBehavior, children, movement, physics: physicsOptions, model, useViverseAvatar, animation, ...props }, ref) => {
|
|
13
13
|
useSimpleCharacterActionBindings(actionBindings ?? input, actionBindingOptions ?? inputOptions);
|
|
14
14
|
const internalRef = useRef(null);
|
package/dist/utils.js
CHANGED
|
@@ -4,8 +4,8 @@ import { useFrame, useThree } from '@react-three/fiber';
|
|
|
4
4
|
import { useEffect, useMemo, useRef } from 'react';
|
|
5
5
|
import { suspend } from 'suspend-react';
|
|
6
6
|
import { Object3D } from 'three';
|
|
7
|
-
import { useViverseActiveAvatar } from './index.js';
|
|
8
7
|
import { useBvhPhysicsWorld } from './physics.js';
|
|
8
|
+
import { useViverseActiveAvatar } from './viverse.js';
|
|
9
9
|
export function useCharacterCameraBehavior(model, options) {
|
|
10
10
|
const behaviorRef = useRef(undefined);
|
|
11
11
|
useEffect(() => {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ClientOptions, Client, checkAuthOptions } from '@viverse/sdk';
|
|
2
|
+
import AvatarClient from '@viverse/sdk/avatar-client';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
declare global {
|
|
5
|
+
interface ImportMeta {
|
|
6
|
+
readonly env: {
|
|
7
|
+
readonly VITE_VIVERSE_APP_ID?: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* provides the BvhPhysicsWorld context and the viverse context necassary for accessing any viverse content
|
|
13
|
+
* @param props.loginRequired forces the user to login before playing
|
|
14
|
+
*/
|
|
15
|
+
export declare function Viverse({ children, loginRequired, checkAuth, ...options }: Partial<ClientOptions> & {
|
|
16
|
+
children?: ReactNode;
|
|
17
|
+
loginRequired?: boolean;
|
|
18
|
+
checkAuth?: checkAuthOptions;
|
|
19
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
/**
|
|
21
|
+
* Hook to access the Viverse client instance for making API calls.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useViverseClient(): Client | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Hook to access the current authentication state.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useViverseAuth(): {
|
|
28
|
+
access_token?: string;
|
|
29
|
+
account_id?: string;
|
|
30
|
+
expires_in?: number;
|
|
31
|
+
state?: string;
|
|
32
|
+
} | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Hook to access the Viverse avatar client for avatar-related operations.
|
|
35
|
+
*/
|
|
36
|
+
export declare function useViverseAvatarClient(): AvatarClient | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Hook to fetch and access the user's Viverse profile information.
|
|
39
|
+
* Uses React Suspense for data fetching.
|
|
40
|
+
*/
|
|
41
|
+
export declare function useViverseProfile(): Awaited<ReturnType<AvatarClient['getProfile']>> | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Hook that returns a function to initiate Viverse login flow.
|
|
44
|
+
*/
|
|
45
|
+
export declare function useViverseLogin(): (options?: import("@viverse/sdk").iframeLoginOptions | undefined) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Hook that returns a function to initiate Viverse logout flow.
|
|
48
|
+
*/
|
|
49
|
+
export declare function useViverseLogout(): () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Hook to fetch the user's personal avatar collection.
|
|
52
|
+
* Uses React Suspense for data fetching.
|
|
53
|
+
*/
|
|
54
|
+
export declare function useViverseAvatarList(): Awaited<ReturnType<AvatarClient['getAvatarList']>> | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Hook to fetch the user's currently active/selected avatar.
|
|
57
|
+
* Uses React Suspense for data fetching.
|
|
58
|
+
*/
|
|
59
|
+
export declare function useViverseActiveAvatar(): Awaited<ReturnType<AvatarClient['getActiveAvatar']>> | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Hook to fetch the list of publicly available avatars in Viverse.
|
|
62
|
+
* Uses React Suspense for data fetching.
|
|
63
|
+
*/
|
|
64
|
+
export declare function useViversePublicAvatarList(): Awaited<ReturnType<AvatarClient['getPublicAvatarList']>> | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Hook to fetch a specific public avatar by its ID.
|
|
67
|
+
* Uses React Suspense for data fetching.
|
|
68
|
+
*/
|
|
69
|
+
export declare function useViversePublicAvatarByID(id: string): Awaited<ReturnType<AvatarClient['getPublicAvatarByID']>> | undefined;
|
package/dist/viverse.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Client } from '@viverse/sdk';
|
|
3
|
+
import AvatarClient from '@viverse/sdk/avatar-client';
|
|
4
|
+
import { createContext, useCallback, useContext } from 'react';
|
|
5
|
+
import { suspend, clear } from 'suspend-react';
|
|
6
|
+
import { BvhPhysicsWorld } from './physics.js';
|
|
7
|
+
// auth
|
|
8
|
+
const viverseCheckAuthSymbol = Symbol('viverse-check-auth');
|
|
9
|
+
const authSuspenseKeys = [];
|
|
10
|
+
function clearViverseAuthCheck() {
|
|
11
|
+
for (const keys of authSuspenseKeys) {
|
|
12
|
+
clear(keys);
|
|
13
|
+
}
|
|
14
|
+
authSuspenseKeys.length = 0;
|
|
15
|
+
}
|
|
16
|
+
function useViverseAuthCheck(client, options) {
|
|
17
|
+
const keys = [viverseCheckAuthSymbol, client, options?.allowedOrigin];
|
|
18
|
+
return suspend(async () => {
|
|
19
|
+
authSuspenseKeys.push(keys);
|
|
20
|
+
return client?.checkAuth({ allowedOrigin: options?.allowedOrigin });
|
|
21
|
+
}, keys);
|
|
22
|
+
}
|
|
23
|
+
// main viverse component
|
|
24
|
+
const ViverseClientContext = createContext(undefined);
|
|
25
|
+
const ViverseAuthContext = createContext(undefined);
|
|
26
|
+
const ViverseAvatarClientContext = createContext(undefined);
|
|
27
|
+
const viverseClientSymbol = Symbol('viverse-client');
|
|
28
|
+
const viverseAvatarClientSymbol = Symbol('viverse-avatar-client');
|
|
29
|
+
/**
|
|
30
|
+
* provides the BvhPhysicsWorld context and the viverse context necassary for accessing any viverse content
|
|
31
|
+
* @param props.loginRequired forces the user to login before playing
|
|
32
|
+
*/
|
|
33
|
+
export function Viverse({ children, loginRequired = false, checkAuth, ...options }) {
|
|
34
|
+
const clientId = options.clientId;
|
|
35
|
+
const client = suspend(async () => clientId == null
|
|
36
|
+
? undefined
|
|
37
|
+
: new Client({
|
|
38
|
+
domain: options.domain ?? 'account.htcvive.com',
|
|
39
|
+
authorizationParams: options.authorizationParams,
|
|
40
|
+
cookieDomain: options.cookieDomain,
|
|
41
|
+
httpTimeoutInMS: options.httpTimeoutInMS,
|
|
42
|
+
clientId,
|
|
43
|
+
}), [
|
|
44
|
+
viverseClientSymbol,
|
|
45
|
+
clientId,
|
|
46
|
+
options.authorizationParams,
|
|
47
|
+
options.cookieDomain,
|
|
48
|
+
options.domain,
|
|
49
|
+
options.httpTimeoutInMS,
|
|
50
|
+
]);
|
|
51
|
+
const auth = useViverseAuthCheck(client);
|
|
52
|
+
if (clientId != null && auth == null && loginRequired) {
|
|
53
|
+
clearViverseAuthCheck();
|
|
54
|
+
client?.loginWithWorlds().catch(console.error);
|
|
55
|
+
}
|
|
56
|
+
const avatarClient = suspend(async () => auth?.access_token != null
|
|
57
|
+
? new AvatarClient({ token: auth.access_token, baseURL: 'https://sdk-api.viverse.com/' })
|
|
58
|
+
: undefined, [viverseAvatarClientSymbol, auth?.access_token]);
|
|
59
|
+
if (client == null) {
|
|
60
|
+
return _jsx(BvhPhysicsWorld, { children: children });
|
|
61
|
+
}
|
|
62
|
+
return (_jsx(ViverseClientContext.Provider, { value: client, children: _jsx(ViverseAuthContext.Provider, { value: auth, children: _jsx(ViverseAvatarClientContext.Provider, { value: avatarClient, children: _jsx(BvhPhysicsWorld, { children: children }) }) }) }));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Hook to access the Viverse client instance for making API calls.
|
|
66
|
+
*/
|
|
67
|
+
export function useViverseClient() {
|
|
68
|
+
return useContext(ViverseClientContext);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Hook to access the current authentication state.
|
|
72
|
+
*/
|
|
73
|
+
export function useViverseAuth() {
|
|
74
|
+
return useContext(ViverseAuthContext);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Hook to access the Viverse avatar client for avatar-related operations.
|
|
78
|
+
*/
|
|
79
|
+
export function useViverseAvatarClient() {
|
|
80
|
+
return useContext(ViverseAvatarClientContext);
|
|
81
|
+
}
|
|
82
|
+
const viverseProfileSymbol = Symbol('viverse-profile');
|
|
83
|
+
/**
|
|
84
|
+
* Hook to fetch and access the user's Viverse profile information.
|
|
85
|
+
* Uses React Suspense for data fetching.
|
|
86
|
+
*/
|
|
87
|
+
export function useViverseProfile() {
|
|
88
|
+
const avatarClient = useViverseAvatarClient();
|
|
89
|
+
return suspend(async () => avatarClient?.getProfile(), [viverseProfileSymbol, avatarClient]);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Hook that returns a function to initiate Viverse login flow.
|
|
93
|
+
*/
|
|
94
|
+
export function useViverseLogin() {
|
|
95
|
+
const client = useViverseClient();
|
|
96
|
+
return useCallback((...params) => {
|
|
97
|
+
if (client == null) {
|
|
98
|
+
console.warn(`useViverseLogin was called without an available client either because not Viverse provider is available or because no client id was provided to the Viverse provider`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
clearViverseAuthCheck();
|
|
102
|
+
client.loginWithWorlds(...params);
|
|
103
|
+
}, [client]);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Hook that returns a function to initiate Viverse logout flow.
|
|
107
|
+
*/
|
|
108
|
+
export function useViverseLogout() {
|
|
109
|
+
const client = useViverseClient();
|
|
110
|
+
return useCallback((...params) => {
|
|
111
|
+
if (client == null) {
|
|
112
|
+
console.warn(`useViverseLogout was called without an available client either because not Viverse provider is available or because no client id was provided to the Viverse provider`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
clearViverseAuthCheck();
|
|
116
|
+
client.logoutWithWorlds(...params);
|
|
117
|
+
}, [client]);
|
|
118
|
+
}
|
|
119
|
+
const viverseAvatarListSymbol = Symbol('viverse-avatar-list');
|
|
120
|
+
/**
|
|
121
|
+
* Hook to fetch the user's personal avatar collection.
|
|
122
|
+
* Uses React Suspense for data fetching.
|
|
123
|
+
*/
|
|
124
|
+
export function useViverseAvatarList() {
|
|
125
|
+
const avatarClient = useViverseAvatarClient();
|
|
126
|
+
return suspend(async () => avatarClient?.getAvatarList(), [viverseAvatarListSymbol, avatarClient]);
|
|
127
|
+
}
|
|
128
|
+
const viverseActiveAvatarSymbol = Symbol('viverse-active-avatar');
|
|
129
|
+
/**
|
|
130
|
+
* Hook to fetch the user's currently active/selected avatar.
|
|
131
|
+
* Uses React Suspense for data fetching.
|
|
132
|
+
*/
|
|
133
|
+
export function useViverseActiveAvatar() {
|
|
134
|
+
const avatarClient = useViverseAvatarClient();
|
|
135
|
+
return suspend(async () => avatarClient?.getActiveAvatar(), [viverseActiveAvatarSymbol, avatarClient]);
|
|
136
|
+
}
|
|
137
|
+
const viversePublicAvatarListSymbol = Symbol('viverse-public-avatar-list');
|
|
138
|
+
/**
|
|
139
|
+
* Hook to fetch the list of publicly available avatars in Viverse.
|
|
140
|
+
* Uses React Suspense for data fetching.
|
|
141
|
+
*/
|
|
142
|
+
export function useViversePublicAvatarList() {
|
|
143
|
+
const avatarClient = useViverseAvatarClient();
|
|
144
|
+
return suspend(async () => avatarClient?.getPublicAvatarList(), [viversePublicAvatarListSymbol, avatarClient]);
|
|
145
|
+
}
|
|
146
|
+
const viversePublicAvatarByIDSymbol = Symbol('viverse-public-avatar-by-id');
|
|
147
|
+
/**
|
|
148
|
+
* Hook to fetch a specific public avatar by its ID.
|
|
149
|
+
* Uses React Suspense for data fetching.
|
|
150
|
+
*/
|
|
151
|
+
export function useViversePublicAvatarByID(id) {
|
|
152
|
+
const avatarClient = useViverseAvatarClient();
|
|
153
|
+
return suspend(async () => avatarClient?.getPublicAvatarByID(id), [viversePublicAvatarByIDSymbol, avatarClient, id]);
|
|
154
|
+
}
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@pixiv/three-vrm": "^3.4.2",
|
|
30
30
|
"zustand": "^5.0.6",
|
|
31
31
|
"@react-three/xr": "^6.6.20",
|
|
32
|
-
"@pmndrs/viverse": "^0.2.
|
|
32
|
+
"@pmndrs/viverse": "^0.2.6"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@react-three/fiber": "*"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@types/react": "^19.1.8",
|
|
41
41
|
"react": "^19.1.0"
|
|
42
42
|
},
|
|
43
|
-
"version": "0.2.
|
|
43
|
+
"version": "0.2.6",
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc",
|
|
46
46
|
"check:prettier": "prettier --check src",
|