ports
只读特性在
ExtendableMessageEvent
interface returns the array containing the
MessagePort
objects representing the ports of the associated message channel (the channel the message is being sent through.)
var myPorts = extendableMessageEvent.ports;
An array of
MessagePort
对象。
When the following code is used inside a service worker to respond to a push messages by sending the data received via
PushMessageData
to the main context via a
channel message
, the event object of
onmessage
将是
ExtendableMessageEvent
.
var port;
self.addEventListener('push', function(e) {
var obj = e.data.json();
if(obj.action === 'subscribe' || obj.action === 'unsubscribe') {
port.postMessage(obj);
} else if(obj.action === 'init' || obj.action === 'chatMsg') {
port.postMessage(obj);
}
});
self.onmessage = function(e) {
port = e.ports[0];
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
服务工作者
The definition of 'ExtendableMessageEvent.ports' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ports
|
Chrome ? | Edge ? |
Firefox
45
注意事项
|
IE 不支持 No | Opera ? | Safari 不支持 No | WebView Android 不支持 No | Chrome Android ? | Firefox Android 45 | Opera Android ? | Safari iOS 不支持 No | Samsung Internet Android ? |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
见实现注意事项。
ExtendableMessageEvent
data
lastEventId
origin
ports
source
缓存
CacheStorage
Client
Clients
ExtendableEvent
FetchEvent
InstallEvent
Navigator.serviceWorker
NotificationEvent
PeriodicSyncEvent
PeriodicSyncManager
PeriodicSyncRegistration
ServiceWorker
ServiceWorkerContainer
ServiceWorkerGlobalScope
ServiceWorkerRegistration
SyncEvent
SyncManager
SyncRegistration
WindowClient