This repository has been archived by the owner on Oct 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRoomList.php
84 lines (69 loc) · 2.2 KB
/
getRoomList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/php
<?php
use iGap\Api;
use React\EventLoop\Factory;
use React\Socket\Connector;
require_once(__DIR__ . '/../../vendor/autoload.php');
function getInput($msg)
{
echo "$msg : ";
return trim(fgets(STDIN));
}
function getRoomList($offset, $limit)
{
$getRoomList = new \Proto\ClientGetRoomList();
$pagination = new \Proto\Pagination();
$pagination->setOffset($offset);
$pagination->setLimit($limit);
$getRoomList->setPagination($pagination);
return Api::getInstance()->invoke(
Api::ACTION_CLIENT_GET_ROOM_LIST,
$getRoomList
);
}
$loop = Factory::create();
$connector = new Connector($loop, [
'dns' => '8.8.8.8',
'timeout' => 10
]);
Api::init($loop, $connector);
$token = file_get_contents(__DIR__ . '/login.token');
if ($token === false) {
throw new Exception('You must register to run this example');
}
$login = new \Proto\UserLogin();
$login->setToken($token);
$login->setAppName('iGap-PHP-Client');
$login->setAppId(11);
$login->setAppBuildVersion(1);
$login->setAppVersion('1.0.0');
$login->setPlatform(
strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? \Proto\Platform::WINDOWS : \Proto\Platform::LINUX
);
$login->setPlatformVersion('0');
$login->setDevice(\Proto\Device::PC);
$login->setDeviceName('UNKNOWN_DEVICE');
$login->setLanguage(\Proto\Language::EN_US);
Api::getInstance()->invoke(
Api::ACTION_USER_LOGIN,
$login
)->then(function () {
$offset = 0;
$limit = 10;
return getRoomList($offset, $limit)
->then(function (\Proto\ClientGetRoomListResponse $response) use ($offset, $limit) {
if ($response->getRooms()->count() !== 0) {
/** @var \Proto\Room $room */
foreach ($response->getRooms()->getIterator() as $room) {
echo 'RoomId : ' . $room->getId() . "\n";
echo $room->serializeToJsonString() . "\n\n";
sleep(1);
}
$offset += $response->getRooms()->count();
return getRoomList($offset, $limit);
}
});
})->otherwise(function (\Proto\ErrorResponse $error) {
echo 'Error #' . $error->getMajorCode() . '.' . $error->getMinorCode() . "\n";
});
$loop->run();