Skip to content

Commit cee7eba

Browse files
authored
Merge pull request #16 from eric2788/develop
忘了新增 listenInternal....
2 parents 029d086 + 86c60f4 commit cee7eba

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/el/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class MessageSource {
5353
// room 必须为真实房间号
5454
async listen(room, update_storage = true) {
5555
if (this.subscribing.has(room)) return false
56+
await this.listenInternal(room)
5657
this.subscribing.add(room)
5758
if (update_storage) {
5859
await update(data => {

test/blive.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const messager = require('../src/el/api/message-source');
33
const assert = require('assert')
44
const { default: axios } = require('axios')
55
const FormData = require('form-data')
6+
const { websocket } = require('../src/el/data-storer').settings
67

78
const toListen = [
89
22853788,
@@ -13,19 +14,34 @@ const toListen = [
1314
8725120,
1415
]
1516

17+
18+
const api = axios.create({
19+
baseURL: `http${websocket['use-tls'] ? 's' : ''}://${websocket.host}/subscribe`,
20+
timeout: 5000,
21+
headers: {
22+
'Content-Type': 'application/x-www-form-urlencoded',
23+
'Authorization': 'vup_monitors'
24+
}
25+
})
26+
1627
async function testListen() {
1728
await messager.connect();
1829
for (const room of toListen) {
1930
await messager.listen(room);
2031
}
2132
assert(toListen.every(room => messager.listening().has(room)), '未成功订阅所有房间');
33+
const res = await api.get()
34+
assert(toListen.every(room => (res.data ?? []).includes(room)), 'biligo-live-ws 服务器返回的房间列表不包含所有订阅的房间');
2235
}
2336

2437
async function testUnListen() {
2538
await messager.connect();
2639
const room = toListen[0];
2740
await messager.listen(room);
2841
assert(await messager.unlisten(room), '未成功取消监听');
42+
assert(!messager.listening().has(room), '监听列表仍然有被取消的房间');
43+
const res = await api.get()
44+
assert(!(res.data ?? []).includes(room), 'biligo-live-ws 服务器返回的房间列表仍然包含被取消的房间');
2945
}
3046

3147
// 獲取真實房間號

0 commit comments

Comments
 (0)