From 714d28358f69eb23ee70fae91239ce1f0c652e42 Mon Sep 17 00:00:00 2001 From: Developer Date: Tue, 17 Mar 2026 18:00:00 +0800 Subject: [PATCH] 1 --- app/index.tsx | 1 - app/live/[roomId].tsx | 2 ++ components/LivePlayer.tsx | 9 ++------- hooks/useLiveDanmaku.ts | 17 ++++++++--------- services/bilibili.ts | 11 +++++++---- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/index.tsx b/app/index.tsx index ce18aa5..53cdff6 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -62,7 +62,6 @@ const LIVE_AREAS = [ { id: 9, name: "虚拟主播" }, { id: 10, name: "生活" }, { id: 11, name: "知识" }, - { id: 13, name: "赛事" }, ]; export default function HomeScreen() { diff --git a/app/live/[roomId].tsx b/app/live/[roomId].tsx index 0b90f1f..73be452 100644 --- a/app/live/[roomId].tsx +++ b/app/live/[roomId].tsx @@ -30,6 +30,7 @@ export default function LiveDetailScreen() { const isLive = room?.live_status === 1; const hlsUrl = stream?.hlsUrl ?? ""; + const flvUrl = stream?.flvUrl ?? ""; const qualities = stream?.qualities ?? []; const currentQn = stream?.qn ?? 0; @@ -51,6 +52,7 @@ export default function LiveDetailScreen() { {/* Player */} - {/* LIVE badge top-left */} - - - live - - {/* Center play/pause */} { + const authBody = JSON.stringify({ uid: 0, roomid: roomId, protover: 2, - platform: 'h5', // must match platform param used in getConf API call + platform: 'h5', type: 2, key: token, }); const authPkt = buildPacket(authBody, 7); - const hdr = Array.from(authPkt.slice(0, 16)) - .map(b => b.toString(16).padStart(2, '0')).join(' '); - // Send as ArrayBuffer (more reliable than Uint8Array in some RN/Hermes versions) - const t0 = Date.now(); + + ws.send(authPkt.buffer as ArrayBuffer); heartbeatRef.current = setInterval(() => { @@ -171,10 +172,8 @@ export function useLiveDanmaku(roomId: number): DanmakuItem[] { if (items.length > 0) setDanmakus(prev => [...prev, ...items]); }; - ws.onerror = (e: Event) => { - const ws2 = (e as any).currentTarget as WebSocket; - }; - ws.onclose = (e: CloseEvent) => { + ws.onerror = () => {}; + ws.onclose = () => { if (heartbeatRef.current) clearInterval(heartbeatRef.current); }; } diff --git a/services/bilibili.ts b/services/bilibili.ts index eb73e8c..4191d03 100644 --- a/services/bilibili.ts +++ b/services/bilibili.ts @@ -261,7 +261,7 @@ export async function getLiveAnchorInfo(roomId: number): Promise export async function getLiveStreamUrl(roomId: number, qn = 10000): Promise { try { const res = await api.get(`${LIVE_BASE}/xlive/web-room/v2/index/getRoomPlayInfo`, { - params: { room_id: roomId, protocol: '0,1', format: '0,1,2', codec: '0', qn }, + params: { room_id: roomId, protocol: '0,1', format: '0,1,2', codec: '0', qn, platform: 'android' }, }); const playurl = res.data?.data?.playurl_info?.playurl; const streams: any[] = playurl?.stream ?? []; @@ -338,11 +338,14 @@ export async function searchVideos(keyword: string, page = 1): Promise { - const res = await api.get(`${LIVE_BASE}/room/v1/Danmu/getConf`, { - params: { room_id: roomId, platform: 'h5' }, + const { imgKey, subKey } = await getWbiKeys(); + const signed = signWbi({ id: roomId, type: 0 }, imgKey, subKey); + const res = await api.get(`${LIVE_BASE}/xlive/web-room/v1/index/getDanmuInfo`, { + params: signed, }); const data = res.data.data; - const hostInfo = data?.host_server_list?.[0]; + const hostList: any[] = data?.host_list ?? []; + const hostInfo = hostList.find(h => h.wss_port === 443) ?? hostList[0]; const host = hostInfo ? `wss://${hostInfo.host}:${hostInfo.wss_port}/sub` : 'wss://broadcastlv.chat.bilibili.com/sub';