Protocol 11: sit out replaces kicking; nudge

Anyone can sit anyone out (host included); only you bring yourself back.
Out members stay in chat and the party, never block or count, and load no
media; a card with the live position and Join back (Space) replaces the
video. The mini player's x sits you out; optionally idle does too. Nudge:
the server forwards it to the target only (3/s, 20/min per sender); the
target hears the nudge sound, gets a toast and a taskbar attention
request. Kick, its messages, errors and dialog are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
foxyzandClaude Opus 5.5 committed 2026-10-09 21:05:35 +03:00
1 parent dbfd351ee4
commit 8b81da4069
46 files changed
+855 -599

No files matched your search

-188
View File
@@ -133,189 +133,6 @@ void main() {
await resp.drain();
});
test('kick: WS drops and media goes 403', () async {
final ch = WebSocketChannel.connect(
Uri.parse('ws://127.0.0.1:${server.boundPort}/sync'));
final firstCompleter = Completer<String>();
var wsClosed = false;
final sub = ch.stream.listen(
(m) {
if (!firstCompleter.isCompleted) firstCompleter.complete('$m');
},
onDone: () => wsClosed = true,
);
final msg = HelloMessage(
proto: RelayConstants.protoVersion,
secret: 'shh',
user: const HelloUser(name: 'mallory'),
media:
const HelloMedia(name: 'f.bin', size: 8192, duration: 10.0)).toJson();
ch.sink.add(jsonEncode(msg));
final first =
await firstCompleter.future.timeout(const Duration(seconds: 5));
final token = (jsonDecode(first) as Map)['token'] as String;
await server.session.kick(token);
final deadline = DateTime.now().add(const Duration(seconds: 5));
while (!wsClosed && DateTime.now().isBefore(deadline)) {
await Future.delayed(const Duration(milliseconds: 50));
}
expect(wsClosed, isTrue);
try {
await sub.cancel();
} catch (_) {}
try {
await ch.sink.close();
} catch (_) {}
final name = file.path.split(Platform.pathSeparator).last;
final resp = await mediaGet('/m/default/$token/$name');
expect(resp.statusCode, 403);
await resp.drain();
});
test('kick delivers reason then drops; instant rejoin works', () async {
final ch = WebSocketChannel.connect(
Uri.parse('ws://127.0.0.1:${server.boundPort}/sync'));
final messages = <String>[];
var wsClosed = false;
final sub = ch.stream.listen(
(m) => messages.add('$m'),
onDone: () => wsClosed = true,
);
HelloMessage helloFor(String who) => HelloMessage(
proto: RelayConstants.protoVersion,
secret: 'shh',
user: HelloUser(name: who),
media: const HelloMedia(
name: 'f.bin', size: 8192, duration: 10.0));
ch.sink.add(jsonEncode(helloFor(' sleepy').toJson()));
Map<String, Object?>? welcome;
final welcomeDeadline = DateTime.now().add(const Duration(seconds: 5));
while (DateTime.now().isBefore(welcomeDeadline)) {
for (final m in messages) {
final decoded = jsonDecode(m) as Map;
if (decoded['t'] == 'welcome') {
welcome = Map<String, Object?>.from(decoded);
}
}
if (welcome != null) break;
await Future.delayed(const Duration(milliseconds: 50));
}
expect(welcome, isNotNull);
final token = welcome!['token'] as String;
await server.session.kick(token, reason: 'idle too long');
final deadline = DateTime.now().add(const Duration(seconds: 5));
Map<String, Object?>? kicked;
while (DateTime.now().isBefore(deadline)) {
for (final m in messages.skip(1)) {
final decoded = jsonDecode(m) as Map;
if (decoded['t'] == 'kicked') {
kicked = Map<String, Object?>.from(decoded);
}
}
if (wsClosed && kicked != null) break;
await Future.delayed(const Duration(milliseconds: 50));
}
expect(wsClosed, isTrue);
expect(kicked, isNotNull);
expect(kicked!['reason'], 'idle too long');
try {
await sub.cancel();
} catch (_) {}
try {
await ch.sink.close();
} catch (_) {}
final rejoin = await hello('shh');
final decoded = jsonDecode(rejoin) as Map;
expect(decoded['t'], 'welcome');
final token2 = decoded['token'] as String;
expect(token2, isNot(token));
final name = file.path.split(Platform.pathSeparator).last;
final resp = await mediaGet('/m/default/$token2/$name');
expect(resp.statusCode, 200);
await resp.drain();
});
test('kick via socket: peer kicked, unknown target errors', () async {
Future<(WebSocketChannel, String, String, List<String>)> join(String who,
[String host = '127.0.0.1']) async {
final ch = WebSocketChannel.connect(
Uri.parse('ws://$host:${server.boundPort}/sync'));
final messages = <String>[];
ch.stream.listen((m) => messages.add('$m'));
final msg = HelloMessage(
proto: RelayConstants.protoVersion,
secret: 'shh',
user: HelloUser(name: who),
media: const HelloMedia(
name: 'f.bin', size: 8192, duration: 10.0)).toJson();
ch.sink.add(jsonEncode(msg));
Map<String, Object?>? welcome;
final deadline = DateTime.now().add(const Duration(seconds: 5));
while (DateTime.now().isBefore(deadline)) {
for (final m in messages) {
final decoded = jsonDecode(m) as Map;
if (decoded['t'] == 'welcome') {
welcome = Map<String, Object?>.from(decoded);
}
}
if (welcome != null) break;
await Future.delayed(const Duration(milliseconds: 50));
}
expect(welcome, isNotNull,
reason: 'no welcome for $who: $messages');
final w = welcome!;
return (ch, w['token'] as String, w['memberId'] as String, messages);
}
Map<String, Object?>? findType(List<String> messages, String type) {
for (final m in messages) {
final decoded = jsonDecode(m) as Map;
if (decoded['t'] == type) return Map<String, Object?>.from(decoded);
}
return null;
}
Future<Map<String, Object?>?> waitType(
List<String> messages, String type, Duration timeout) async {
final deadline = DateTime.now().add(timeout);
while (DateTime.now().isBefore(deadline)) {
final found = findType(messages, type);
if (found != null) return found;
await Future.delayed(const Duration(milliseconds: 50));
}
return findType(messages, type);
}
final (a, _, _, messagesA) = await join('alice');
final (b, tokenB, idB, messagesB) = await join('bob');
try {
a.sink.add(jsonEncode(
KickRequest(target: idB, reason: 'afk?').toJson()));
final kicked = await waitType(
messagesB, 'kicked', const Duration(seconds: 5));
expect(kicked, isNotNull);
expect(kicked!['reason'], 'afk?');
expect(server.session.gate(tokenB), MediaGate.forbidden);
a.sink.add(
jsonEncode(const KickRequest(target: 'm99').toJson()));
final err = await waitType(
messagesA, 'err', const Duration(seconds: 5));
expect(err, isNotNull);
} finally {
try {
await a.sink.close();
} catch (_) {}
try {
await b.sink.close();
} catch (_) {}
}
});
test('silent socket dropped and member removed', () async {
final ch = WebSocketChannel.connect(
Uri.parse('ws://127.0.0.1:${server.boundPort}/sync'));
@@ -557,11 +374,6 @@ void main() {
ProfileIntent(avatar: 'x' * (RelayConstants.maxAvatarBytes + 1)).toJson()));
final err = await waitFor((m) => m['t'] == 'err');
expect(err['message'], 'rejected: avatar too large');
await server.session.kick(token);
final kicked = await avatarGet(token, hash);
expect(kicked.statusCode, 403);
await kicked.drain();
} finally {
await sub.cancel();
try {