Chrome 推送通知。消息识别

Chrome push notifications. Message identification

当我向客户端发送通知时,我有一些数据:

$> curl --header "Authorization: key=$key" --header Content-Type:"application/json" https://gcm-http.googleapis.com/gcm/send -d "{\"registration_ids\":[\"$subs\"]}"    
{"multicast_id":5959734605210485936,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1454898928592704%592683fbf9fd7ecd"}]}

这是 multicast_idmessage_id 参数。

我的问题是:如何从 ServiceWorker 脚本中获取其中一个(或两个)参数?

self.addEventListener('push', function (event) {
  ...
  // I need something like that:
  msgid = event.message_id;
  m_castid = event.multicast_id;
  ...
});

换句话说,我需要任何可能的方法来确定 ServiceWorker 脚本中的消息。

提前致谢,

谨致问候,

尼古拉

已解决!

我不知道如何获取消息 ID,但找到了如何识别您的订阅:

self.addEventListener('push', function (event) {
    ...
    self.registration.pushManager
      .getSubscription()
      .then( function( subscription ) 
    {
        var registrationId = subscription.endpoint.split('/');
        registrationId = registrationId[ registrationId.length - 1 ];
        ...
    });
    ...
});

可能对某些人有用。