Presentation.receiver - Web APIs 编辑

The read-only Presentation attribute receiver, which is only available in browser contexts which are receiving a presentation, returns the PresentationReceiver object which can be used to access and communicate with the browser context which controls the presentation. This property is always null when accessed from outside a browser context which is receiving a presentation.

Syntax

receiver = Presentation.receiver;

receiver = navigator.presentation.receiver;

Since the Presentation interface is typically accessed through navigation.presentation, the second form of the syntax shown above is the more commonly used.

Value

If the code is running in a context which is receiving a presentation, the returned value is a PresentationReceiver which can then be used to communicate with the context which is the source of the presentation.

If the current context is not receiving a presentation, receiver is null.

Example

Determining whether or not the context is receiving a presentation

You can easily determine whether or not the context is the receiver for a presentation by checking the value of navigator.receiver. If it's a non-null value, then the context is indeed receiving a presentation. If it's null, there's no incoming presentation.

if (navigator.receiver) {
  footer.innerHTML = "Receiving presentation";
}  else {
  footer.innerHTML = "(idle)";
}

Accessing the connection list

This example uses receiver to access the list of incoming connections and to build and display a list of those connections' ID strings.

let listElem = document.getElementById("connectionview");

navigator.presentation.receiver.connectionList
          .then(function(connections) {
    connections.forEach(function(aConnection)) {
      listElem.innerHTML += "<li>" + aConnection.id
            + "</li>";
    });
});

After getting access to the output list element in the variable connectionView, navigator.receiver is used to get a reference to the PresentationReceiver object for this context, and its connectionList is used to get a Promise which will be called when the list is available.

The promise handler receives as its input parameter an array of the incoming connections. We iterate over these using forEach(), appending a new item to the connectionView list element for each connection.

Specifications

SpecificationStatusComment
Presentation API
The definition of 'receiver' in that specification.
Candidate Recommendation 

Browser Compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:61 次

字数:5562

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文