sprinklers3/common/sprinklersRpc/websocketData.ts

95 lines
2.4 KiB
TypeScript
Raw Normal View History

2018-08-12 11:55:15 +03:00
import { IUser } from "@common/httpApi";
2018-08-31 21:59:06 -06:00
import * as rpc from "@common/jsonRpc/index";
import { Response as ResponseData } from "@common/sprinklersRpc/deviceRequests";
export interface IAuthenticateRequest {
2018-09-02 02:57:55 -06:00
accessToken: string;
}
export interface IDeviceSubscribeRequest {
2018-09-02 02:57:55 -06:00
deviceId: string;
2018-06-29 18:16:06 -06:00
}
export interface IDeviceCallRequest {
2018-09-02 02:57:55 -06:00
deviceId: string;
data: any;
2017-10-09 08:09:08 -06:00
}
export interface IClientRequestTypes {
2018-09-02 02:57:55 -06:00
authenticate: IAuthenticateRequest;
deviceSubscribe: IDeviceSubscribeRequest;
deviceUnsubscribe: IDeviceSubscribeRequest;
deviceCall: IDeviceCallRequest;
}
export interface IAuthenticateResponse {
2018-09-02 02:57:55 -06:00
authenticated: boolean;
message: string;
user: IUser;
}
export interface IDeviceSubscribeResponse {
2018-09-02 02:57:55 -06:00
deviceId: string;
}
2017-10-09 08:09:08 -06:00
export interface IDeviceCallResponse {
2018-09-02 02:57:55 -06:00
data: ResponseData;
2017-10-09 08:09:08 -06:00
}
export interface IServerResponseTypes {
2018-09-02 02:57:55 -06:00
authenticate: IAuthenticateResponse;
deviceSubscribe: IDeviceSubscribeResponse;
deviceUnsubscribe: IDeviceSubscribeResponse;
deviceCall: IDeviceCallResponse;
2018-06-16 23:54:03 -06:00
}
export type ClientRequestMethods = keyof IClientRequestTypes;
export interface IBrokerConnectionUpdate {
2018-09-02 02:57:55 -06:00
brokerConnected: boolean;
2018-06-30 14:49:13 -06:00
}
export interface IDeviceUpdate {
2018-09-02 02:57:55 -06:00
deviceId: string;
data: any;
}
2017-10-09 08:09:08 -06:00
export interface IServerNotificationTypes {
2018-09-02 02:57:55 -06:00
brokerConnectionUpdate: IBrokerConnectionUpdate;
deviceUpdate: IDeviceUpdate;
error: IError;
2017-10-09 08:09:08 -06:00
}
export type ServerNotificationMethod = keyof IServerNotificationTypes;
2018-06-30 23:26:48 -06:00
export type IError = rpc.DefaultErrorType;
export type ErrorData = rpc.ErrorData<IError>;
2018-09-02 02:57:55 -06:00
export type ServerMessage = rpc.Message<
{},
IServerResponseTypes,
IError,
IServerNotificationTypes
>;
export type ServerNotification = rpc.Notification<IServerNotificationTypes>;
2018-06-30 23:26:48 -06:00
export type ServerResponse = rpc.Response<IServerResponseTypes, IError>;
2018-09-02 02:57:55 -06:00
export type ServerResponseData<
Method extends keyof IServerResponseTypes = keyof IServerResponseTypes
> = rpc.ResponseData<IServerResponseTypes, IError, Method>;
export type ServerResponseHandlers = rpc.ResponseHandlers<
IServerResponseTypes,
IError
>;
export type ServerNotificationHandlers = rpc.NotificationHandlers<
IServerNotificationTypes
>;
2017-10-09 08:09:08 -06:00
2018-09-02 02:57:55 -06:00
export type ClientRequest<
Method extends keyof IClientRequestTypes = keyof IClientRequestTypes
> = rpc.Request<IClientRequestTypes, Method>;
2018-06-30 23:26:48 -06:00
export type ClientMessage = rpc.Message<IClientRequestTypes, {}, IError, {}>;
2018-09-02 02:57:55 -06:00
export type ClientRequestHandlers = rpc.RequestHandlers<
IClientRequestTypes,
IServerResponseTypes,
IError
>;