HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall_new/buyercall/buyercall/assets/scripts/faye.js
var faye = function () {
    // Add format method to strings.
    String.prototype.format = function () {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function (match, number) {
            return typeof args[number] != 'undefined'
                ? args[number]
                : match
                ;
        });
    };

    var fayeScriptSelector = '#faye';
    var broadcastSelector = '#broadcast';
    var $broadcast = $(broadcastSelector);
    var $emptyStream = $('#empty_stream');
    var channel = '/cats';
    var maxItems = 10;
    var itemSelector = 'div';
    var fayeURL = $(fayeScriptSelector).data('faye-public-url');
    var tweetTemplate = $('#tweetTemplate').html();

    // Avoid duplicate clients and subscriptions.
    if (typeof window.fayeClient === 'undefined') {
        window.fayeClient = new Faye.Client(fayeURL);
    }
    if (window.fayeSubscription) {
        window.fayeSubscription.unsubscribe();
    }

    window.fayeSubscription = window.fayeClient.subscribe(channel, function (message) {
        $emptyStream.hide();

        var template = tweetTemplate.format(message.user,
            message.type,
            message.tweet);
        $broadcast.prepend(template);

        if ($(broadcastSelector + ' > ' + itemSelector).length > maxItems) {
            $(broadcastSelector + ' ' + itemSelector + ':last').remove();
        }
    });
};

module.exports = faye;