-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestLiveAPI.js
More file actions
66 lines (52 loc) · 1.98 KB
/
testLiveAPI.js
File metadata and controls
66 lines (52 loc) · 1.98 KB
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
// server/testLiveAPI.js
// Test script to manually test live stream API endpoints
import fs from "fs";
import path from "path";
console.log("Testing Live Stream API...");
// Test 1: Check if live directory exists
const liveDir = path.join(process.cwd(), "uploads", "live");
console.log("Live directory path:", liveDir);
if (fs.existsSync(liveDir)) {
console.log("✅ Live directory exists");
// Test 2: List all stream directories
const streamIds = fs.readdirSync(liveDir);
console.log("Found stream directories:", streamIds);
// Test 3: Check each stream for HLS files
streamIds.forEach((streamId) => {
const streamDir = path.join(liveDir, streamId);
const playlistPath = path.join(streamDir, "index.m3u8");
const segmentPath = path.join(streamDir, "segment_000.ts");
console.log(`\nStream ${streamId}:`);
console.log(` Directory exists: ${fs.existsSync(streamDir)}`);
console.log(` Playlist exists: ${fs.existsSync(playlistPath)}`);
console.log(` Segment exists: ${fs.existsSync(segmentPath)}`);
if (fs.existsSync(streamDir)) {
const files = fs.readdirSync(streamDir);
console.log(` All files: ${files.join(", ")}`);
}
});
} else {
console.log("❌ Live directory does not exist");
// Create test directory structure
console.log("Creating test directory structure...");
fs.mkdirSync(liveDir, { recursive: true });
// Create a test stream
const testStreamId = Date.now().toString();
const testStreamDir = path.join(liveDir, testStreamId);
fs.mkdirSync(testStreamDir, { recursive: true });
// Create a test HLS playlist
const testPlaylist = `#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:2.0,
segment_000.ts
#EXT-X-ENDLIST`;
fs.writeFileSync(path.join(testStreamDir, "index.m3u8"), testPlaylist);
fs.writeFileSync(
path.join(testStreamDir, "segment_000.ts"),
"test segment data"
);
console.log(`✅ Created test stream: ${testStreamId}`);
}
console.log("\nTest completed!");