 
 
   unsubscribePubnub: (channel) ->
+
+    return  unless channel
+
     {token} = channel
     channelName = "channel-#{token}"
     @pubnub.unsubscribe({


      return callback err  if err

      realtimeToken = Cookies.get("realtimeToken")

      return callback { message : 'Could not find realtime token'}  unless realtimeToken

        message : (message, env, channel) =>
          return  unless message
          {eventName, body} = message
          # when a user is connected in two browsers, and leaves a channel, in second one
          # they receive RemovedFromChannel event for their own. Therefore we must unsubscribe
          # user from all connected devices.
          if eventName is 'RemovedFromChannel' and body.accountId is KD.whoami().socialApiId
            return @unsubscribePubnub message.channel

          # no need to emit any events when not subscribed
          return  unless @channels[channel]
