Skip to content

Commit

Permalink
waiting for event with 3 layers added; also improved event collecting
Browse files Browse the repository at this point in the history
  • Loading branch information
jwrobdolby committed Nov 7, 2024
1 parent 726db6e commit 719bb0a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Feature: Simulcast Feature

Scenario: Publisher connects with simulcast and viewer subscribes to layers event
Scenario: Publisher connects with simulcast and viewer select layers
Given the "publisher1" opens "Publisher" app
When the "publisher1" starts the stream with the specified options
| codec | h264 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ScenarioWorld, logger, runStep } from "cucumber-playwright-framework";
import { getListOfActorsEvents, waitForEventLayers } from "../support-utils/events";

export async function viewerSelectLayer(
scenarioWorld: ScenarioWorld,
Expand All @@ -7,6 +8,9 @@ export async function viewerSelectLayer(
) {
logger.debug(`viewerSelectLayer function was called`);

await getListOfActorsEvents(scenarioWorld,actor)
await waitForEventLayers(scenarioWorld,actor)

await runStep([
`the ${actor} switch to the "Viewer" app`,
`the ${actor} executes the "window.millicastView.select({encodingId:"${encodingId}"})" JavaScript function on the page`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ export async function verifyViwerVideoResolutionForLayer(
width = layer["width"]
}
}

if (!height || !width) {throw Error(`Resolution values are missing for layer with encodingId ${encodingId}`)}
await runStep([
`the ${actor} switch to the "Viewer" app`,
`the ${actor} waits for "5" seconds`,
`the "TestUtil.getResolution('${playerId}')[0]" JavaScript function result should be ${height}`,
`the "TestUtil.getResolution('${playerId}')[1]" JavaScript function result should be ${width}`,
], scenarioWorld);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
import { ScenarioWorld } from "cucumber-playwright-framework";
import { WebSocket } from "playwright";
import { retryUntilTrue } from "./generic";

export async function collectWsEvents(scenarioWorld:ScenarioWorld, actor:string) {
//init events collection (array) for actor
scenarioWorld.localDataStore.save(actor+"_eventsList",[])

scenarioWorld.page.on('websocket', (ws:WebSocket) => {
ws.on('framereceived', (event:any) => {
const payloadJson = JSON.parse(event.payload);
if (payloadJson["name"] === "active") {
scenarioWorld.localDataStore.save(actor+"_event_"+Date.now(), payloadJson);
}
if (payloadJson["name"] === "layers") {
scenarioWorld.localDataStore.save(actor+"_event_"+Date.now(), payloadJson);
if (payloadJson["name"] === "active" || payloadJson["name"] === "layers") {
const actorsEventList: Array<any> = scenarioWorld.localDataStore.load(actor+"_eventsList")
actorsEventList.push(payloadJson)
scenarioWorld.localDataStore.save(actor+"_eventsList", actorsEventList)
}
});
}
)}

export async function getListOfActorsEvents(scenarioWorld: ScenarioWorld, actor: string) {
return scenarioWorld.localDataStore.load(actor+"_eventsList")
}

export async function waitForEventLayers(scenarioWorld: ScenarioWorld, actor: string) {
const verifyMethod = async (): Promise<boolean> => {
const eventsList: any = await getListOfActorsEvents(scenarioWorld, actor);
let eventPresent = false;
for (const myEvent of eventsList) {
if(myEvent["name"] === "layers" && myEvent["data"]["medias"]["0"]["layers"].length === 3) {
eventPresent = true
console.log("3 Layers Found")
}
} return(eventPresent) as boolean
}
await retryUntilTrue(verifyMethod, 20)
}

export async function getLayersFromEvent(scenarioWorld: ScenarioWorld, actor: string) {
const allevents: Map<any, any> = scenarioWorld.localDataStore.getAllData();
const eventsList: any = await getListOfActorsEvents(scenarioWorld, actor);
let layers:Array<any> = [];
allevents.forEach((value, key) => {
if(key.includes("event") && value["name"] === "layers"){
layers = value["data"]["medias"]["0"]["layers"]
}
});
return layers;
}
for (const myEvent of eventsList) {
if(myEvent["name"] === "layers" && myEvent["data"]["medias"]["0"]["layers"].length === 3) {
layers = myEvent["data"]["medias"]["0"]["layers"]
}
} if (layers) {return layers}
else {throw Error('No layers found')}
}

0 comments on commit 719bb0a

Please sign in to comment.