Chrome推送通知。消息识别

时间:2016-02-08 03:10:02

标签: javascript google-chrome notifications push

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

$> 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_id message_id 参数。

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

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

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

提前致谢,

最诚挚的问候,

尼古拉

1 个答案:

答案 0 :(得分:0)

解决!

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

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

可能会对某人有用。

相关问题