Add availableMediaTypes bitmask to receiver selector open method

This commit is contained in:
hensm
2019-07-09 10:56:55 +01:00
parent 43fcd5b351
commit 70e05566fa
14 changed files with 100 additions and 29 deletions

View File

@@ -22,6 +22,21 @@ let peerConnection: RTCPeerConnection;
let drawWindowIntervalId: number;
let availableMediaTypes =
ReceiverSelectorMediaType.Screen
| ReceiverSelectorMediaType.Tab;
/**
* Remove "Screen" option when on an insecure origin as
* MediaDevices.getDisplayMedia will not exist (and legacy
* MediaDevices.getUserMedia mediaSource constraint will
* fail).
*/
if (typeof navigator.mediaDevices.getDisplayMedia === "undefined") {
availableMediaTypes &= ~ReceiverSelectorMediaType.Screen;
}
/**
* Sends a message to the fx_cast app running on the
* receiver device.
@@ -70,7 +85,6 @@ async function onRequestSessionSuccess (
switch (newSelectedMedia) {
case ReceiverSelectorMediaType.Tab: {
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
@@ -118,7 +132,6 @@ async function onRequestSessionSuccess (
}
case ReceiverSelectorMediaType.Screen: {
const stream = await navigator.mediaDevices.getDisplayMedia({
video: { cursor: "motion" }
, audio: false
@@ -142,8 +155,11 @@ async function onRequestSessionSuccess (
function receiverListener (availability: string) {
cast.logMessage("receiverListener");
if (!wasSessionRequested
&& availability === cast.ReceiverAvailability.AVAILABLE) {
if (wasSessionRequested) {
return;
}
if (availability === cast.ReceiverAvailability.AVAILABLE) {
wasSessionRequested = true;
cast.requestSession(
onRequestSessionSuccess
@@ -181,7 +197,8 @@ init().then(async bridgeInfo => {
, sessionListener
, receiverListener
, undefined, undefined
, selectedMedia);
, selectedMedia
, availableMediaTypes);
cast.initialize(apiConfig
, onInitializeSuccess