| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/de/docs/Web/API/Presentation_API | [Back] [Original] |
Get to know MDN better
Dieser Inhalt wurde automatisch aus dem Englischen bersetzt, und kann Fehler enthalten. Erfahre mehr ber dieses Experiment.
Diese Funktion ist nicht Baseline, da sie in einigen der am weitesten verbreiteten Browser nicht funktioniert.
Want more browser support for this feature? Tell us why.
Sicherer Kontext: Diese Funktion ist nur in sicheren Kontexten (HTTPS) in einigen oder allen untersttzenden Browsern verfgbar.
Experimentell: Dies ist eine experimentelle Technologie
berprfen Sie die Browser-Kompatibilittstabelle sorgfltig vor der Verwendung auf produktiven Webseiten.
Die Presentation API ermglicht einem user agent (wie etwa einem Webbrowser) Webinhalte effektiv auf groen Prsentationsgerten wie Projektoren und netzwerkverbundenen Fernsehern anzuzeigen. Untersttzte Arten von Multimedia-Gerten umfassen sowohl Displays, die ber HDMI, DVI oder hnliche Kabel verbunden sind, als auch kabellose Verbindungen wie DLNA, Chromecast, AirPlay oder Miracast.
Im Allgemeinen verwendet eine Webseite die Presentation Controller API, um die Webinhalte anzugeben, die auf einem Prsentationsgert gerendert werden sollen, und um die Prsentationssitzung zu starten. Mit der Presentation Receiver API erhlt der prsentierende Webinhalt den Sitzungsstatus. Durch die Bereitstellung eines nachrichtenbasierten Kanals sowohl fr die Controller-Seite als auch die Empfngerseite kann ein Webentwickler die Interaktion zwischen diesen beiden Seiten implementieren.
Abhngig vom Verbindungsmechanismus, der vom Prsentationsgert bereitgestellt wird, knnen Controller- und Empfngerseite durch denselben oder durch separate Nutzeragenten gerendert werden.
PresentationIn einem steuernden Browsing-Kontext bietet die Presentation-Schnittstelle einen Mechanismus, um das Standardverhalten des Browsers beim Start einer Prsentation auf einem externen Bildschirm zu berschreiben. In einem empfangenden Browsing-Kontext bietet die Presentation-Schnittstelle Zugriff auf die verfgbaren Prsentationsverbindungen.
PresentationRequestInitiiert oder verbindet sich erneut mit einer Prsentation, die von einem steuernden Browsing-Kontext erstellt wurde.
PresentationAvailabilityEin PresentationAvailability-Objekt ist mit verfgbaren Prsentationsanzeigen verbunden und reprsentiert die Verfgbarkeit von Prsentationsanzeigen fr eine Prsentationsanfrage.
PresentationConnectionAvailableEventDas PresentationConnectionAvailableEvent wird bei einer PresentationRequest ausgelst, wenn eine Verbindung, die mit dem Objekt assoziiert ist, erstellt wird.
PresentationConnectionJede Prsentationsverbindung wird durch ein PresentationConnection-Objekt dargestellt.
PresentationConnectionCloseEventEin PresentationConnectionCloseEvent wird ausgelst, wenn eine Prsentationsverbindung in den closed-Zustand bergeht.
PresentationReceiverDer PresentationReceiver ermglicht einem empfangenden Browsing-Kontext, auf die steuernden Browsing-Kontexte zuzugreifen und mit ihnen zu kommunizieren.
PresentationConnectionListPresentationConnectionList reprsentiert die Sammlung von nicht beendeten Prsentationsverbindungen und berwacht das Ereignis neuer verfgbarer Prsentationsverbindungen.
Die folgenden Beispielcodes veranschaulichen die Verwendung der Hauptfunktionen der Presentation API: controller.html implementiert den Controller und presentation.html die Prsentation. Beide Seiten werden von der Domain https://example.org bereitgestellt (https://example.org/controller.html und https://example.org/presentation.html). Diese Beispiele setzen voraus, dass die steuernde Seite jeweils eine Prsentation verwaltet. Bitte sehen Sie sich die Kommentare in den Codebeispielen fr weitere Details an.
In controller.html:
<button id="presentBtn" class="hidden">Present</button>
.hidden {
display: none;
}
// The Present button is visible if at least one presentation display is available
const presentBtn = document.getElementById("presentBtn");
// It is also possible to use relative presentation URL e.g. "presentation.html"
const presUrls = [
"https://example.com/presentation.html",
"https://example.net/alternate.html",
];
// Show or hide present button depending on display availability
const handleAvailabilityChange = (available) => {
if (available) {
presentBtn.classList.remove("hidden");
} else {
presentBtn.classList.add("hidden");
}
};
// Promise is resolved as soon as the presentation display availability is known.
const request = new PresentationRequest(presUrls);
request
.getAvailability()
.then((availability) => {
// availability.value may be kept up-to-date by the controlling UA as long
// as the availability object is alive. It is advised for the web developers
// to discard the object as soon as it's not needed.
handleAvailabilityChange(availability.value);
availability.onchange = () => {
handleAvailabilityChange(availability.value);
};
})
.catch(() => {
// Availability monitoring is not supported by the platform, so discovery of
// presentation displays will happen only after request.start() is called.
// Pretend the devices are available for simplicity; or, one could implement
// a third state for the button.
handleAvailabilityChange(true);
});
In controller.html:
presentBtn.onclick = () => {
// Start new presentation.
request
.start()
// The connection to the presentation will be passed to setConnection on success.
.then(setConnection);
// Otherwise, the user canceled the selection dialog or no screens were found.
};
In der Datei controller.html:
<button id="reconnectBtn" class="hidden">Reconnect</button>
const reconnect = () => {
const presId = localStorage.getItem("presId");
// presId is mandatory when reconnecting to a presentation.
if (presId) {
request
.reconnect(presId)
// The new connection to the presentation will be passed to
// setConnection on success.
.then(setConnection);
// No connection found for presUrl and presId, or an error occurred.
}
};
// On navigation of the controller, reconnect automatically.
reconnect();
// Or allow manual reconnection.
reconnectBtn.onclick = reconnect;
In der Datei controller.html:
navigator.presentation.defaultRequest = new PresentationRequest(presUrls);
navigator.presentation.defaultRequest.onconnectionavailable = (evt) => {
setConnection(evt.connection);
};
Das Setzen von presentation.defaultRequest ermglicht es der Seite, den PresentationRequest anzugeben, der verwendet werden soll, wenn das steuernde UA eine Prsentation initiiert.
In controller.html:
<button id="disconnectBtn" class="hidden">Disconnect</button>
<button id="stopBtn" class="hidden">Stop</button>
<button id="reconnectBtn" class="hidden">Reconnect</button>
let connection;
// The Disconnect and Stop buttons are visible if there is a connected presentation
const stopBtn = document.querySelector("#stopBtn");
const reconnectBtn = document.querySelector("#reconnectBtn");
const disconnectBtn = document.querySelector("#disconnectBtn");
stopBtn.onclick = () => {
connection?.terminate();
};
disconnectBtn.onclick = () => {
connection?.close();
};
function setConnection(newConnection) {
// Disconnect from existing presentation, if not attempting to reconnect
if (
connection &&
connection !== newConnection &&
connection.state !== "closed"
) {
connection.onclose = undefined;
connection.close();
}
// Set the new connection and save the presentation ID
connection = newConnection;
localStorage.setItem("presId", connection.id);
function showConnectedUI() {
// Allow the user to disconnect from or terminate the presentation
stopBtn.classList.remove("hidden");
disconnectBtn.classList.remove("hidden");
reconnectBtn.classList.add("hidden");
}
function showDisconnectedUI() {
disconnectBtn.classList.add("hidden");
stopBtn.classList.add("hidden");
if (localStorage.getItem("presId")) {
// If there is a presId in localStorage, allow the user to reconnect
reconnectBtn.classList.remove("hidden");
} else {
reconnectBtn.classList.add("hidden");
}
}
// Monitor the connection state
connection.onconnect = () => {
showConnectedUI();
// Register message handler
connection.onmessage = (message) => {
console.log(`Received message: ${message.data}`);
};
// Send initial message to presentation page
connection.send("Say hello");
};
connection.onclose = () => {
connection = null;
showDisconnectedUI();
};
connection.onterminate = () => {
localStorage.removeItem("presId");
connection = null;
showDisconnectedUI();
};
}
In presentation.html:
const addConnection = (connection) => {
connection.onmessage = (message) => {
if (message.data === "Say hello") connection.send("hello");
};
};
navigator.presentation.receiver.connectionList.then((list) => {
list.connections.forEach((connection) => {
addConnection(connection);
});
list.onconnectionavailable = (evt) => {
addConnection(evt.connection);
};
});
In der Datei controller.html:
connection.send('{"string": "!", "lang": "zh-CN"}');
connection.send('{"string": "!", "lang": "ja"}');
connection.send('{"string": ", !", "lang": "ko"}');
connection.send('{"string": "Hello, world!", "lang": "en-US"}');
In der Datei presentation.html:
connection.onmessage = (message) => {
const messageObj = JSON.parse(message.data);
const spanElt = document.createElement("SPAN");
spanElt.lang = messageObj.lang;
spanElt.textContent = messageObj.string;
document.body.appendChild(spanElt);
};
| Spezifikation |
|---|
| Presentation API # interface-presentation |
Presentation API polyfill enthlt ein JavaScript-Polyfill der Presentation API Spezifikation, die im Rahmen der Second Screen Working Group bei W3C standardisiert wird. Das Polyfill ist hauptschlich dafr gedacht, zu erforschen, wie die Presentation API auf verschiedenen Prsentationsmechanismen umgesetzt werden kann.
Der Bauplan fr ein besseres Internet.
Teile dieses Inhalts sind 19982026 von einzelnen mozilla.org-Mitwirkenden. Inhalte sind verfgbar unter einer Creative-Commons-Lizenz.
| Web Proxy Viewer | New URL | Original Page |