@things-factory/shell 6.1.160 → 6.1.166

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.
@@ -1,3 +1,103 @@
1
- import './scene-viewer'
1
+ import './scene-components'
2
+ import gql from 'graphql-tag'
2
3
 
3
- export { BoardPlayer } from '@operato/board'
4
+ import { ReferenceMap, create, error } from '@hatiolab/things-scene'
5
+
6
+ export { BoardViewer, BoardPlayer } from '@operato/board'
7
+ import { client, gqlContext, subscribe } from '@operato/graphql'
8
+
9
+ export const provider = new ReferenceMap(
10
+ async (boardId, resolve, reject) => {
11
+ try {
12
+ const response = await client.query({
13
+ query: gql`
14
+ query FetchBoardById($id: String!) {
15
+ board(id: $id) {
16
+ model
17
+ }
18
+ }
19
+ `,
20
+ variables: { id: boardId },
21
+ context: gqlContext()
22
+ })
23
+
24
+ const board = response.data.board
25
+
26
+ var model = JSON.parse(board.model)
27
+
28
+ var scene
29
+
30
+ try {
31
+ scene = await provider.get(boardId)
32
+ console.warn('Board fetched more than twice.', boardId)
33
+ } catch (e) {
34
+ scene = create({
35
+ model,
36
+ mode: 0,
37
+ refProvider: provider
38
+ })
39
+
40
+ // s.app.baseUrl = undefined;
41
+ }
42
+
43
+ resolve(scene)
44
+ } catch (e) {
45
+ error(e)
46
+ reject(e)
47
+ }
48
+ },
49
+ async (id, ref) => {
50
+ ref.dispose()
51
+ }
52
+ )
53
+
54
+ var subscriptionForAutoRefresh
55
+
56
+ export const startSubscribingForAutoRefresh = async (playGroupId, callback) => {
57
+ if (!playGroupId) {
58
+ return
59
+ }
60
+
61
+ await stopSubscribing()
62
+
63
+ subscriptionForAutoRefresh = await subscribe(
64
+ {
65
+ query: gql`
66
+ subscription ($id: String!) {
67
+ playGroup(id: $id) {
68
+ id
69
+ boards {
70
+ id
71
+ model
72
+ }
73
+ }
74
+ }
75
+ `,
76
+ variables: {
77
+ id: playGroupId
78
+ }
79
+ },
80
+ {
81
+ next: async ({ data }) => {
82
+ const { id, boards = '{}' } = data.playGroup
83
+
84
+ if (data) {
85
+ callback &&
86
+ (await callback({
87
+ id,
88
+ boards
89
+ }))
90
+ }
91
+ }
92
+ }
93
+ )
94
+ }
95
+
96
+ export const stopSubscribing = async () => {
97
+ await subscriptionForAutoRefresh?.unsubscribe()
98
+ subscriptionForAutoRefresh = null
99
+ }
100
+
101
+ window['headlessSceneProvider'] = provider
102
+ window['startSubscribingForAutoRefresh'] = startSubscribingForAutoRefresh
103
+ window['stopSubscribing'] = stopSubscribing
@@ -1,7 +1,7 @@
1
1
  import './scene-components'
2
2
 
3
3
  import { ReferenceMap, create, error } from '@hatiolab/things-scene'
4
- import { client, gqlContext } from '@operato/graphql'
4
+ import { client, gqlContext, subscribe } from '@operato/graphql'
5
5
 
6
6
  import gql from 'graphql-tag'
7
7
 
@@ -57,4 +57,50 @@ export const provider = new ReferenceMap(
57
57
  }
58
58
  )
59
59
 
60
+ var subscriptionForAutoRefresh
61
+
62
+ export const startSubscribingForAutoRefresh = async (boardId, callback) => {
63
+ if (!boardId) {
64
+ return
65
+ }
66
+
67
+ await stopSubscribing()
68
+
69
+ subscriptionForAutoRefresh = await subscribe(
70
+ {
71
+ query: gql`
72
+ subscription ($id: String!) {
73
+ board(id: $id) {
74
+ id
75
+ model
76
+ }
77
+ }
78
+ `,
79
+ variables: {
80
+ id: boardId
81
+ }
82
+ },
83
+ {
84
+ next: async ({ data }) => {
85
+ const { id, model = '{}' } = data.board
86
+
87
+ if (data) {
88
+ callback &&
89
+ (await callback({
90
+ id,
91
+ model: JSON.parse(model)
92
+ }))
93
+ }
94
+ }
95
+ }
96
+ )
97
+ }
98
+
99
+ export const stopSubscribing = async () => {
100
+ await subscriptionForAutoRefresh?.unsubscribe()
101
+ subscriptionForAutoRefresh = null
102
+ }
103
+
60
104
  window['headlessSceneProvider'] = provider
105
+ window['startSubscribingForAutoRefresh'] = startSubscribingForAutoRefresh
106
+ window['stopSubscribing'] = stopSubscribing