-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
waiting for event with 3 layers added; also improved event collecting
- Loading branch information
1 parent
726db6e
commit 719bb0a
Showing
4 changed files
with
41 additions
and
15 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/millicast-sdk/integration-tests/features/simulcast.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 34 additions & 13 deletions
47
packages/millicast-sdk/integration-tests/src/support-utils/events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')} | ||
} |