@driftengine/xr 4.8.1 → 4.8.2

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/support.d.ts CHANGED
@@ -35,7 +35,14 @@ export interface XrSupport {
35
35
  /** Empty when a session could be entered. A whole sentence otherwise. */
36
36
  readonly reason: string;
37
37
  }
38
- /** A context that can be asked to become XR compatible. Both backends' contexts satisfy it. */
38
+ /**
39
+ * A context that can be asked to become XR compatible: what `probeXrSupport` looks for on the
40
+ * object it is handed.
41
+ *
42
+ * **Not the parameter's type**, which is any object. One optional member makes this a weak type,
43
+ * and the DOM types do not declare `makeXRCompatible` on `WebGL2RenderingContext`, so typed as this
44
+ * the context every game draws with failed to compile until it was cast.
45
+ */
39
46
  export interface XrCompatibleContext {
40
47
  makeXRCompatible?(): Promise<void>;
41
48
  }
@@ -46,6 +53,6 @@ export interface XrCompatibleContext {
46
53
  * Without one, `compatible` is false and `reason` says the question was not asked, which is a
47
54
  * different thing from asked and refused.
48
55
  */
49
- export declare function probeXrSupport(context?: XrCompatibleContext | null, override?: XrSystem | null): Promise<XrSupport>;
56
+ export declare function probeXrSupport(context?: object | null, override?: XrSystem | null): Promise<XrSupport>;
50
57
  /** The best mode this support answer allows, or null when none is worth asking for. */
51
58
  export declare function bestMode(support: XrSupport): XrMode | null;
package/dist/support.js CHANGED
@@ -68,13 +68,15 @@ override) {
68
68
  ]);
69
69
  let compatible = false;
70
70
  let compatibleReason = '';
71
- if (context?.makeXRCompatible === undefined) {
71
+ const offered = (context ?? null);
72
+ const makeCompatible = typeof offered?.makeXRCompatible === 'function' ? offered.makeXRCompatible.bind(offered) : null;
73
+ if (makeCompatible === null) {
72
74
  compatibleReason =
73
75
  'no rendering context was offered, so whether one can be made XR compatible is unasked.';
74
76
  }
75
77
  else {
76
78
  try {
77
- await context.makeXRCompatible();
79
+ await makeCompatible();
78
80
  compatible = true;
79
81
  }
80
82
  catch (error) {
@@ -96,7 +98,7 @@ override) {
96
98
  */
97
99
  const anyMode = immersiveVr || immersiveAr || inline;
98
100
  let reason = '';
99
- if (context?.makeXRCompatible !== undefined && !compatible) {
101
+ if (makeCompatible !== null && !compatible) {
100
102
  reason = compatibleReason;
101
103
  }
102
104
  else if (!anyMode) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftengine/xr",
3
- "version": "4.8.1",
3
+ "version": "4.8.2",
4
4
  "description": "WebXR sessions, stereo views, controller input and hand joints, over both backends",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -30,7 +30,7 @@
30
30
  "gl-matrix": "^3.4.3"
31
31
  },
32
32
  "peerDependencies": {
33
- "@driftengine/core": "4.8.1"
33
+ "@driftengine/core": "4.8.2"
34
34
  },
35
35
  "author": "Drift Technologies",
36
36
  "repository": {
package/src/support.ts CHANGED
@@ -47,7 +47,14 @@ const NOTHING: XrSupport = {
47
47
  reason: 'this browser has no WebXR: navigator.xr is not defined.',
48
48
  };
49
49
 
50
- /** A context that can be asked to become XR compatible. Both backends' contexts satisfy it. */
50
+ /**
51
+ * A context that can be asked to become XR compatible: what `probeXrSupport` looks for on the
52
+ * object it is handed.
53
+ *
54
+ * **Not the parameter's type**, which is any object. One optional member makes this a weak type,
55
+ * and the DOM types do not declare `makeXRCompatible` on `WebGL2RenderingContext`, so typed as this
56
+ * the context every game draws with failed to compile until it was cast.
57
+ */
51
58
  export interface XrCompatibleContext {
52
59
  makeXRCompatible?(): Promise<void>;
53
60
  }
@@ -78,7 +85,7 @@ async function supports(system: XrSystem, mode: XrMode): Promise<boolean> {
78
85
  * different thing from asked and refused.
79
86
  */
80
87
  export async function probeXrSupport(
81
- context?: XrCompatibleContext | null,
88
+ context?: object | null,
82
89
  /*
83
90
  * The system, overridable for the same reason `enterXr` takes one: a test cannot assign
84
91
  * `globalThis.navigator`, which is getter-only, and stubbing a global to ask a question about a
@@ -97,12 +104,15 @@ export async function probeXrSupport(
97
104
 
98
105
  let compatible = false;
99
106
  let compatibleReason = '';
100
- if (context?.makeXRCompatible === undefined) {
107
+ const offered = (context ?? null) as XrCompatibleContext | null;
108
+ const makeCompatible =
109
+ typeof offered?.makeXRCompatible === 'function' ? offered.makeXRCompatible.bind(offered) : null;
110
+ if (makeCompatible === null) {
101
111
  compatibleReason =
102
112
  'no rendering context was offered, so whether one can be made XR compatible is unasked.';
103
113
  } else {
104
114
  try {
105
- await context.makeXRCompatible();
115
+ await makeCompatible();
106
116
  compatible = true;
107
117
  } catch (error) {
108
118
  const name = (error as Error)?.name ?? 'Error';
@@ -124,7 +134,7 @@ export async function probeXrSupport(
124
134
  */
125
135
  const anyMode = immersiveVr || immersiveAr || inline;
126
136
  let reason = '';
127
- if (context?.makeXRCompatible !== undefined && !compatible) {
137
+ if (makeCompatible !== null && !compatible) {
128
138
  reason = compatibleReason;
129
139
  } else if (!anyMode) {
130
140
  reason =