How to use getTransceiver method in wpt

Best JavaScript code snippet using wpt

index.js

Source:index.js Github

copy

Full Screen

...240 if (client.room.conductor && client.room.conductor !== client) {241 client.room.singers.push(client.room.conductor);242 }243 client.room.conductor = client;244 let conductorVideo = client.peer?.getTransceiver(RTCTransceivers.MY_VIDEO).receiver.track245 let conductorAudio = client.peer?.getTransceiver(RTCTransceivers.MY_AUDIO).receiver.track246 for(let c of client.room.singers) {247 c.sendJSON({cmd: "updateRoomConductor", conductorUserId: client.room.conductor?.user.userId})248 client.sendJSON({cmd: "updateSingerState", user: c.user, state: c.singerState});249 if (conductorVideo && c.peer) {250 await c.peer.getTransceiver(RTCTransceivers.CONDUCTOR_VIDEO).sender.replaceTrack(conductorVideo);251 await c.peer.getTransceiver(RTCTransceivers.CONDUCTOR_AUDIO).sender.replaceTrack(conductorAudio);252 }253 }254 clientLog(client, `Conducting room ${client.room.roomId}`)255 } else if (client.conducting) {256 client.conducting = false;257 client.room.conductor = null;258 client.room.singers.push(client);259 clientLog(client, `No longer conducting room ${client.room.roomId}`)260 }261 return true;262 },263 listProjects: async (client) => {264 return await listProjects(client.room.roomId);265 },266 createProject: async (client, {name}) => {267 requireConductor(client);268 let project = await addProject(uuid(), client.room.roomId, name);269 let lanes = await listLanes(project.projectId);270 let items = await listItemsByProject(project.projectId);271 let users = await listUsers(project.projectId);272 client.room.currentProjectId = project.projectId;273 await saveRoom(client.room);274 conduct(client.room, {cmd: "loadProject", project, lanes, items, users});275 return {project, lanes, items, users};276 },277 loadProject: async (client, {projectId}) => {278 let project = await getProject(projectId);279 let lanes = await listLanes(projectId);280 let items = await listItemsByProject(projectId);281 let users = await listUsers(projectId);282 if (client.conducting) {283 roomLog(client.room, `Loading project ${projectId}`);284 client.room.currentProjectId = projectId;285 await saveRoom(client.room);286 conduct(client.room, {cmd: "loadProject", project, lanes, items, users});287 }288 return {project, lanes, items, users};289 },290 play: (client, {startTime}) => {291 requireConductor(client);292 roomLog(client.room, `Playing from ${startTime} seconds`);293 conduct(client.room, {cmd: "play", startTime});294 },295 stop: (client) => {296 requireConductor(client);297 roomLog(client.room, `Stopping`);298 conduct(client.room, {cmd: "stop"});299 },300 startRecording: (client) => {301 requireConductor(client);302 roomLog(client.room, `Recording`);303 conduct(client.room, {cmd: "startRecording"});304 },305 stopRecording: (client) => {306 requireConductor(client);307 roomLog(client.room, `Stop recording`);308 conduct(client.room, {cmd: "stopRecording"});309 },310 seek: (client, {time}) => {311 requireConductor(client);312 roomLog(client.room, `Seek to ${time}`);313 conduct(client.room, {cmd: "seek", time});314 },315 singerStateUpdate: (client, {state}) => {316 client.singerState = state;317 for (let c of client.room.clients) {318 c.sendJSON({cmd: "updateSingerState", user: client.user, state});319 }320 },321 uploadItem: async (client, { name }, data) => {322 clientLog(client, "New upload:", name, data.length, "bytes");323 let itemId = uuid();324 fs.mkdirSync(".items", {recursive: true});325 fs.writeFileSync(`.items/${itemId}.${name}`, data);326 let laneIdx = (await listLanes(client.room.currentProjectId)).length;327 let lane = await addLane(uuid(), client.room.currentProjectId, client.user.userId, name, laneIdx, true);328 let itemIdx = (await listItemsByProject(client.room.currentProjectId)).filter(i => i.laneId === lane.laneId).length;329 let item = await addItem(itemId, lane.laneId, 0, 0, 0, itemIdx, `/.items/${itemId}.${name}`, null, null);330 for (let c of client.room.clients) {331 c.sendJSON({cmd: "newItem", item, lane, user: client.user});332 }333 },334 newItem: async (client, { itemId, laneId, videoBytes, backingTrackId, referenceOutputStartTime }, data) => {335 requireUuid(itemId);336 clientLog(client, "New item:", itemId, data.length-videoBytes, "bytes of audio, ", videoBytes, "bytes of video");337 fs.mkdirSync(".items", {recursive: true});338 fs.writeFileSync(`.items/${itemId}.original.vid`, data.subarray(0,videoBytes));339 fs.writeFileSync(`.items/${itemId}.reference.aud`, data.subarray(videoBytes));340 await new Promise((resolve, reject) => ffmpeg(`.items/${itemId}.original.vid`)341 // Extract the recorded audio from the video342 .output(`.items/${itemId}.aud`)343 .noVideo()344 .format("f32le")345 .audioCodec("pcm_f32le")346 .audioFrequency(44100)347 .audioChannels(1)348 // Strip the audio from the video349 .output(`.items/${itemId}.vid`)350 .noAudio()351 .videoCodec("copy")352 .format("matroska")353 .on('error', reject)354 .on('end', resolve)355 .run());356 let offset = align(itemId);357 await exportWav(`.items/${itemId}.aud`);358 await exportWav(`.items/${itemId}.cancelled.aud`);359 await exportWav(`.items/${itemId}.reference.aud`);360 let lane = await getLane(laneId);361 if (!lane) {362 // No valid lane was provided. Create a new lane for this user.363 lane = await _createLane(client.room.currentProjectId, client.user.userId);364 }365 let itemIdx = (await listItemsByProject(client.room.currentProjectId)).filter(i => i.laneId === lane.laneId).length;366 let item = await addItem(itemId, lane.laneId, referenceOutputStartTime, 0, 0, itemIdx, `/.items/${itemId}.cancelled.aud`, `/.items/${itemId}.vid`, offset);367 for (let c of client.room.clients) {368 c.sendJSON({cmd: "newItem", item, lane, user: client.user});369 }370 },371 deleteItem: async (client, {itemId}) => {372 requireConductor(client);373 let item = await db.getItem(itemId);374 if (item) {375 await _deleteItem(client, item);376 }377 },378 deleteLane: async (client, {laneId}) => {379 requireConductor(client);380 let lane = await db.getLane(laneId);381 if (lane) {382 for (let item of await listItemsByLane(laneId)) {383 await _deleteItem(client, item);384 }385 conduct(client.room, {cmd: "deleteLane", laneId});386 await deleteLane(laneId);387 }388 },389 updateLane: async (client, {lane}) => {390 requireConductor(client); // TODO: Or owner of lane.391 await saveLane(lane);392 let items = await listItemsByLane(lane.laneId);393 let user = await getUser(lane.userId);394 conduct(client.room, {cmd: "updateLane", lane, items, user});395 },396 setTargetLane: async (client, {userId, laneId}) => {397 requireConductor(client);398 if (userId !== client.user.userId) {399 for(let c of client.room.clients) {400 if (c.user.userId === userId) {401 c.sendJSON({cmd: "setTargetLane", userId, laneId});402 }403 }404 }405 },406 updateItem: async (client, {item}) => {407 requireConductor(client); // TODO: Or owner of item.408 let lane = await getLane(item.laneId);409 if (item.newLaneId !== undefined) {410 lane = await _createLane(client.room.currentProjectId, lane.userId);411 item.laneId = lane.laneId;412 delete item.newLaneId;413 }414 await saveItem(item);415 for (let c of client.room.clients) {416 c.sendJSON({cmd: "updateItem", item, lane});417 }418 },419 setRehearsalState: async (client, {roomId, rehearsalState}) => {420 requireConductor(client);421 client.room.rehearsalState = rehearsalState;422 conduct(client.room, {cmd: "setRehearsalState", rehearsalState});423 await saveRoom(client.room);424 },425 rtcRequestOffer: async (client) => {426 client.peer = new Peer({ initiator: true, wrtc });427 for (let t of RTCTransceivers) {428 client.peer.addTransceiver(/video|audio/.exec(t)[0]);429 }430 client.peer.on("signal", data => {431 client.sendJSON({cmd: "rtcSignal", data})432 });433 client.peer.on("error", err => {434 if (err.message !== "Ice connection failed.") {435 console.error(err);436 }437 });438 if (!client.conducting) {439 if (client.room.conductor) {440 let conductorVideo = client.room.conductor?.peer.getTransceiver(RTCTransceivers.MY_VIDEO).receiver.track441 let conductorAudio = client.room.conductor?.peer.getTransceiver(RTCTransceivers.MY_AUDIO).receiver.track442 await client.peer.getTransceiver(RTCTransceivers.CONDUCTOR_VIDEO).sender.replaceTrack(conductorVideo);443 await client.peer.getTransceiver(RTCTransceivers.CONDUCTOR_AUDIO).sender.replaceTrack(conductorAudio);444 }445 let videoSink = new RTCVideoSink(client.peer.getTransceiver(RTCTransceivers.MY_VIDEO).receiver.track);446 videoSink.addEventListener("frame", async ({frame}) => {447 if (client.room && !client.conducting) {448 let myIdx = client.room.singers.indexOf(client);449 let gridSize = Math.ceil(Math.sqrt(client.room.singers.length));450 let gridX = myIdx % gridSize;451 let gridY = Math.floor(myIdx / gridSize);452 let tileWidth = 640/gridSize;453 let tileHeight = 480/gridSize;454 try {455 //let start = performance.now();456 video.i420overlay(frame.data.buffer, client.room.video.frame.data.buffer, frame.width, frame.height, gridX * tileWidth, gridY * tileHeight, tileWidth, tileHeight);457 //console.log("Frame processing took", (performance.now() - start).toFixed(3), "ms");458 } catch (e) {459 console.error(e);460 }461 }462 });463 } else {464 let conductorVideo = client.peer.getTransceiver(RTCTransceivers.MY_VIDEO).receiver.track465 let conductorAudio = client.peer.getTransceiver(RTCTransceivers.MY_AUDIO).receiver.track466 for(let c of client.room.singers) {467 if (conductorVideo && c.peer) {468 await c.peer.getTransceiver(RTCTransceivers.CONDUCTOR_VIDEO).sender.replaceTrack(conductorVideo);469 await c.peer.getTransceiver(RTCTransceivers.CONDUCTOR_AUDIO).sender.replaceTrack(conductorAudio);470 }471 }472 }473 await client.peer.getTransceiver(RTCTransceivers.CHOIR_VIDEO).sender.replaceTrack(client.room.video.source.createTrack());474 if (client?.room.speaker) {475 await client.peer.getTransceiver(RTCTransceivers.SPEAKER_VIDEO).sender.replaceTrack(client.room.speaker.peer.getTransceiver(RTCTransceivers.MY_VIDEO).receiver.track);476 await client.peer.getTransceiver(RTCTransceivers.SPEAKER_AUDIO).sender.replaceTrack(client.room.speaker !== client ? client.room.speaker.peer.getTransceiver(RTCTransceivers.MY_AUDIO).receiver.track : null);477 client.sendJSON({cmd: "nowSpeaking", user: client.room.speaker.user});478 }479 },480 rtcSignal: async (client, {data}) => {481 if (client.peer) {482 client.peer.signal(data);483 }484 },485 requestSpeak: async (client, {wantsToSpeak}) => {486 if (client.room.speaker && client.room.speaker !== client) {487 return false;488 }489 if (client.peer && !client.conducting) {490 client.room.speaker = wantsToSpeak ? client : null;491 let videoTrack = wantsToSpeak ? client.peer.getTransceiver(RTCTransceivers.MY_VIDEO).receiver.track : null;492 let audioTrack = wantsToSpeak ? client.peer.getTransceiver(RTCTransceivers.MY_AUDIO).receiver.track : null;493 for(let c of client.room.clients) {494 if (c.peer) {495 await c.peer.getTransceiver(RTCTransceivers.SPEAKER_VIDEO).sender.replaceTrack(videoTrack);496 await c.peer.getTransceiver(RTCTransceivers.SPEAKER_AUDIO).sender.replaceTrack(c !== client ? audioTrack : null);497 c.sendJSON({cmd: "nowSpeaking", user: wantsToSpeak ? client.user : null});498 }499 }500 return wantsToSpeak;501 }502 return false;503 },504 muteChoir: async (client) => {505 requireConductor(client);506 if (client.room) {507 client.room.speaker = null;508 for (let c of client.room.clients) {509 if (c.peer) {510 await c.peer.getTransceiver(RTCTransceivers.SPEAKER_VIDEO).sender.replaceTrack(null);511 await c.peer.getTransceiver(RTCTransceivers.SPEAKER_AUDIO).sender.replaceTrack(null);512 c.sendJSON({cmd: "nowSpeaking", user: null});513 }514 }515 }516 },517 uploadLyrics: async (client, {projectId, srtText, filename}) => {518 requireConductor(client);519 let path = `.lyrics/${projectId}.${filename}`;520 fs.mkdirSync(".lyrics", {recursive: true});521 fs.writeFileSync(path, srtText);522 let project = await getProject(projectId);523 if (project) {524 project.lyricsUrl = `/${path}`;525 await _saveAndBroadcastProject(client, project);...

Full Screen

Full Screen

core.js

Source:core.js Github

copy

Full Screen

...5 return new Promise((resolve, reject) => {6 s.peer = new Peer();7 s.peer.on("signalingStateChange", state => {8 if (state === "have-remote-offer") {9 s.peer.getTransceiver(RTCTransceivers.MY_VIDEO).direction = "sendonly";10 s.peer.getTransceiver(RTCTransceivers.MY_AUDIO).direction = "sendonly";11 }12 });13 s.peer.on("signal", data => {14 dispatch({15 type: "ws/call",16 fn: "rtcSignal",17 kwargs: { data },18 _log: false,19 });20 });21 s.peer.on("connect", async () => {22 console.log("RTC Connected");23 resolve({24 conductorVideo: s.peer.getTransceiver(RTCTransceivers.CONDUCTOR_VIDEO).receiver.track,25 conductorAudio: s.peer.getTransceiver(RTCTransceivers.CONDUCTOR_AUDIO).receiver.track,26 choirVideo: s.peer.getTransceiver(RTCTransceivers.CHOIR_VIDEO).receiver.track,27 speakerAudio: s.peer.getTransceiver(RTCTransceivers.SPEAKER_AUDIO).receiver.track,28 });29 });30 s.peer._pc.ontrack = (receiver, streams, transceiver) => {31 console.log("RTC Received track", transceiver);32 };33 s.peer.on("data", data => {34 console.log("[RTC Data]", data);35 });36 dispatch({37 type: "ws/call",38 fn: "rtcRequestOffer"39 });40 });41}42export const setMe = async (me) => {43 s.me = me44 if (s.peer) {45 await s.peer.getTransceiver(RTCTransceivers.MY_VIDEO).sender.replaceTrack(me?.getVideoTracks()[0]);46 await s.peer.getTransceiver(RTCTransceivers.MY_AUDIO).sender.replaceTrack(me?.getAudioTracks()[0]);47 }48}49export const signal = (data) => {50 if (s.peer) {51 s.peer.signal(data);52 }53}54export const muteOutput = async () => {55 await s.peer.getTransceiver(RTCTransceivers.MY_AUDIO).sender.replaceTrack(null);56}57export const unmuteOutput = async () => {58 await s.peer.getTransceiver(RTCTransceivers.MY_AUDIO).sender.replaceTrack(s.me?.getAudioTracks()[0]);...

Full Screen

Full Screen

AdminProtocol.mjs

Source:AdminProtocol.mjs Github

copy

Full Screen

1//A specification for the dual protocols we use between client and server2import DPTransceiver, {tID, Protocol, DataInterpreter} from "./../Protocol.mjs"3//Protocols for sending of each (other receives using that protocol)4let srvsend = new Protocol([2, tID.uint8]); //ModuleID, EffectCode5let adminsend = new Protocol([1, tID.uint8]); //6function GetTransceiver(cnxn, recv, send) {7 return new DPTransceiver(cnxn, recv, new DataInterpreter(send));8};9//All of these semantic protocol modules generally come in Client/Server pairs of this form:10export let ServerTransceiver = (cnxn => GetTransceiver(cnxn, adminsend, srvsend));...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful