Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set own device info to "self-hosted server" #942

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/mapeo-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,7 @@ export class MapeoManager extends TypedEmitter {
}

/**
* @typedef {Exclude<
* import('./schema/client.js').DeviceInfoParam['deviceType'],
* 'selfHostedServer'>} RPCDeviceType
* @typedef {import('./schema/client.js').DeviceInfoParam['deviceType']} RPCDeviceType
*/

/**
Expand All @@ -765,13 +763,22 @@ export class MapeoManager extends TypedEmitter {
})
)

await Promise.all(
this.#localPeers.peers
.filter(({ status }) => status === 'connected')
.map((peer) =>
this.#localPeers.sendDeviceInfo(peer.deviceId, deviceInfo)
)
)
if (deviceInfo.deviceType !== 'selfHostedServer') {
// We have to make a copy of this because TypeScript can't guarantee that
// `deviceInfo` won't be mutated by the time it gets to the
// `sendDeviceInfo` call below.
const deviceInfoToSend = {
...deviceInfo,
deviceType: deviceInfo.deviceType,
}
await Promise.all(
this.#localPeers.peers
.filter(({ status }) => status === 'connected')
.map((peer) =>
this.#localPeers.sendDeviceInfo(peer.deviceId, deviceInfoToSend)
)
)
}

this.#l.log('set device info %o', deviceInfo)
}
Expand Down
12 changes: 12 additions & 0 deletions test-e2e/device-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ test('write and read deviceInfo', async () => {
deviceType: 'mobile',
deviceId: manager.deviceId,
})

await manager.setDeviceInfo({
name: 'a little server',
deviceType: 'selfHostedServer',
selfHostedServerDetails: { baseUrl: 'https://comapeo-test.example/' },
})
assert.deepEqual(manager.getDeviceInfo(), {
name: 'a little server',
deviceType: 'selfHostedServer',
deviceId: manager.deviceId,
selfHostedServerDetails: { baseUrl: 'https://comapeo-test.example/' },
})
})

test('device info written to projects', async (t) => {
Expand Down
Loading