title: fcm subscribe to topic
body: <p>I'm trying to use FCM to send notifications to all topic subscribers. First of all, I need to subscribe the user to a topic. What I do (I'm using JavaScript Firebase Cloud Messaging for web push notifications):</p>
  
  <p>1) Get FCM instance</p>
  
  <pre><code>var messaging = firebase.messaging();
  </code></pre>
  
  <p>2) Get token</p>
  
  <pre><code>messaging.getToken();
  </code></pre>
  
  <p>3) Send token to server by ajax</p>
  
  <p>4) Subscribe the client to a topic from a server</p>
  
  <pre><code>https://iid.googleapis.com/iid/v1/IID_TOKEN/rel/topics/TOPIC_NAME
  </code></pre>
  
  <p>So, my js code is smth like this:</p>
  
  <pre><code>            var messaging = firebase.messaging();
              messaging.useServiceWorker(reg);
  
              messaging.requestPermission()
                  .then(function () {
                      messaging.getToken()
                          .then(function (currentToken) {
                              if (currentToken) {
                                  $.ajax({
                                      type   : 'POST',
                                      url    : URL_TO_SERVER_METHOD
                                      data   : {
                                          token : currentToken
                                      }
                                  });
  
                              }
                          })
                  })
  </code></pre>
  
  <p>Then, if I make a request to <a href="https://fcm.googleapis.com/fcm/send" rel="nofollow noreferrer">https://fcm.googleapis.com/fcm/send</a> with all necessary parameters, I get a notification in my browser.
  Everything works fine, but I've read from fcm docs that tokens are refreshed sometimes by an fcm app. This means if the token was refreshed, but the user wasn't resubscribed with that new token, he wouldn't get notifications.</p>
  
  <ul>
  <li>Question #1:</li>
  </ul>
  
  <p>How can I be sure my subscribers always get notifications?</p>
  
  <ul>
  <li>Question #2:</li>
  </ul>
  
  <p>I've seen something about the onTokenRefresh method, but will it be called when a browser is closed or computer is turned off (I'm sure, no)? And how can a simulate token refresh action?</p>
  
  <ul>
  <li>Question #3:</li>
  </ul>
  
  <p>I can do subscription only once (next times with the same token aren't needed), but I don't know if my token is old and I have to resubscribe current user. What should I do this case (it's related to previous questions)?</p>