如何从基于 Web 的发件人上的 Google Cast Receiver 接收消息?
How to receive a message from a Google Cast Receiver on a web-based sender?
我正在尝试从 Chromecast(接收方)向其附加的网络应用程序(发送方)发送消息。 The documentation 暗示这很简单:
const i = cast.framework.CastReceiverContext.getInstance();
i.sendCustomMessage('url:x-cast:com.example.app', undefined, 'my data');
但是,我找不到任何关于如何在 Web 应用程序端实际接收此消息的文档。我只能找到这个:
Similarly, receiver applications can keep senders informed about the state of the receiver by sending messages to connected senders. A receiver application can send messages using sendCustomMessage(namespace, senderId, message) on CastReceiverContext. A receiver can send messages to an individual sender, either in response to a received message or due to an application state change. Beyond point-to-point messaging (with a limit of 64kb), a receiver may also broadcast messages to all connected senders.
来源:https://developers.google.com/cast/docs/caf_receiver/core_features
我在寻找什么 API 来实际从基于网络的 "sender" 上接收来自 "receiver" 的消息?
我发现我需要的是会话:
session.addMessageListener(config.namespace, (namespace, data) => {
});
只是为了贡献:我使用这种机制通过自定义名称空间将日志消息从接收方发送到发送方,以避免必须在接收方上打开远程 Web 检查器进行调试。
我正在尝试从 Chromecast(接收方)向其附加的网络应用程序(发送方)发送消息。 The documentation 暗示这很简单:
const i = cast.framework.CastReceiverContext.getInstance();
i.sendCustomMessage('url:x-cast:com.example.app', undefined, 'my data');
但是,我找不到任何关于如何在 Web 应用程序端实际接收此消息的文档。我只能找到这个:
Similarly, receiver applications can keep senders informed about the state of the receiver by sending messages to connected senders. A receiver application can send messages using sendCustomMessage(namespace, senderId, message) on CastReceiverContext. A receiver can send messages to an individual sender, either in response to a received message or due to an application state change. Beyond point-to-point messaging (with a limit of 64kb), a receiver may also broadcast messages to all connected senders.
来源:https://developers.google.com/cast/docs/caf_receiver/core_features
我在寻找什么 API 来实际从基于网络的 "sender" 上接收来自 "receiver" 的消息?
我发现我需要的是会话:
session.addMessageListener(config.namespace, (namespace, data) => {
});
只是为了贡献:我使用这种机制通过自定义名称空间将日志消息从接收方发送到发送方,以避免必须在接收方上打开远程 Web 检查器进行调试。