⚡ Ring service now provide batch variant of get websocket status endpoint
This commit is contained in:
@@ -2,6 +2,7 @@ using DysonNetwork.Ring.Connection;
|
|||||||
using DysonNetwork.Ring.Notification;
|
using DysonNetwork.Ring.Notification;
|
||||||
using DysonNetwork.Shared.Models;
|
using DysonNetwork.Shared.Models;
|
||||||
using DysonNetwork.Shared.Proto;
|
using DysonNetwork.Shared.Proto;
|
||||||
|
using Google.Protobuf.Collections;
|
||||||
using Google.Protobuf.WellKnownTypes;
|
using Google.Protobuf.WellKnownTypes;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ public class RingServiceGrpc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Empty> PushWebSocketPacketToDevice(PushWebSocketPacketToDeviceRequest request,
|
public override Task<Empty> PushWebSocketPacketToDevice(PushWebSocketPacketToDeviceRequest request,
|
||||||
ServerCallContext context)
|
ServerCallContext context)
|
||||||
{
|
{
|
||||||
var packet = Shared.Models.WebSocketPacket.FromProtoValue(request.Packet);
|
var packet = Shared.Models.WebSocketPacket.FromProtoValue(request.Packet);
|
||||||
|
|
||||||
@@ -139,10 +140,24 @@ public class RingServiceGrpc(
|
|||||||
{
|
{
|
||||||
GetWebsocketConnectionStatusRequest.IdOneofCase.DeviceId =>
|
GetWebsocketConnectionStatusRequest.IdOneofCase.DeviceId =>
|
||||||
WebSocketService.GetDeviceIsConnected(request.DeviceId),
|
WebSocketService.GetDeviceIsConnected(request.DeviceId),
|
||||||
GetWebsocketConnectionStatusRequest.IdOneofCase.UserId => WebSocketService.GetAccountIsConnected(Guid.Parse(request.UserId)),
|
GetWebsocketConnectionStatusRequest.IdOneofCase.UserId => WebSocketService.GetAccountIsConnected(
|
||||||
|
Guid.Parse(request.UserId)),
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
|
|
||||||
return Task.FromResult(new GetWebsocketConnectionStatusResponse { IsConnected = isConnected });
|
return Task.FromResult(new GetWebsocketConnectionStatusResponse { IsConnected = isConnected });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Task<GetWebsocketConnectionStatusBatchResponse> GetWebsocketConnectionStatusBatch(
|
||||||
|
GetWebsocketConnectionStatusBatchRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
var resp = new GetWebsocketConnectionStatusBatchResponse();
|
||||||
|
foreach (var id in request.UsersId)
|
||||||
|
{
|
||||||
|
var gid = Guid.Parse(id);
|
||||||
|
resp.IsConnected[id] = WebSocketService.GetAccountIsConnected(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(resp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -12,117 +12,126 @@ import "account.proto";
|
|||||||
|
|
||||||
// RingService provides methods to send various types of notifications.
|
// RingService provides methods to send various types of notifications.
|
||||||
service RingService {
|
service RingService {
|
||||||
// Sends an email.
|
// Sends an email.
|
||||||
rpc SendEmail(SendEmailRequest) returns (google.protobuf.Empty) {}
|
rpc SendEmail(SendEmailRequest) returns (google.protobuf.Empty) {}
|
||||||
|
|
||||||
// Pushes a packet to a user via WebSocket.
|
// Pushes a packet to a user via WebSocket.
|
||||||
rpc PushWebSocketPacket(PushWebSocketPacketRequest) returns (google.protobuf.Empty) {}
|
rpc PushWebSocketPacket(PushWebSocketPacketRequest) returns (google.protobuf.Empty) {}
|
||||||
|
|
||||||
// Pushes a packet to a list of users via WebSocket.
|
// Pushes a packet to a list of users via WebSocket.
|
||||||
rpc PushWebSocketPacketToUsers(PushWebSocketPacketToUsersRequest) returns (google.protobuf.Empty) {}
|
rpc PushWebSocketPacketToUsers(PushWebSocketPacketToUsersRequest) returns (google.protobuf.Empty) {}
|
||||||
|
|
||||||
// Pushes a packet to a device via WebSocket.
|
// Pushes a packet to a device via WebSocket.
|
||||||
rpc PushWebSocketPacketToDevice(PushWebSocketPacketToDeviceRequest) returns (google.protobuf.Empty) {}
|
rpc PushWebSocketPacketToDevice(PushWebSocketPacketToDeviceRequest) returns (google.protobuf.Empty) {}
|
||||||
|
|
||||||
// Pushes a packet to a list of devices via WebSocket.
|
// Pushes a packet to a list of devices via WebSocket.
|
||||||
rpc PushWebSocketPacketToDevices(PushWebSocketPacketToDevicesRequest) returns (google.protobuf.Empty) {}
|
rpc PushWebSocketPacketToDevices(PushWebSocketPacketToDevicesRequest) returns (google.protobuf.Empty) {}
|
||||||
|
|
||||||
// Sends a push notification to a user.
|
// Sends a push notification to a user.
|
||||||
rpc SendPushNotificationToUser(SendPushNotificationToUserRequest) returns (google.protobuf.Empty) {}
|
rpc SendPushNotificationToUser(SendPushNotificationToUserRequest) returns (google.protobuf.Empty) {}
|
||||||
|
|
||||||
// Sends a push notification to a list of users.
|
// Sends a push notification to a list of users.
|
||||||
rpc SendPushNotificationToUsers(SendPushNotificationToUsersRequest) returns (google.protobuf.Empty) {}
|
rpc SendPushNotificationToUsers(SendPushNotificationToUsersRequest) returns (google.protobuf.Empty) {}
|
||||||
|
|
||||||
// Unsubscribes a device from push notifications.
|
// Unsubscribes a device from push notifications.
|
||||||
rpc UnsubscribePushNotifications(UnsubscribePushNotificationsRequest) returns (google.protobuf.Empty) {}
|
rpc UnsubscribePushNotifications(UnsubscribePushNotificationsRequest) returns (google.protobuf.Empty) {}
|
||||||
|
|
||||||
// Gets the WebSocket connection status for a device or user.
|
// Gets the WebSocket connection status for a device or user.
|
||||||
rpc GetWebsocketConnectionStatus(GetWebsocketConnectionStatusRequest) returns (GetWebsocketConnectionStatusResponse) {}
|
rpc GetWebsocketConnectionStatus(GetWebsocketConnectionStatusRequest) returns (GetWebsocketConnectionStatusResponse) {}
|
||||||
|
|
||||||
|
rpc GetWebsocketConnectionStatusBatch(GetWebsocketConnectionStatusBatchRequest) returns (GetWebsocketConnectionStatusBatchResponse) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents an email message.
|
// Represents an email message.
|
||||||
message EmailMessage {
|
message EmailMessage {
|
||||||
string to_name = 1;
|
string to_name = 1;
|
||||||
string to_address = 2;
|
string to_address = 2;
|
||||||
string subject = 3;
|
string subject = 3;
|
||||||
string body = 4;
|
string body = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SendEmailRequest {
|
message SendEmailRequest {
|
||||||
EmailMessage email = 1;
|
EmailMessage email = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents a WebSocket packet.
|
// Represents a WebSocket packet.
|
||||||
message WebSocketPacket {
|
message WebSocketPacket {
|
||||||
string type = 1;
|
string type = 1;
|
||||||
bytes data = 2;
|
bytes data = 2;
|
||||||
google.protobuf.StringValue error_message = 3;
|
google.protobuf.StringValue error_message = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PushWebSocketPacketRequest {
|
message PushWebSocketPacketRequest {
|
||||||
string user_id = 1;
|
string user_id = 1;
|
||||||
WebSocketPacket packet = 2;
|
WebSocketPacket packet = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PushWebSocketPacketToUsersRequest {
|
message PushWebSocketPacketToUsersRequest {
|
||||||
repeated string user_ids = 1;
|
repeated string user_ids = 1;
|
||||||
WebSocketPacket packet = 2;
|
WebSocketPacket packet = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PushWebSocketPacketToDeviceRequest {
|
message PushWebSocketPacketToDeviceRequest {
|
||||||
string device_id = 1;
|
string device_id = 1;
|
||||||
WebSocketPacket packet = 2;
|
WebSocketPacket packet = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PushWebSocketPacketToDevicesRequest {
|
message PushWebSocketPacketToDevicesRequest {
|
||||||
repeated string device_ids = 1;
|
repeated string device_ids = 1;
|
||||||
WebSocketPacket packet = 2;
|
WebSocketPacket packet = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents a push notification.
|
// Represents a push notification.
|
||||||
message PushNotification {
|
message PushNotification {
|
||||||
string topic = 1;
|
string topic = 1;
|
||||||
string title = 2;
|
string title = 2;
|
||||||
string subtitle = 3;
|
string subtitle = 3;
|
||||||
string body = 4;
|
string body = 4;
|
||||||
optional bytes meta = 5;
|
optional bytes meta = 5;
|
||||||
optional string action_uri = 6;
|
optional string action_uri = 6;
|
||||||
bool is_silent = 7;
|
bool is_silent = 7;
|
||||||
bool is_savable = 8;
|
bool is_savable = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SendPushNotificationToUserRequest {
|
message SendPushNotificationToUserRequest {
|
||||||
string user_id = 1;
|
string user_id = 1;
|
||||||
PushNotification notification = 2;
|
PushNotification notification = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SendPushNotificationToUsersRequest {
|
message SendPushNotificationToUsersRequest {
|
||||||
repeated string user_ids = 1;
|
repeated string user_ids = 1;
|
||||||
PushNotification notification = 2;
|
PushNotification notification = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UnsubscribePushNotificationsRequest {
|
message UnsubscribePushNotificationsRequest {
|
||||||
string device_id = 1;
|
string device_id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetWebsocketConnectionStatusRequest {
|
message GetWebsocketConnectionStatusRequest {
|
||||||
oneof id {
|
oneof id {
|
||||||
string device_id = 1;
|
string device_id = 1;
|
||||||
string user_id = 2;
|
string user_id = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetWebsocketConnectionStatusResponse {
|
message GetWebsocketConnectionStatusResponse {
|
||||||
bool is_connected = 1;
|
bool is_connected = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message GetWebsocketConnectionStatusBatchRequest {
|
||||||
|
repeated string users_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetWebsocketConnectionStatusBatchResponse {
|
||||||
|
map<string, bool> is_connected = 1;
|
||||||
|
}
|
||||||
|
|
||||||
service RingHandlerService {
|
service RingHandlerService {
|
||||||
rpc ReceiveWebSocketPacket(ReceiveWebSocketPacketRequest) returns (google.protobuf.Empty) {}
|
rpc ReceiveWebSocketPacket(ReceiveWebSocketPacketRequest) returns (google.protobuf.Empty) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
message ReceiveWebSocketPacketRequest {
|
message ReceiveWebSocketPacketRequest {
|
||||||
WebSocketPacket packet = 1;
|
WebSocketPacket packet = 1;
|
||||||
Account account = 2;
|
Account account = 2;
|
||||||
string device_id = 3;
|
string device_id = 3;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user