Skip to content

Commit

Permalink
fix: remove disconnected remote surfaces from surfaces table
Browse files Browse the repository at this point in the history
This was part of an abandonded experiment
  • Loading branch information
Julusian committed Sep 11, 2024
1 parent 1b03103 commit 14ac7bf
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 103 deletions.
47 changes: 0 additions & 47 deletions companion/lib/Surface/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,6 @@ class SurfaceController extends CoreBase {
* @returns {ClientDevicesListItem[]}
*/
getDevicesList() {
const remoteConnections = Object.values(this.#outboundController.storage)

const usedRemoteConnectionIds = new Set()

/**
*
* @param {string} id
Expand All @@ -676,27 +672,14 @@ class SurfaceController extends CoreBase {
isConnected: !!surfaceHandler,
displayName: getSurfaceName(config, id),
location: null,
remoteConnectionId: null,
}

if (surfaceHandler) {
let location = surfaceHandler.panel.info.location
if (location && location.startsWith('::ffff:')) location = location.substring(7)
let remotePort = surfaceHandler.panel.info.remotePort

surfaceInfo.location = location || null
surfaceInfo.configFields = surfaceHandler.panel.info.configFields || []

// Translate remote connections info
if (config?.integrationType === 'elgato-streamdeck-tcp') {
const matchingRemote = remoteConnections.find(
(s) => s.type === 'elgato' && s.address === location && s.port === remotePort
)
if (matchingRemote) {
surfaceInfo.remoteConnectionId = matchingRemote.id
usedRemoteConnectionIds.add(matchingRemote.id)
}
}
}

return surfaceInfo
Expand Down Expand Up @@ -782,36 +765,6 @@ class SurfaceController extends CoreBase {
}
}

for (const connection of remoteConnections) {
if (usedRemoteConnectionIds.has(connection.id)) continue

const tcpId = `tcp://${connection.address}:${connection.port}`

/** @type {ClientDevicesListItem} */
const groupResult = {
id: tcpId,
index: undefined,
displayName: `${connection.displayName || connection.type} - Offline`,
isAutoGroup: true,
surfaces: [
{
id: tcpId,
type: 'Unknown Elgato Stream Deck (TCP)',
integrationType: config?.integrationType || '',
name: config?.name || '',
// location: 'Offline',
configFields: [],
isConnected: false,
displayName: connection.displayName,
location: null,
remoteConnectionId: connection.id,
},
],
}
result.push(groupResult)
// groupsMap.set(groupId, groupResult)
}

return result
}

Expand Down
1 change: 0 additions & 1 deletion companion/lib/Surface/Handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const PINCODE_NUMBER_POSITIONS_SKIP_FIRST_COL = [
* type: string
* configFields: import('@companion-app/shared/Model/Surfaces.js').CompanionSurfaceConfigField[]
* location?: string
* remotePort?: number
* }} SurfacePanelInfo
* @typedef {{
* info: SurfacePanelInfo
Expand Down
10 changes: 0 additions & 10 deletions companion/lib/Surface/Outbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ export class SurfaceOutboundController {
autoConnectToSecondaries: true,
})

/**
* @type {Record<string, import('@companion-app/shared/Model/Surfaces.js').OutboundSurfaceInfo>}
*/
get storage() {
return this.#storage
}

/**
*
* @param {import('./Controller.js').default} controller
Expand Down Expand Up @@ -153,7 +146,6 @@ export class SurfaceOutboundController {
info: newInfo,
},
])
setImmediate(() => this.#controller.updateDevicesList())

this.#streamdeckTcpConnectionManager.connectTo(address, port)

Expand All @@ -173,7 +165,6 @@ export class SurfaceOutboundController {
itemId: id,
},
])
setImmediate(() => this.#controller.updateDevicesList())

this.#streamdeckTcpConnectionManager.disconnectFrom(surfaceInfo.address, surfaceInfo.port)
})
Expand All @@ -193,7 +184,6 @@ export class SurfaceOutboundController {
info: surfaceInfo,
},
])
setImmediate(() => this.#controller.updateDevicesList())
})
}

Expand Down
2 changes: 0 additions & 2 deletions companion/lib/Surface/USB/ElgatoStreamDeck.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class SurfaceUSBElgatoStreamDeck extends EventEmitter {
configFields: getConfigFields(this.#streamDeck),
deviceId: '', // set in #init()
location: undefined, // set later
remotePort: undefined, // set later
}

const allRowValues = this.#streamDeck.CONTROLS.map((control) => control.row)
Expand Down Expand Up @@ -255,7 +254,6 @@ class SurfaceUSBElgatoStreamDeck extends EventEmitter {
this.#shouldCleanupOnQuit = false

this.info.location = tcpStreamdeck.remoteAddress
this.info.remotePort = tcpStreamdeck.remotePort

tcpStreamdeck.tcpEvents.on('disconnected', () => {
this.#logger.info(
Expand Down
1 change: 0 additions & 1 deletion shared-lib/lib/Model/Surfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface ClientSurfaceItem {
isConnected: boolean
displayName: string
location: string | null
remoteConnectionId: string | null
}

export interface ClientDevicesListItem {
Expand Down
56 changes: 14 additions & 42 deletions webui/src/Surfaces/KnownSurfacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,17 @@ export const KnownSurfacesTable = observer(function SurfacesPage() {
}, [])

const forgetSurface = useCallback(
(surfaceId: string, remoteConnectionId: string | null) => {
if (remoteConnectionId) {
confirmRef.current?.show(
'Disconnect and Forget Surface',
[
'Are you sure you want to disconnect from and forget this surface? Any settings will be lost.',
'Any surfaces sharing this connection will also be disconnected.',
],
'Forget',
() => {
socketEmitPromise(socket, 'surfaces:forget', [surfaceId]).catch((err) => {
console.error('fotget failed', err)
})
socketEmitPromise(socket, 'surfaces:outbound:remove', [remoteConnectionId]).catch((err) => {
console.error('fotget failed', err)
})
}
)
} else {
confirmRef.current?.show(
'Forget Surface',
'Are you sure you want to forget this surface? Any settings will be lost',
'Forget',
() => {
socketEmitPromise(socket, 'surfaces:forget', [surfaceId]).catch((err) => {
console.error('fotget failed', err)
})
}
)
}
(surfaceId: string) => {
confirmRef.current?.show(
'Forget Surface',
'Are you sure you want to forget this surface? Any settings will be lost',
'Forget',
() => {
socketEmitPromise(socket, 'surfaces:forget', [surfaceId]).catch((err) => {
console.error('fotget failed', err)
})
}
)
},
[socket]
)
Expand Down Expand Up @@ -167,7 +148,7 @@ interface ManualGroupRowProps {
updateName: (surfaceId: string, name: string) => void
configureSurface: (surfaceId: string) => void
deleteEmulator: (surfaceId: string) => void
forgetSurface: (surfaceId: string, remoteConnectionId: string | null) => void
forgetSurface: (surfaceId: string) => void
}
function ManualGroupRow({
group,
Expand Down Expand Up @@ -226,7 +207,7 @@ interface SurfaceRowProps {
updateName: (surfaceId: string, name: string) => void
configureSurface: (surfaceId: string) => void
deleteEmulator: (surfaceId: string) => void
forgetSurface: (surfaceId: string, remoteConnectionId: string | null) => void
forgetSurface: (surfaceId: string) => void
noBorder: boolean
}

Expand All @@ -242,10 +223,7 @@ function SurfaceRow({
const updateName2 = useCallback((val: string) => updateName(surface.id, val), [updateName, surface.id])
const configureSurface2 = useCallback(() => configureSurface(surface.id), [configureSurface, surface.id])
const deleteEmulator2 = useCallback(() => deleteEmulator(surface.id), [deleteEmulator, surface.id])
const forgetSurface2 = useCallback(
() => forgetSurface(surface.id, surface.remoteConnectionId),
[forgetSurface, surface.id]
)
const forgetSurface2 = useCallback(() => forgetSurface(surface.id), [forgetSurface, surface.id])

return (
<tr
Expand Down Expand Up @@ -277,12 +255,6 @@ function SurfaceRow({
</CButton>
</>
)}

{surface.remoteConnectionId ? (
<CButton onClick={forgetSurface2} title="Disconnect Surface">
<FontAwesomeIcon icon={faTrash} />
</CButton>
) : null}
</CButtonGroup>
) : (
<CButton onClick={forgetSurface2}>
Expand Down

0 comments on commit 14ac7bf

Please sign in to comment.