-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
427 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ages/adapter-tcp/src/event-handlers/command-event-handlers/locate-device.event-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { DomainException } from '@agnoc/toolkit'; | ||
import type { ConnectionManager } from '../../connection.manager'; | ||
import type { CommandEventHandler, LocateDeviceCommand } from '@agnoc/domain'; | ||
|
||
export class LocateDeviceEventHandler implements CommandEventHandler { | ||
readonly eventName = 'LocateDeviceCommand'; | ||
|
||
constructor(private readonly connectionManager: ConnectionManager) {} | ||
|
||
async handle(event: LocateDeviceCommand): Promise<void> { | ||
const [connection] = this.connectionManager.findConnectionsByDeviceId(event.deviceId); | ||
|
||
if (!connection || !connection.device) { | ||
throw new DomainException(`Unable to find a connection for the device with id ${event.deviceId.value}`); | ||
} | ||
|
||
await connection.sendAndWait('DEVICE_SEEK_LOCATION_REQ', {}); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ages/adapter-tcp/src/event-handlers/packet-event-handlers/device-located.event-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { DomainException } from '@agnoc/toolkit'; | ||
import type { PacketEventHandler } from '../../packet.event-handler'; | ||
import type { PacketMessage } from '../../packet.message'; | ||
|
||
export class DeviceLocatedEventHandler implements PacketEventHandler { | ||
readonly eventName = 'DEVICE_SEEK_LOCATION_RSP'; | ||
|
||
async handle(message: PacketMessage<'DEVICE_SEEK_LOCATION_RSP'>): Promise<void> { | ||
if (!message.device) { | ||
throw new DomainException('Device not found'); | ||
} | ||
|
||
// TODO: Should do something here? | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.