PHP Classes

File: sevent.js

Recommend this page to a friend!
  Classes of Mohamed Elbahja   PHP Server Sent Events Library   sevent.js   Download  
File: sevent.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Server Sent Events Library
Send data of server events to the browsers
Author: By
Last change:
Date: 7 years ago
Size: 965 bytes
 

Contents

Class file image Download
/** * Project: Sevent * Description: Server-sent Events jQuery Plugin * Author: Mohamed Elbahja * version: 1.0 */ (function($) { $.sevent = { isSupported: "EventSource" in window, options: { url: false, notSupported: function () { console.error('this browser not supported EventSource'); }, source: false }, init: function(options) { this.options = $.extend({}, this.options, options); if (this.isSupported === false) { this.options.notSupported(); } this.options.source = new EventSource(this.options.url); }, on: function(event, func) { this.options.source.addEventListener(event, func, false); }, json: function(response) { try { response = $.parseJSON(response.data); } catch (e) { response = false; } return response; }, exit: function() { this.options.source.close(); } }; }(jQuery));