@xen-orchestra/web-core 0.0.1 → 0.0.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/env.d.ts ADDED
@@ -0,0 +1 @@
1
+ /// <reference types="novnc__novnc" />
@@ -0,0 +1,119 @@
1
+ <template>
2
+ <div :class="uiStore.isMobile ? 'mobile' : undefined" class="remote-console">
3
+ <div ref="consoleContainer" class="console"></div>
4
+ </div>
5
+ </template>
6
+
7
+ <script lang="ts" setup>
8
+ import { useUiStore } from '@core/stores/ui.store'
9
+ import VncClient from '@novnc/novnc/core/rfb'
10
+ import { promiseTimeout } from '@vueuse/shared'
11
+ import { fibonacci } from 'iterable-backoff'
12
+ import { onBeforeUnmount, ref, watchEffect } from 'vue'
13
+
14
+ const props = defineProps<{
15
+ url: URL
16
+ }>()
17
+
18
+ const N_TOTAL_TRIES = 8
19
+ const FIBONACCI_MS_ARRAY: number[] = Array.from(fibonacci().toMs().take(N_TOTAL_TRIES))
20
+
21
+ const consoleContainer = ref<HTMLDivElement | null>(null)
22
+
23
+ let vncClient: VncClient | undefined
24
+ let nConnectionAttempts = 0
25
+
26
+ const handleDisconnectionEvent = () => {
27
+ clearVncClient()
28
+
29
+ nConnectionAttempts++
30
+
31
+ if (nConnectionAttempts > N_TOTAL_TRIES) {
32
+ console.error('The number of reconnection attempts has been exceeded for:', props.url)
33
+ return
34
+ }
35
+
36
+ console.error(
37
+ `Connection lost for the remote console: ${props.url}. New attempt in ${
38
+ FIBONACCI_MS_ARRAY[nConnectionAttempts - 1]
39
+ }ms`
40
+ )
41
+ createVncConnection()
42
+ }
43
+
44
+ const handleConnectionEvent = () => (nConnectionAttempts = 0)
45
+
46
+ const clearVncClient = () => {
47
+ if (vncClient === undefined) {
48
+ return
49
+ }
50
+
51
+ vncClient.removeEventListener('disconnect', handleDisconnectionEvent)
52
+ vncClient.removeEventListener('connect', handleConnectionEvent)
53
+ vncClient.disconnect()
54
+
55
+ vncClient = undefined
56
+ }
57
+
58
+ const createVncConnection = async () => {
59
+ if (nConnectionAttempts !== 0) {
60
+ await promiseTimeout(FIBONACCI_MS_ARRAY[nConnectionAttempts - 1])
61
+
62
+ if (vncClient !== undefined) {
63
+ // New VNC Client may have been created in the meantime
64
+ return
65
+ }
66
+ }
67
+
68
+ vncClient = new VncClient(consoleContainer.value!, props.url.toString(), {
69
+ wsProtocols: ['binary'],
70
+ })
71
+ vncClient.scaleViewport = true
72
+ vncClient.background = 'transparent'
73
+
74
+ vncClient.addEventListener('disconnect', handleDisconnectionEvent)
75
+ vncClient.addEventListener('connect', handleConnectionEvent)
76
+ }
77
+
78
+ watchEffect(() => {
79
+ if (consoleContainer.value === null) {
80
+ return
81
+ }
82
+
83
+ nConnectionAttempts = 0
84
+
85
+ clearVncClient()
86
+ createVncConnection()
87
+ })
88
+
89
+ onBeforeUnmount(() => {
90
+ clearVncClient()
91
+ })
92
+
93
+ const uiStore = useUiStore()
94
+ </script>
95
+
96
+ <style lang="postcss" scoped>
97
+ .remote-console {
98
+ --padding: 0.8rem;
99
+ --height: 80rem;
100
+ --width: 100%;
101
+
102
+ &.mobile {
103
+ --padding: 0.8rem 0;
104
+ --height: 100%;
105
+ --width: 95vw;
106
+ }
107
+ }
108
+
109
+ .remote-console {
110
+ padding: var(--padding);
111
+ height: var(--height);
112
+ width: var(--width);
113
+ max-width: 100%;
114
+ }
115
+
116
+ .console {
117
+ height: 100%;
118
+ }
119
+ </style>
@@ -0,0 +1 @@
1
+ declare module 'iterable-backoff'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xen-orchestra/web-core",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "private": false,
6
6
  "exports": {
7
7
  "./*": {
@@ -10,13 +10,18 @@
10
10
  }
11
11
  },
12
12
  "devDependencies": {
13
+ "@fontsource/poppins": "^5.0.14",
13
14
  "@fortawesome/fontawesome-svg-core": "^6.5.1",
14
15
  "@fortawesome/free-regular-svg-icons": "^6.5.1",
15
16
  "@fortawesome/free-solid-svg-icons": "^6.5.1",
16
17
  "@fortawesome/vue-fontawesome": "^3.0.5",
18
+ "@novnc/novnc": "^1.4.0",
17
19
  "@types/lodash-es": "^4.17.12",
20
+ "@types/novnc__novnc": "^1.3.5",
18
21
  "@vue/tsconfig": "^0.5.1",
19
22
  "@vueuse/core": "^10.7.1",
23
+ "@vueuse/shared": "^10.7.1",
24
+ "iterable-backoff": "^0.1.0",
20
25
  "lodash-es": "^4.17.21",
21
26
  "pinia": "^2.1.7",
22
27
  "placement.js": "^1.0.0-beta.5",