1 | <?php |
||
10 | class AppClient |
||
11 | { |
||
12 | private $auth; |
||
13 | private $baseURL; |
||
14 | |||
15 | public function __construct(Auth $auth) |
||
21 | |||
22 | /** |
||
23 | * 创建应用 |
||
24 | * |
||
25 | * @param string $hub 绑定的直播 hub |
||
26 | * @param string $title app 的名称 注意,Title 不是唯一标识,重复 create 动作将生成多个 app |
||
27 | * @param int $maxUsers 连麦房间支持的最大在线人数 |
||
28 | * @param bool $noAutoKickUser 禁止自动踢人(抢流),默认为 false |
||
29 | * @return array |
||
30 | * @link https://doc.qnsdk.com/rtn/docs/server_overview#2_1 |
||
31 | */ |
||
32 | public function createApp($hub, $title, $maxUsers = null, $noAutoKickUser = false) |
||
45 | |||
46 | /** |
||
47 | * 更新一个应用的配置信息 |
||
48 | * |
||
49 | * @param string $appId app 的唯一标识,创建的时候由系统生成 |
||
50 | * @param string $hub app 的名称,可选 |
||
51 | * @param string $title 绑定的直播 hub,可选,用于合流后 rtmp 推流 |
||
52 | * @param int $maxUsers 连麦房间支持的最大在线人数,可选 |
||
53 | * @param bool $noAutoKickUser 禁止自动踢人,可选 |
||
54 | * @param null $mergePublishRtmp 连麦合流转推 RTMP 的配置,可选择。其详细配置可以参考文档 |
||
55 | * @return array |
||
56 | * @link https://doc.qnsdk.com/rtn/docs/server_overview#2_1 |
||
57 | */ |
||
58 | public function updateApp($appId, $hub, $title, $maxUsers = null, $noAutoKickUser = false, $mergePublishRtmp = null) |
||
75 | |||
76 | /** |
||
77 | * 获取应用信息 |
||
78 | * |
||
79 | * @param string $appId |
||
80 | * @return array |
||
81 | * @link https://doc.qnsdk.com/rtn/docs/server_overview#2_1 |
||
82 | */ |
||
83 | public function getApp($appId) |
||
88 | |||
89 | /** |
||
90 | * 删除应用 |
||
91 | * |
||
92 | * @param string $appId app 的唯一标识,创建的时候由系统生成 |
||
93 | * @return array |
||
94 | * @link https://doc.qnsdk.com/rtn/docs/server_overview#2_1 |
||
95 | */ |
||
96 | public function deleteApp($appId) |
||
101 | |||
102 | /** |
||
103 | * 获取房间内用户列表 |
||
104 | * |
||
105 | * @param string $appId app 的唯一标识,创建的时候由系统生成 |
||
106 | * @param string $roomName 操作所查询的连麦房间 |
||
107 | * @return array |
||
108 | * @link https://doc.qnsdk.com/rtn/docs/server_overview#2_2 |
||
109 | */ |
||
110 | public function listUser($appId, $roomName) |
||
115 | |||
116 | /** |
||
117 | * 指定一个用户踢出房间 |
||
118 | * |
||
119 | * @param string $appId app 的唯一标识,创建的时候由系统生成 |
||
120 | * @param string $roomName 连麦房间 |
||
121 | * @param string $userId 操作所剔除的用户 |
||
122 | * @return mixed |
||
123 | * @link https://doc.qnsdk.com/rtn/docs/server_overview#2_2 |
||
124 | */ |
||
125 | public function kickUser($appId, $roomName, $userId) |
||
130 | |||
131 | /** |
||
132 | * 停止一个房间的合流转推 |
||
133 | * |
||
134 | * @param string $appId |
||
135 | * @param string $roomName |
||
136 | * @return array |
||
137 | * @link https://doc.qnsdk.com/rtn/docs/server_overview#2_2 |
||
138 | */ |
||
139 | public function stopMerge($appId, $roomName) |
||
144 | |||
145 | /** |
||
146 | * 获取应用中活跃房间 |
||
147 | * |
||
148 | * @param string $appId 连麦房间所属的 app |
||
149 | * @param null $prefix 所查询房间名的前缀索引,可以为空。 |
||
150 | * @param int $offset 分页查询的位移标记 |
||
151 | * @param int $limit 此次查询的最大长度 |
||
152 | * @return array |
||
153 | * @link https://doc.qnsdk.com/rtn/docs/server_overview#2_2 |
||
154 | */ |
||
155 | public function listActiveRooms($appId, $prefix = null, $offset = null, $limit = null) |
||
174 | |||
175 | /** |
||
176 | * 生成加入房间的令牌 |
||
177 | * |
||
178 | * @param string $appId app 的唯一标识,创建的时候由系统生成 |
||
179 | * @param string $roomName 房间名称,需满足规格 ^[a-zA-Z0-9_-]{3,64}$ |
||
180 | * @param int $userId 请求加入房间的用户 ID,需满足规格 ^[a-zA-Z0-9_-]{3,50}$ |
||
181 | * @param int $expireAt 鉴权的有效时间,传入以秒为单位的64位 Unix 绝对时间 |
||
182 | * @param string $permission 该用户的房间管理权限,"admin" 或 "user",默认为 "user" |
||
183 | * @return string |
||
184 | * @link https://doc.qnsdk.com/rtn/docs/server_overview#1 |
||
185 | */ |
||
186 | public function appToken($appId, $roomName, $userId, $expireAt, $permission) |
||
196 | |||
197 | private function get($url, $cType = null) |
||
207 | |||
208 | private function delete($url, $contentType = 'application/json') |
||
218 | |||
219 | private function post($url, $body, $contentType = 'application/json') |
||
230 | } |
||
231 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.