@webspatial/core-sdk 0.1.10 → 0.1.13

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.
@@ -7,6 +7,33 @@ import {
7
7
  sceneDataJSBShape,
8
8
  } from '../types'
9
9
 
10
+ declare global {
11
+ interface Window {
12
+ // Location for webspatial custom functions
13
+ __WebSpatialData: {
14
+ androidNativeMessage: Function
15
+ getNativeVersion: Function
16
+ }
17
+
18
+ // Location for webspatial internal callbacks (eg. completion events)
19
+ __SpatialWebEvent: Function
20
+
21
+ // Used to access webkit specific api
22
+ webkit: any
23
+
24
+ // Marks the page as unloaded so it doesn't send additional events
25
+ __WebSpatialUnloaded: boolean
26
+
27
+ // Internal id information mapping to internal state about the native window
28
+ _webSpatialID: string
29
+ _webSpatialGroupID: string
30
+ _webSpatialParentGroupID: string
31
+
32
+ // Will be removed in favor of __WebSpatialData
33
+ WebSpatailNativeVersion: string
34
+ }
35
+ }
36
+
10
37
  export class WindowContainer {
11
38
  id = ''
12
39
  }
@@ -41,7 +68,7 @@ export class WebSpatial {
41
68
  }
42
69
 
43
70
  static init() {
44
- ;(window as any).__SpatialWebEvent = (e: any) => {
71
+ window.__SpatialWebEvent = (e: any) => {
45
72
  if (e.resourceId) {
46
73
  var callback = WebSpatial.eventReceivers[e.resourceId]
47
74
  callback(e.data)
@@ -77,7 +104,7 @@ export class WebSpatial {
77
104
  }
78
105
 
79
106
  static getBackend() {
80
- if ((window as any).webkit) {
107
+ if (window.webkit) {
81
108
  return 'AVP'
82
109
  } else {
83
110
  return 'UNKNOWN'
@@ -85,7 +112,7 @@ export class WebSpatial {
85
112
  }
86
113
 
87
114
  static async sendCommand(cmd: RemoteCommand) {
88
- if ((window as any).__WebSpatialUnloaded) {
115
+ if (window.__WebSpatialUnloaded) {
89
116
  return
90
117
  }
91
118
  if (WebSpatial.transactionStarted) {
@@ -96,10 +123,10 @@ export class WebSpatial {
96
123
  var msg = JSON.stringify(cmd)
97
124
 
98
125
  if (WebSpatial.getBackend() == 'AVP') {
99
- ;(window as any).webkit.messageHandlers.bridge.postMessage(msg)
126
+ window.webkit.messageHandlers.bridge.postMessage(msg)
100
127
  return
101
128
  } else {
102
- ;(window as any).bridge.nativeMessage(msg)
129
+ window.__WebSpatialData.androidNativeMessage(msg)
103
130
  return
104
131
  }
105
132
  }
@@ -132,13 +159,13 @@ export class WebSpatial {
132
159
  const { window: newWindow, ...sceneData } = cfg.sceneData
133
160
  const jsbSceneData: sceneDataJSBShape = {
134
161
  ...sceneData,
135
- windowID: (newWindow as any)._webSpatialID,
136
- windowContainerID: (newWindow as any)._webSpatialGroupID,
162
+ windowID: newWindow._webSpatialID,
163
+ windowContainerID: newWindow._webSpatialGroupID,
137
164
  }
138
165
  var cmd = new RemoteCommand('createScene', {
139
166
  windowStyle: style,
140
167
  sceneData: jsbSceneData,
141
- windowContainerID: (window as any)._webSpatialParentGroupID, // parent WindowContainerID
168
+ windowContainerID: window._webSpatialParentGroupID, // parent WindowContainerID
142
169
  })
143
170
 
144
171
  try {
@@ -311,7 +338,7 @@ export class WebSpatial {
311
338
 
312
339
  static async setLoading(method: LoadingMethodKind, style?: string) {
313
340
  var cmd = new RemoteCommand('setLoading', {
314
- windowContainerID: (window as any)._webSpatialParentGroupID, // parent WindowContainerID
341
+ windowContainerID: window._webSpatialParentGroupID, // parent WindowContainerID
315
342
  loading: {
316
343
  method,
317
344
  style,
@@ -0,0 +1,12 @@
1
+ declare global {
2
+ interface Window {
3
+ __webspatialsdk__?: {
4
+ XR_ENV?: string
5
+ 'natvie-version'?: string
6
+ 'react-sdk-version'?: string
7
+ 'core-sdk-version'?: string
8
+ }
9
+ }
10
+ declare const __WEBSPATIAL_CORE_SDK_VERSION__: string
11
+ }
12
+ export {}
package/tsconfig.json CHANGED
@@ -21,6 +21,6 @@
21
21
  "outDir": "./dist",
22
22
  "allowSyntheticDefaultImports": true
23
23
  },
24
- "include": ["src/index.ts"],
24
+ "include": ["src/index.ts", "src/types/*.d.ts"],
25
25
  "references": []
26
26
  }
package/tsup.config.ts CHANGED
@@ -1,11 +1,24 @@
1
1
  // tsup.config.ts
2
2
  import { defineConfig, Options } from 'tsup'
3
-
3
+ import { version } from './package.json'
4
4
  const baseConfig: Options = {
5
5
  splitting: false,
6
6
  sourcemap: true,
7
7
  clean: true,
8
8
  dts: true,
9
+ banner: {
10
+ js: `
11
+ (function(){
12
+ if(typeof window === 'undefined') return;
13
+ if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
14
+ window.__webspatialsdk__['core-sdk-version'] = ${JSON.stringify(version)}
15
+ })()
16
+ `,
17
+ },
18
+ }
19
+
20
+ const versionDefine = {
21
+ __WEBSPATIAL_CORE_SDK_VERSION__: JSON.stringify(version),
9
22
  }
10
23
 
11
24
  export default defineConfig([
@@ -17,7 +30,22 @@ export default defineConfig([
17
30
  esbuildOptions(options) {
18
31
  options.define = {
19
32
  ...options.define,
33
+ ...versionDefine,
34
+ }
35
+ },
36
+ },
37
+ {
38
+ ...baseConfig,
39
+ entry: ['src/index.ts'],
40
+ format: ['iife'],
41
+ outDir: 'dist/iife',
42
+ globalName: 'webspatialCore',
43
+ esbuildOptions(options) {
44
+ options.define = {
45
+ ...options.define,
46
+ ...versionDefine,
20
47
  }
21
48
  },
49
+ minify: true,
22
50
  },
23
51
  ])