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