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