writeln(sprintf('%-5s %s %s', $who, $direction, str_replace("\t", ' ⇥> ', $line)));
};
$send = static function (MemorySession $s, string $code, array $fields) use ($chat, $show): void {
$show($s->address(), '→>', implode("\t", [$code, ...$fields]));
$chat->receive($s, $code, $fields);
};
$flush = static function () use ($alice, $bob, $show): void {
foreach ([$alice, $bob] as $s) {
foreach ($s->take() as $line) {
$show($s->address(), '←>', $line);
}
}
};
$chat->connect($alice);
$chat->connect($bob);
$flush();
$send($alice, '0', ['0', TempId::make('Alice', 24, 0, 'Lyon')]);
$flush();
$send($bob, '0', ['0', TempId::make('Bob', 27, 1, 'Paris')]);
$flush();
$send($alice, '20', ['Accueil', '0']);
$flush();
$send($bob, '20', ['Accueil', '0']);
$flush();
$send($alice, '70', ['0100Salut tout le monde :-)']);
$flush();
$bobId = array_key_last($chat->users());
$send($alice, '72', [(string)$bobId, '0100Tu viens de Paris ?']);
$flush();
$send($bob, '94', []);
$flush();
$chat->disconnect($alice);
$flush();
@unlink(sys_get_temp_dir() . '/caramail-demo-' . getmypid() . '.json');
return Command::SUCCESS;
}
}