fix: should now sync with other devices
All checks were successful
Queue Release Build / prepare (push) Successful in 25s
Deploy Web Apps / deploy (push) Successful in 7m8s
Queue Release Build / build-windows (push) Successful in 28m10s
Queue Release Build / build-linux (push) Successful in 44m38s
Queue Release Build / build-android (push) Successful in 18m36s
Queue Release Build / finalize (push) Successful in 1m40s
All checks were successful
Queue Release Build / prepare (push) Successful in 25s
Deploy Web Apps / deploy (push) Successful in 7m8s
Queue Release Build / build-windows (push) Successful in 28m10s
Queue Release Build / build-linux (push) Successful in 44m38s
Queue Release Build / build-android (push) Successful in 18m36s
Queue Release Build / finalize (push) Successful in 1m40s
This commit is contained in:
@@ -220,4 +220,50 @@ describe('server websocket handler - multi-client sessions', () => {
|
||||
expect((stale.ws as WebSocket & { closeCalled: boolean }).closeCalled).toBe(true);
|
||||
expect(connectedUsers.get('conn-new')?.authenticated).toBe(true);
|
||||
});
|
||||
|
||||
it('relays account_sync payloads to other connections for the same user', async () => {
|
||||
createConnectedUser('conn-a1', {
|
||||
authenticated: true,
|
||||
oderId: 'user-1',
|
||||
serverIds: new Set(['server-1']),
|
||||
clientInstanceId: 'device-a'
|
||||
});
|
||||
const receiver = createConnectedUser('conn-a2', {
|
||||
authenticated: true,
|
||||
oderId: 'user-1',
|
||||
serverIds: new Set(['server-1']),
|
||||
clientInstanceId: 'device-b'
|
||||
});
|
||||
|
||||
getSentMessages(receiver).length = 0;
|
||||
|
||||
await handleWebSocketMessage('conn-a1', {
|
||||
type: 'account_sync',
|
||||
clientInstanceId: 'device-a',
|
||||
payload: {
|
||||
type: 'friend-added',
|
||||
userId: 'friend-1',
|
||||
addedAt: 123
|
||||
}
|
||||
});
|
||||
|
||||
const messages = getSentMessages(receiver).map((raw) => JSON.parse(raw) as {
|
||||
type: string;
|
||||
payload?: { type: string; userId?: string };
|
||||
clientInstanceId?: string;
|
||||
fromUserId?: string;
|
||||
});
|
||||
const relay = messages.find((message) => message.type === 'account_sync');
|
||||
|
||||
expect(relay).toEqual({
|
||||
type: 'account_sync',
|
||||
clientInstanceId: 'device-a',
|
||||
fromUserId: 'user-1',
|
||||
payload: {
|
||||
type: 'friend-added',
|
||||
userId: 'friend-1',
|
||||
addedAt: 123
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -296,6 +296,11 @@ async function handleIdentify(user: ConnectedUser, message: WsMessage, connectio
|
||||
connectedUsers.set(connectionId, user);
|
||||
console.log(`User identified: ${user.displayName} (${user.oderId})`);
|
||||
|
||||
notifyOtherConnectionsForOderId(newOderId, {
|
||||
type: 'account_sync_peer_online',
|
||||
clientInstanceId: newClientInstanceId
|
||||
}, connectionId);
|
||||
|
||||
const voiceSnapshot = Array.from(connectedUsers.entries()).find(([otherConnectionId, otherUser]) =>
|
||||
otherConnectionId !== connectionId
|
||||
&& otherUser.oderId === newOderId
|
||||
@@ -541,6 +546,21 @@ function handleVoiceClientTakeover(user: ConnectedUser, message: WsMessage, conn
|
||||
}, connectionId);
|
||||
}
|
||||
|
||||
function handleAccountSync(user: ConnectedUser, message: WsMessage, connectionId: string): void {
|
||||
const payload = message['payload'];
|
||||
|
||||
if (!payload || typeof payload !== 'object' || typeof (payload as { type?: unknown }).type !== 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
notifyOtherConnectionsForOderId(user.oderId, {
|
||||
type: 'account_sync',
|
||||
clientInstanceId: normalizeClientInstanceId(message['clientInstanceId']) ?? user.clientInstanceId,
|
||||
fromUserId: user.oderId,
|
||||
payload
|
||||
}, connectionId);
|
||||
}
|
||||
|
||||
function handleTyping(user: ConnectedUser, message: WsMessage, connectionId: string): void {
|
||||
const typingSid = (message['serverId'] as string | undefined) ?? user.viewedServerId;
|
||||
const channelId = typeof message['channelId'] === 'string' && message['channelId'].trim() ? message['channelId'].trim() : 'general';
|
||||
@@ -747,6 +767,10 @@ export async function handleWebSocketMessage(connectionId: string, message: WsMe
|
||||
handleVoiceClientTakeover(user, message, connectionId);
|
||||
break;
|
||||
|
||||
case 'account_sync':
|
||||
handleAccountSync(user, message, connectionId);
|
||||
break;
|
||||
|
||||
case 'typing':
|
||||
handleTyping(user, message, connectionId);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user