11<template >
22 <div ref =" resizeTarget" class =" ff--immersive-editor-wrapper" :class =" {resizing: isEditorResizing}" >
33 <EditorWrapper
4- :url =" device ?.editor ?.url "
54 :disable-events =" isEditorResizing "
65 :device =" device "
76 />
2221
2322 <div class =" header" >
2423 <div class =" logo" >
25- <router-link title =" Back to remote instance overview" :to =" { name: 'device-overview', params: {id: device.id} }" >
24+ <router-link
25+ title =" Back to remote instance overview"
26+ :to =" { name: 'device-overview', params: {id: device.id} }"
27+ >
2628 <ArrowLeftIcon class="ff-btn--icon" />
2729 </router-link >
2830 </div >
@@ -123,7 +125,7 @@ export default {
123125 agentSupportsActions: null ,
124126 device: null ,
125127 openingTunnel: false ,
126- openTunnelTimeout : null
128+ ws : null
127129 }
128130 },
129131 computed: {
@@ -135,11 +137,20 @@ export default {
135137 isDevModeAvailable : function () {
136138 return !! this .features .deviceEditor
137139 },
140+ isEditorAvailable () {
141+ return this .device &&
142+ Object .prototype .hasOwnProperty .call (this .device , ' editor' ) &&
143+ Object .prototype .hasOwnProperty .call (this .device .editor , ' connected' ) &&
144+ this .device .editor .connected
145+ },
138146 navigation () {
139147 return [
140148 {
141149 label: ' Expert' ,
142- to: { name: ' device-editor-expert' , params: { id: this .device .id } },
150+ to: {
151+ name: ' device-editor-expert' ,
152+ params: { id: this .device .id }
153+ },
143154 tag: ' device-expert' ,
144155 icon: ExpertTabIcon,
145156 hidden: ! this .featuresCheck .isExpertAssistantFeatureEnabled
@@ -176,24 +187,27 @@ export default {
176187 label: ' Settings' ,
177188 to: { name: ' device-editor-settings' },
178189 tag: ' device-settings'
179- },
180- {
181- label: ' Developer Mode' ,
182- to: { name: ' device-editor-developer-mode' },
183- tag: ' device-devmode' ,
184- hidden: ! (this .isDevModeAvailable && this .device .mode === ' developer' )
185190 }
191+ // {
192+ // label: 'Developer Mode',
193+ // to: { name: 'device-editor-developer-mode' },
194+ // tag: 'device-devmode',
195+ // hidden: !(this.isDevModeAvailable && this.device.mode === 'developer')
196+ // }
186197 ]
187198 }
188199 },
189200 watch: {
190201 device (device ) {
191- if (device && Object . prototype . hasOwnProperty . call (device, ' editor ' ) ) {
202+ if (device && this . isEditorAvailable ) {
192203 this .setContextDevice (device)
204+ this .pollDeviceComms ()
205+ this .runInitialTease ()
193206 } else {
194- Alerts .emit (' Unable to connect to the Remote Instance' , ' warning' )
195-
196- setTimeout (() => this .$router .push ({ name: ' device-overview' }), 2000 )
207+ this .closeComms ()
208+ this .$router .push ({ name: ' device-overview' })
209+ .then (() => Alerts .emit (' Unable to connect to the Remote Instance' , ' warning' ))
210+ .catch (e => e)
197211 }
198212 }
199213 },
@@ -217,9 +231,9 @@ export default {
217231 })
218232 })
219233 .catch (err => err)
220- . finally (() => {
221- this . runInitialTease ()
222- } )
234+ },
235+ beforeUnmount () {
236+ this . closeComms ( )
223237 },
224238 methods: {
225239 ... mapActions (' context' , { setContextDevice: ' setDevice' }),
@@ -228,22 +242,39 @@ export default {
228242 this .device = await deviceApi .getDevice (this .$route .params .id )
229243 } catch (err) {
230244 if (err .status === 403 ) {
231- return this .$router .push ({ name: ' Home ' })
245+ return this .$router .push ({ name: ' device-overview ' })
232246 }
233- } finally {
234- this .loading = false
235247 }
236248
237249 this .agentSupportsDeviceAccess = this .device .agentVersion && semver .gte (this .device .agentVersion , ' 0.8.0' )
238250 this .agentSupportsActions = this .device .agentVersion && semver .gte (this .device .agentVersion , ' 2.3.0' )
239251
240252 // todo we first need to get the device and set the team afterwards
241253 await this .$store .dispatch (' account/setTeam' , this .device .team .slug )
254+ },
255+ pollDeviceComms () {
256+ if (! this .isEditorAvailable || this .ws ) return
257+
258+ const uri = ` /api/v1/devices/${ this .device .id } /editor/proxy/comms`
259+
260+ this .ws = new WebSocket (uri)
261+
262+ this .ws .addEventListener (' error' , this .handleCommsDisconnect )
263+ this .ws .addEventListener (' close' , this .handleCommsDisconnect )
264+ },
265+ handleCommsDisconnect () {
266+ this .$router .push ({ name: ' device-overview' })
267+ .then (() => Alerts .emit (' Disconnected from remote instance.' , ' warning' ))
268+ .catch (e => e)
269+ },
270+ closeComms () {
271+ if (this .ws ) {
272+ this .ws .removeEventListener (' error' , this .handleCommsDisconnect )
273+ this .ws .removeEventListener (' close' , this .handleCommsDisconnect )
274+ this .ws .close ()
275+ this .ws = null
276+ }
242277 }
243278 }
244279}
245280 </script >
246-
247- <style scoped lang="scss">
248-
249- </style >
0 commit comments