Clean up & Add connection setup
This commit is contained in:
39
events/Events.ts
Normal file
39
events/Events.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { MqttOptions, DataSourceState } from '../backend/src/DataSource'
|
||||
|
||||
export interface Event<MessageType> {
|
||||
topic: string
|
||||
}
|
||||
|
||||
export interface AddMqttConnection {
|
||||
id: string,
|
||||
options: MqttOptions
|
||||
}
|
||||
|
||||
export const addMqttConnectionEvent: Event<AddMqttConnection> = {
|
||||
topic: 'connection/add/mqtt',
|
||||
}
|
||||
|
||||
interface RemoveConnection {
|
||||
connectionId: string,
|
||||
}
|
||||
|
||||
export const removeConnection: Event<string> = {
|
||||
topic: 'connection/remove',
|
||||
}
|
||||
|
||||
export function makeConnectionStateEvent(connectionId: string): Event<DataSourceState> {
|
||||
return {
|
||||
topic: `conn/state/${connectionId}`,
|
||||
}
|
||||
}
|
||||
|
||||
interface Message {
|
||||
topic: string,
|
||||
payload: any
|
||||
}
|
||||
|
||||
export function makeConnectionMessageEvent(connectionId: string): Event<Message> {
|
||||
return {
|
||||
topic: `conn/${connectionId}`,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user