<commit_before>define [ 'INST', 'jquery' ], (INST, $) ->

  class Client
    constructor: ->
      @faye = null
      @tokens = {}

    # Is truthy if PandaPub is enabled.
    #
    enabled:
      INST.pandaPubSettings

    # Subscribe to a channel with a token. Returns an object
    # which can receive a .cancel() call in order to unsubscribe.
    # That object is also a Deferred, to find out when the subscription
    # is successful or failed.
    #
    subscribe: (channel, token, cb) =>
      fullChannel = "/#{INST.pandaPubSettings.application_id}#{channel}"

      @tokens[fullChannel] = token

      dfd = new $.Deferred
      dfd.cancel = ->

      @client (faye) =>
        subscription = faye.subscribe fullChannel, (message) ->
          cb(message)

        subscription.then dfd.resolve, dfd.reject
        dfd.cancel = ->
          subscription.cancel()

      dfd


    # Subscribe to transport-level events, transport:down or
    # transport:up. See http://faye.jcoglan.com/browser/transport.html

    on: (event, cb) =>
      @client (faye) =>
        faye.on(event, cb)


    # @api private

    authExtension: =>
      outgoing: (message, cb) =>
        if message.channel == '/meta/subscribe'
          if message.subscription of @tokens
            message.ext ||= {}
            message.ext.auth =
              token: @tokens[message.subscription]

        cb(message)

    # Creates or returns the internal Faye client, loading it first
    # if necessary.
    #
    # @api private

    client: (cb) ->
      if @faye then cb(@faye)

      unless @faye
        require [ INST.pandaPubSettings.push_url + '/client.js' ], =>
          @faye = new window.Faye.Client INST.pandaPubSettings.push_url
          @faye.addExtension @authExtension()<commit_msg>Fix PandaPub to work with webpack<commit_after>define [ 'INST', 'jquery' ], (INST, $) ->

  class Client
    constructor: ->
      @faye = null
      @tokens = {}

    # Is truthy if PandaPub is enabled.
    #
    enabled:
      INST.pandaPubSettings

    # Subscribe to a channel with a token. Returns an object
    # which can receive a .cancel() call in order to unsubscribe.
    # That object is also a Deferred, to find out when the subscription
    # is successful or failed.
    #
    subscribe: (channel, token, cb) =>
      fullChannel = "/#{INST.pandaPubSettings.application_id}#{channel}"

      @tokens[fullChannel] = token

      dfd = new $.Deferred
      dfd.cancel = ->

      @client (faye) =>
        subscription = faye.subscribe fullChannel, (message) ->
          cb(message)

        subscription.then dfd.resolve, dfd.reject
        dfd.cancel = ->
          subscription.cancel()

      dfd


    # Subscribe to transport-level events, transport:down or
    # transport:up. See http://faye.jcoglan.com/browser/transport.html

    on: (event, cb) =>
      @client (faye) =>
        faye.on(event, cb)


    # @api private

    authExtension: =>
      outgoing: (message, cb) =>
        if message.channel == '/meta/subscribe'
          if message.subscription of @tokens
            message.ext ||= {}
            message.ext.auth =
              token: @tokens[message.subscription]

        cb(message)

    # Creates or returns the internal Faye client, loading it first
    # if necessary.
    #
    # @api private

    client: (cb) ->
      if @faye then cb(@faye)

      unless @faye
        $.getScript INST.pandaPubSettings.push_url + '/client.js', =>
          @faye = new window.Faye.Client INST.pandaPubSettings.push_url
          @faye.addExtension @authExtension()
{'fraction_non_alphanumeric': 0.11396648044692738, 'fraction_numerical': 0.0, 'mean_word_length': 2.1662245800176834, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3930995', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1056, 'n_words': 292}