Files
Heimdall/tests/Heimdall.E2E.Tests/Pages/LiveViewTests.cs
T
arnaud.dartois 848a050fad
Heimdall Gitea / Detect CI scope (pull_request) Successful in 30s
Heimdall Gitea / Build and tests (pull_request) Failing after 7m59s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 2s
feat(live): relay optional audio over WebRTC
2026-11-05 19:56:02 +01:00

101 lines
4.1 KiB
C#

using System.Net;
using System.Text.Json;
using Shouldly;
namespace Heimdall.E2E.Tests.Pages;
[Collection("E2E")]
public sealed class LiveViewTests : E2ETestBase
{
public LiveViewTests(TestCommon.PostgreSqlContainerFixture postgres) : base(postgres) { }
[Fact]
public async Task Live_view_negotiates_audio_and_video_and_starts_muted_for_autoplay()
{
var cameraId = Guid.NewGuid();
await Page.RouteAsync("**/api/live-media/**", async route =>
{
var request = route.Request;
if (request.Url.EndsWith("/session", StringComparison.Ordinal))
{
await route.FulfillAsync(new()
{
Status = (int)HttpStatusCode.OK,
ContentType = "application/json",
Body = JsonSerializer.Serialize(new
{
url = $"{BaseUrl}/media/{cameraId:D}/whep",
token = "synthetic-read-ticket",
sessionId = Guid.NewGuid(),
iceServers = Array.Empty<object>()
})
});
return;
}
await route.FulfillAsync(new() { Status = (int)HttpStatusCode.NoContent });
});
await Page.RouteAsync("**/media/**/whep", route => route.FulfillAsync(new()
{
Status = (int)HttpStatusCode.Created,
ContentType = "application/sdp",
Headers = new Dictionary<string, string> { ["Location"] = "/media/session-resource" },
Body = "v=0\r\n"
}));
await Page.RouteAsync("**/media/session-resource", route => route.FulfillAsync(new()
{
Status = (int)HttpStatusCode.NoContent
}));
await Page.GotoAsync($"{BaseUrl}/login");
await Page.EvaluateAsync("""
() => {
window.__liveViewTransceivers = [];
window.__liveViewTracks = [];
window.RTCPeerConnection = class {
constructor() { this.iceGatheringState = 'complete'; }
addTransceiver(kind, options) { window.__liveViewTransceivers.push({ kind, direction: options.direction }); }
async createOffer() { return { type: 'offer', sdp: 'v=0\\r\\n' }; }
async setLocalDescription(description) { this.localDescription = description; }
async setRemoteDescription() {
const stream = new MediaStream();
for (const kind of ['video', 'audio']) {
window.__liveViewTracks.push(kind);
this.ontrack({ streams: [stream], track: { kind, addEventListener() {} } });
}
}
addEventListener() {}
close() {}
};
}
""");
var result = await Page.EvaluateAsync<JsonElement>("""
async cameraId => {
const video = document.createElement('video');
video.dataset.liveCamera = cameraId;
video.play = async () => { window.__liveViewPlayCalled = true; };
document.body.append(video);
const live = await import('/js/live-view.js');
await live.start(cameraId, video);
const value = {
transceivers: window.__liveViewTransceivers,
tracks: window.__liveViewTracks,
muted: video.muted,
playCalled: window.__liveViewPlayCalled
};
await live.stop(cameraId);
return value;
}
""", cameraId.ToString("D"));
result.GetProperty("transceivers").EnumerateArray().Select(x => x.GetProperty("kind").GetString())
.ShouldBe(new[] { "video", "audio" });
result.GetProperty("transceivers").EnumerateArray().ShouldAllBe(x =>
x.GetProperty("direction").GetString() == "recvonly");
result.GetProperty("tracks").EnumerateArray().Select(x => x.GetString()).ShouldBe(new[] { "video", "audio" });
result.GetProperty("muted").GetBoolean().ShouldBeTrue();
result.GetProperty("playCalled").GetBoolean().ShouldBeTrue();
}
}