-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
907aed6
commit dd5dd64
Showing
15 changed files
with
727 additions
and
804 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,120 @@ | ||
import { Counter, peer, sleep, waitVideoPlay } from "../fixture"; | ||
|
||
describe("combination_all_media", () => { | ||
it( | ||
"combination_all_media_answer", | ||
async () => | ||
new Promise<void>(async (done) => { | ||
const label = "combination_all_media_answer"; | ||
it("combination_all_media_answer", async () => | ||
new Promise<void>(async (done) => { | ||
const label = "combination_all_media_answer"; | ||
|
||
const counter = new Counter(3, () => { | ||
pc.close(); | ||
done(); | ||
}); | ||
const counter = new Counter(3, () => { | ||
pc.close(); | ||
done(); | ||
}); | ||
|
||
if (!peer.connected) await new Promise<void>((r) => peer.on("open", r)); | ||
await sleep(100); | ||
if (!peer.connected) await new Promise<void>((r) => peer.on("open", r)); | ||
await sleep(100); | ||
|
||
const pc = new RTCPeerConnection({ | ||
iceServers: [{ urls: "stun:stun.l.google.com:19302" }], | ||
}); | ||
pc.ontrack = async ({ track }) => { | ||
await waitVideoPlay(track); | ||
counter.done(); | ||
const pc = new RTCPeerConnection({ | ||
iceServers: [{ urls: "stun:stun.l.google.com:19302" }], | ||
}); | ||
pc.ontrack = async ({ track }) => { | ||
await waitVideoPlay(track); | ||
counter.done(); | ||
}; | ||
pc.ondatachannel = ({ channel }) => { | ||
channel.onopen = () => { | ||
channel.send("ping"); | ||
}; | ||
pc.ondatachannel = ({ channel }) => { | ||
channel.onopen = () => { | ||
channel.send("ping"); | ||
}; | ||
channel.onmessage = (e) => { | ||
if (e.data === "pong") { | ||
counter.done(); | ||
} | ||
}; | ||
channel.onmessage = (e) => { | ||
if (e.data === "pong") { | ||
counter.done(); | ||
} | ||
}; | ||
}; | ||
|
||
{ | ||
const [track] = ( | ||
await navigator.mediaDevices.getUserMedia({ video: true }) | ||
).getTracks(); | ||
pc.addTrack(track); | ||
} | ||
{ | ||
const [track] = ( | ||
await navigator.mediaDevices.getUserMedia({ video: true }) | ||
).getTracks(); | ||
pc.addTrack(track); | ||
} | ||
|
||
const offer = await peer.request(label, { | ||
type: "init", | ||
}); | ||
await pc.setRemoteDescription(offer); | ||
await pc.setLocalDescription(await pc.createAnswer()); | ||
{ | ||
const [track] = ( | ||
await navigator.mediaDevices.getUserMedia({ video: true }) | ||
).getTracks(); | ||
pc.addTrack(track); | ||
} | ||
{ | ||
const [track] = ( | ||
await navigator.mediaDevices.getUserMedia({ video: true }) | ||
).getTracks(); | ||
pc.addTrack(track); | ||
} | ||
|
||
pc.onicecandidate = ({ candidate }) => { | ||
peer | ||
.request(label, { | ||
type: "candidate", | ||
payload: candidate, | ||
}) | ||
.catch(() => {}); | ||
}; | ||
const offer = await peer.request(label, { | ||
type: "init", | ||
}); | ||
await pc.setRemoteDescription(offer); | ||
await pc.setLocalDescription(await pc.createAnswer()); | ||
|
||
pc.onicecandidate = ({ candidate }) => { | ||
peer | ||
.request(label, { | ||
type: "answer", | ||
payload: pc.localDescription, | ||
type: "candidate", | ||
payload: candidate, | ||
}) | ||
.catch(() => {}); | ||
}), | ||
10 * 1000, | ||
); | ||
}; | ||
|
||
it( | ||
"combination_all_media_offer", | ||
async () => | ||
new Promise<void>(async (done) => { | ||
const label = "combination_all_media_offer"; | ||
peer | ||
.request(label, { | ||
type: "answer", | ||
payload: pc.localDescription, | ||
}) | ||
.catch(() => {}); | ||
})); | ||
|
||
const counter = new Counter(2, () => { | ||
pc.close(); | ||
done(); | ||
}); | ||
it("combination_all_media_offer", async () => | ||
new Promise<void>(async (done) => { | ||
const label = "combination_all_media_offer"; | ||
|
||
if (!peer.connected) await new Promise<void>((r) => peer.on("open", r)); | ||
await sleep(100); | ||
const counter = new Counter(2, () => { | ||
pc.close(); | ||
done(); | ||
}); | ||
|
||
const pc = new RTCPeerConnection({ | ||
iceServers: [{ urls: "stun:stun.l.google.com:19302" }], | ||
}); | ||
pc.ontrack = async ({ track }) => { | ||
await waitVideoPlay(track); | ||
counter.done(); | ||
}; | ||
if (!peer.connected) await new Promise<void>((r) => peer.on("open", r)); | ||
await sleep(100); | ||
|
||
const channel = pc.createDataChannel("dc"); | ||
channel.onopen = () => { | ||
channel.send("ping"); | ||
}; | ||
channel.onmessage = (e) => { | ||
if (e.data === "pong") { | ||
counter.done(); | ||
} | ||
}; | ||
const pc = new RTCPeerConnection({ | ||
iceServers: [{ urls: "stun:stun.l.google.com:19302" }], | ||
}); | ||
pc.ontrack = async ({ track }) => { | ||
await waitVideoPlay(track); | ||
counter.done(); | ||
}; | ||
|
||
const [track] = ( | ||
await navigator.mediaDevices.getUserMedia({ video: true }) | ||
).getTracks(); | ||
pc.addTrack(track); | ||
pc.onicecandidate = ({ candidate }) => { | ||
peer | ||
.request(label, { | ||
type: "candidate", | ||
payload: candidate, | ||
}) | ||
.catch(() => {}); | ||
}; | ||
const channel = pc.createDataChannel("dc"); | ||
channel.onopen = () => { | ||
channel.send("ping"); | ||
}; | ||
channel.onmessage = (e) => { | ||
if (e.data === "pong") { | ||
counter.done(); | ||
} | ||
}; | ||
|
||
await pc.setLocalDescription(await pc.createOffer()); | ||
const answer = await peer.request(label, { | ||
type: "init", | ||
payload: pc.localDescription, | ||
}); | ||
await pc.setRemoteDescription(answer); | ||
}), | ||
10 * 1000, | ||
); | ||
const [track] = ( | ||
await navigator.mediaDevices.getUserMedia({ video: true }) | ||
).getTracks(); | ||
pc.addTrack(track); | ||
pc.onicecandidate = ({ candidate }) => { | ||
peer | ||
.request(label, { | ||
type: "candidate", | ||
payload: candidate, | ||
}) | ||
.catch(() => {}); | ||
}; | ||
|
||
await pc.setLocalDescription(await pc.createOffer()); | ||
const answer = await peer.request(label, { | ||
type: "init", | ||
payload: pc.localDescription, | ||
}); | ||
await pc.setRemoteDescription(answer); | ||
})); | ||
}); |
Oops, something went wrong.