Last active
March 25, 2018 20:29
-
-
Save piroor/5185096 to your computer and use it in GitHub Desktop.
Wrapper of socket.io-client for Sencha Touch/ExtJS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Usage: | |
| * var socket = Ext.create('MyApp.data.SocketIO', { | |
| * host: 'localhost', | |
| * port: 80 | |
| * }); | |
| * | |
| * License: The MIT License | |
| * Copyright (c) 2013 ClearCode Inc. / YUKI "Piro" Hiroshi | |
| */ | |
| Ext.define('MyApp.data.SocketIO', { | |
| constructor: function(config){ | |
| var me = this; | |
| me.superclass.constructor.call(me); | |
| me.self._sockets = me.self._sockets || {}; | |
| var key = config.host + ':' + config.port; | |
| if (!me.self._sockets[key]) { | |
| me.self._sockets[key] = me.connect(config); | |
| } | |
| me._socket = me.self._sockets[key]; | |
| }, | |
| connect: function(config) { | |
| return io.connect(config.host, { | |
| port: config.port, | |
| path: config.path, | |
| reconnection: config.reconnection, | |
| reconnectionAttempts: config.reconnectionAttempts, | |
| reconnectionDelay: config.reconnectionDelay, | |
| reconnectionDelayMax: config.reconnectionDelayMax, | |
| timeout: config.timeout | |
| }); | |
| }, | |
| on: function() { | |
| return this._socket.on.apply(this._socket, arguments); | |
| }, | |
| removeListener: function() { | |
| return this._socket.removeListener.apply(this._socket, arguments); | |
| }, | |
| removeAllListener: function() { | |
| return this._socket.removeAllListener.apply(this._socket, arguments); | |
| }, | |
| emit: function() { | |
| return this._socket.emit.apply(this._socket, arguments); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment