Presentation:receiver 屬性
只讀的 Presentation 屬性 receiver,僅在接收演示的瀏覽器上下文中可用,它返回 PresentationReceiver 物件,該物件可用於訪問和與控制演示的瀏覽器上下文進行通訊。當從不接收演示的瀏覽器上下文外部訪問此屬性時,它始終為 null。
值
如果程式碼在接收演示的上下文中執行,則返回值為 PresentationReceiver,然後可用於與演示源所在的上下文進行通訊。
如果當前上下文未接收演示,則 receiver 為 null。
示例
確定上下文是否正在接收演示
透過檢查 navigator.presentation.receiver 的值,可以輕鬆確定上下文是否是演示的接收方。如果它的值不是 null,那麼上下文確實正在接收演示。如果它是 null,則沒有傳入的演示。
js
footer.textContent = navigator.presentation.receiver
? "Receiving presentation"
: "(idle)";
訪問連線列表
此示例使用 receiver 訪問傳入連線的列表,並構建並顯示這些連線的 ID 字串列表。
js
const listElem = document.getElementById("connection-view");
navigator.presentation.receiver.connectionList.then((connections) => {
connections.forEach((connection) => {
listElem.appendChild(document.createElement("li")).textContent =
connection.id;
});
});
在變數 connectionView 中獲取對輸出列表元素的訪問許可權後,navigator.presentation.receiver 用於獲取此上下文的 PresentationReceiver 物件的引用,並使用其 connectionList 來獲取一個 Promise,該 Promise 將在列表可用時被呼叫。
Promise 處理程式接收一個傳入連線的陣列作為其輸入引數。我們使用 forEach() 遍歷這些連線,為每個連線向 connectionView 列表元素追加一個新項。
規範
| 規範 |
|---|
| Presentation API # dom-presentation-receiver |
瀏覽器相容性
載入中…
另見
- Presentation API
PresentationPresentationReceiver