<commit_before>'use strict';

/**
 * @namespace Jii
 * @ignore
 */
var Jii = require('jii');

var SockJS = require('sockjs-client');

/**
 * @class Jii.comet.client.transport.Sockjs
 * @extends Jii.comet.client.transport.TransportInterface
 */
Jii.defineClass('Jii.comet.client.transport.Sockjs', /** @lends Jii.comet.client.transport.Sockjs.prototype */{

	__extends: Jii.comet.client.transport.TransportInterface,

    transports: null,

	/**
	 * @type {SockJS}
	 */
	_websocket: null,

	/**
	 * Open connection
	 * @param {string} url
	 */
	open: function(url) {
		this._websocket = new SockJS(url, null, {
			//debug: HelpOnClick.debug,
            transports: this.transports
		});

		this._websocket.onopen = this._onOpen.bind(this);
		this._websocket.onmessage = this._onMessage.bind(this);
		this._websocket.onclose = this._onClose.bind(this);
	},

	/**
	 * Close connection
	 */
	close: function() {
		if (this._websocket) {
			this._websocket.close();
			this._websocket = null;
		}
	},<commit_msg>fix sockjs global bug (when Jii used in node-webkit)<commit_after>'use strict';

/**
 * @namespace Jii
 * @ignore
 */
var Jii = require('jii');

// sockjs global fix: sockjs expect that global object is equal window, but it is not always, for example in node-webkit
if (typeof global !== 'undefined' && typeof window !== 'undefined' && global !== window) {
    var usedWindowKeys = ['document', 'location', 'XMLHttpRequest', 'EventSource', 'WebSocket', 'MozWebSocket',
        'XDomainRequest', 'crypto', 'navigator', 'chrome', 'addEventListener', 'attachEvent',
        'removeEventListener', 'detachEvent', 'parent', 'postMessage', 'console'];
    Jii._.each(usedWindowKeys, function(key) {
        global[key] = window[key];
    });
}
// @todo jsonp callbacks

var SockJS = require('sockjs-client');

/**
 * @class Jii.comet.client.transport.Sockjs
 * @extends Jii.comet.client.transport.TransportInterface
 */
Jii.defineClass('Jii.comet.client.transport.Sockjs', /** @lends Jii.comet.client.transport.Sockjs.prototype */{

	__extends: Jii.comet.client.transport.TransportInterface,

    /**
     * Available:
     * - websocket
     * - xdr-polling
     * - xdr-streaming
     * - xhr-polling
     * - xhr-streaming
     * - eventsource
     * - htmlfile
     * - iframe
     * - jsonp-polling
     */
    transports: null,

	/**
	 * @type {SockJS}
	 */
	_websocket: null,

	/**
	 * Open connection
	 * @param {string} url
	 */
	open: function(url) {
		this._websocket = new SockJS(url, null, {
			//debug: HelpOnClick.debug,
            transports: this.transports
		});

		this._websocket.onopen = this._onOpen.bind(this);
		this._websocket.onmessage = this._onMessage.bind(this);
		this._websocket.onclose = this._onClose.bind(this);
	},

	/**
	 * Close connection
	 */
	close: function() {
		if (this._websocket) {
			this._websocket.close();
			this._websocket = null;
		}
	},
{'fraction_non_alphanumeric': 0.16073280331835466, 'fraction_numerical': 0.0, 'mean_word_length': 3.293768545994065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2737620', 'n_tokens_mistral': 1047, 'n_tokens_neox': 966, 'n_words': 185}