     @webPushTokenRegistrationUrl = "#{@options.endPoint}/api/push-subscriptions/#{@options.channelId}"
 
   subscribe: ->
-    @initializeFirebase()
-    @getToken()
+    @initialize() unless @messaging
+    @getTokenAndSubscribe()
 
-  initializeFirebase: () ->
+  initialize: () ->
     config =
       apiKey: @options.firebaseApiKey
       messagingSenderId: @options.firebaseMessagingSenderId
-    firebase.initializeApp config
+    if !firebase.apps.length
+      firebase.initializeApp config
     @messaging = firebase.messaging()
 
     @messaging.onMessage (payload) =>

        @options.onErrorRetrievingRefreshedToken()

  getToken: () ->
    @messaging.getToken().then((currentToken) =>
      if currentToken
        @sendTokenToServer currentToken

          @options.onPermissionFailed()

        setTokenSentToServer(false)
    ).catch (err) ->
      console.log 'An error occurred while retrieving token. ', err
      setTokenSentToServer(false)
