PageRenderTime 36ms queryFilters 41ms Sphinxql 93ms app.CodeModel.GetByIds 504ms findMatchingLines 201ms GetByIds 705ms meta 0ms repositoryFilters 9ms languageFilters 8ms sourceFilters 2ms

626,242 results for 'socket repo:JeevRobinson/tortoisegit' (36 ms)

Source

Language

Repository

clisp.lisp https://bitbucket.org/hwo2014/hwo2014-team-876.git | Lisp | 700 lines
169         (with-mapped-conditions (socket)
170           (socket:socket-accept (socket socket)
171                                 :element-type (or element-type
188     (remove-waiter (wait-list usocket) usocket))
189  (socket:socket-server-close (socket usocket)))
190
211  (dotted-quad-to-vector-quad
212   (socket:socket-server-host (socket usocket))))
213
220(defmethod get-local-port ((usocket stream-server-usocket))
221  (socket:socket-server-port (socket usocket)))
222
556				      remote-port)
557    (let ((sock (%socket +socket-af-inet+ +socket-sock-dgram+ +socket-ip-proto-udp+))
558	  (lsock_addr (fill-sockaddr_in (ffi:allocate-shallow 'sockaddr_in)
socket.c https://github.com/midos0/Energia.git | C | 1,173 lines
128		
129		if(SOCKET_STATUS_ACTIVE != get_socket_active_status(sd))
130			return -1;
355//!          addr is addrlen bytes long. Traditionally, this is called when a 
356//!          socket is created with socket, it exists in a name space (address 
357//!          family) but has no name assigned.
510//!  @brief  initiate a connection on a socket 
511//!          Function connects the socket referred to by the socket descriptor 
512//!          sd, to the address specified by addr. The addrlen argument 
518//!          If the socket is of type SOCK_STREAM, this call attempts to make a 
519//!          connection to another socket. The other socket is specified  by 
520//!          address, which is an address in the communications space of the
942//!                 function receives a message from a connection-mode or
943//!                 connectionless-mode socket. Note that raw sockets are not
944//!                 supported.
socket.io.js https://github.com/svlsummerjam/Arduino-angular-socketio-phonegap-app.git | JavaScript | 6,066 lines
1544
1545Socket.Socket = Socket;
1546Socket.Transport = require('./transport');
1608  var transport;
1609  if (this.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf('websocket') != -1) {
1610    transport = 'websocket';
1683        self.emit('upgrading', transport);
1684        Socket.priorWebsocketSuccess = 'websocket' == transport.name;
1685
1756  this.readyState = 'open';
1757  Socket.priorWebsocketSuccess = 'websocket' == this.transport.name;
1758  this.emit('open');
4404
4405var WebSocket = global.WebSocket || global.MozWebSocket;
4406
GCDAsyncSocket.h https://github.com/ipmcc/CocoaHTTPServer.git | C++ Header | 1,084 lines
808 * Here's how you would accomplish something like that:
809 * - (dispatch_queue_t)newSocketQueueForConnectionFromAddress:(NSData *)address onSocket:(GCDAsyncSocket *)sock
810 * {
818 * }
819 * - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket
820 * {
965 * This method is called immediately prior to socket:didAcceptNewSocket:.
966 * It optionally allows a listening socket to specify the socketQueue for a new accepted socket.
967 * If this method is not implemented, or returns NULL, the new accepted socket will create its own default queue.
981**/
982- (dispatch_queue_t)newSocketQueueForConnectionFromAddress:(NSData *)address onSocket:(GCDAsyncSocket *)sock;
983
993**/
994- (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket;
995
socket.io.js https://github.com/narcisoguillen/socket.io.git | JavaScript | 1,326 lines
187        request(srv)
188        .get('/socket.io/socket.io.js')
189        .end(function(err, res){
364          sio.of('/news', function(socket){
365            expect(socket).to.be.a(Socket);
366            --total || done();
1186  describe('middleware', function(done){
1187    var Socket = require('../lib/socket');
1188
1193      sio.use(function(socket, next){
1194        expect(socket).to.be.a(Socket);
1195        run++;
1198      sio.use(function(socket, next){
1199        expect(socket).to.be.a(Socket);
1200        run++;
socket.io.js https://github.com/JoshElias/EmberSkeleton.git | JavaScript | 7,591 lines
12    
13    <title>socket.io-client/socket.io.js at master ยท Automattic/socket.io-client</title>
14    <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub" />
22      <meta content="@github" name="twitter:site" /><meta content="summary" name="twitter:card" /><meta content="Automattic/socket.io-client" name="twitter:title" /><meta content="socket.io-client - Realtime application framework (client)" name="twitter:description" /><meta content="https://avatars2.githubusercontent.com/u/887802?s=400" name="twitter:image:src" />
23<meta content="GitHub" property="og:site_name" /><meta content="object" property="og:type" /><meta content="https://avatars2.githubusercontent.com/u/887802?s=400" property="og:image" /><meta content="Automattic/socket.io-client" property="og:title" /><meta content="https://github.com/Automattic/socket.io-client" property="og:url" /><meta content="socket.io-client - Realtime application framework (client)" property="og:description" />
24
324        <li>
325          <a href="/Automattic/socket.io-client/fork" class="minibutton with-count js-toggler-target fork-button lighter tooltipped-n" title="Fork your own copy of Automattic/socket.io-client to your account" aria-label="Fork your own copy of Automattic/socket.io-client to your account" rel="nofollow" data-method="post">
326            <span class="octicon octicon-repo-forked"></span>
463
464  <a href="github-windows://openRepo/https://github.com/Automattic/socket.io-client" class="minibutton sidebar-button" title="Save Automattic/socket.io-client to your computer and use it in GitHub Desktop." aria-label="Save Automattic/socket.io-client to your computer and use it in GitHub Desktop.">
465    <span class="octicon octicon-device-desktop"></span>
1224  <div class="breadcrumb">
1225    <span class='repo-root js-repo-root'><span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/Automattic/socket.io-client" data-branch="master" data-direction="back" data-pjax="true" itemscope="url"><span itemprop="title">socket.io-client</span></a></span></span><span class="separator"> / </span><strong class="final-path">socket.io.js</strong>
1226  </div>
7503           </td>
7504           <td class="blob-line-code"><div class="code-body highlight"><pre><div class='line' id='LC1'><span class="o">!</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span><span class="s2">&quot;object&quot;</span><span class="o">==</span><span class="k">typeof</span> <span class="nx">exports</span><span class="o">?</span><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span><span class="o">=</span><span class="nx">e</span><span class="p">()</span><span class="o">:</span><span class="s2">&quot;function&quot;</span><span class="o">==</span><span class="k">typeof</span> <span class="nx">define</span><span class="o">&amp;&amp;</span><span class="nx">define</span><span class="p">.</span><span class="nx">amd</span><span class="o">?</span><span class="nx">define</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span><span class="o">:</span><span class="s2">&quot;undefined&quot;</span><span class="o">!=</span><span class="k">typeof</span> <span class="nb">window</span><span class="o">?</span><span class="nb">window</span><span class="p">.</span><span class="nx">io</span><span class="o">=</span><span class="nx">e</span><span class="p">()</span><span class="o">:</span><span class="s2">&quot;undefined&quot;</span><span class="o">!=</span><span class="k">typeof</span> <span class="nx">global</span><span class="o">?</span><span class="nx">global</span><span class="p">.</span><span class="nx">io</span><span class="o">=</span><span class="nx">e</span><span class="p">()</span><span class="o">:</span><span class="s2">&quot;undefined&quot;</span><span class="o">!=</span><span class="k">typeof</span> <span class="nx">self</span><span class="o">&amp;&amp;</span><span class="p">(</span><span class="nx">self</span><span class="p">.</span><span class="nx">io</span><span class="o">=</span><span class="nx">e</span><span class="p">())}(</span><span class="kd">function</span><span class="p">(){</span><span class="kd">var</span> <span class="nx">define</span><span class="p">,</span><span class="nx">module</span><span class="p">,</span><span class="nx">exports</span><span class="p">;</span></div><div class='line' id='LC2'><span class="k">return</span> <span class="p">(</span><span class="kd">function</span> <span class="nx">e</span><span class="p">(</span><span class="nx">t</span><span class="p">,</span><span class="nx">n</span><span class="p">,</span><span class="nx">r</span><span class="p">){</span><span class="kd">function</span> <span class="nx">s</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span><span class="nx">u</span><span class="p">){</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">n</span><span class="p">[</span><span class="nx">o</span><span class="p">]){</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">t</span><span class="p">[</span><span class="nx">o</span><span class="p">]){</span><span class="kd">var</span> <span class="nx">a</span><span class="o">=</span><span class="k">typeof</span> <span class="nx">require</span><span class="o">==</span><span class="s2">&quot;function&quot;</span><span class="o">&amp;&amp;</span><span class="nx">require</span><span class="p">;</span><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">u</span><span class="o">&amp;&amp;</span><span class="nx">a</span><span class="p">)</span><span class="k">return</span> <span class="nx">a</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span><span class="o">!</span><span class="mi">0</span><span class="p">);</span><span class="k">if</span><span class="p">(</span><span class="nx">i</span><span class="p">)</span><span class="k">return</span> <span class="nx">i</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span><span class="o">!</span><span class="mi">0</span><span class="p">);</span><span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;Cannot find module &#39;&quot;</span><span class="o">+</span><span class="nx">o</span><span class="o">+</span><span class="s2">&quot;&#39;&quot;</span><span class="p">)}</span><span class="kd">var</span> <span class="nx">f</span><span class="o">=</span><span class="nx">n</span><span class="p">[</span><span class="nx">o</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="nx">exports</span><span class="o">:</span><span class="p">{}};</span><span class="nx">t</span><span class="p">[</span><span class="nx">o</span><span class="p">][</span><span class="mi">0</span><span class="p">].</span><span class="nx">call</span><span class="p">(</span><span class="nx">f</span><span class="p">.</span><span class="nx">exports</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span><span class="kd">var</span> <span class="nx">n</span><span class="o">=</span><span class="nx">t</span><span class="p">[</span><span class="nx">o</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="nx">e</span><span class="p">];</span><span class="k">return</span> <span class="nx">s</span><span class="p">(</span><span class="nx">n</span><span class="o">?</span><span class="nx">n</span><span class="o">:</span><span class="nx">e</span><span class="p">)},</span><span class="nx">f</span><span class="p">,</span><span class="nx">f</span><span class="p">.</span><span class="nx">exports</span><span class="p">,</span><span class="nx">e</span><span class="p">,</span><span class="nx">t</span><span class="p">,</span><span class="nx">n</span><span class="p">,</span><span class="nx">r</span><span class="p">)}</span><span class="k">return</span> <span class="nx">n</span><span class="p">[</span><span class="nx">o</span><span class="p">].</span><span class="nx">exports</span><span class="p">}</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="k">typeof</span> <span class="nx">require</span><span class="o">==</span><span class="s2">&quot;function&quot;</span><span class="o">&amp;&amp;</span><span class="nx">require</span><span class="p">;</span><span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">o</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="nx">o</span><span class="o">&lt;</span><span class="nx">r</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span><span class="nx">o</span><span class="o">++</span><span class="p">)</span><span class="nx">s</span><span class="p">(</span><span class="nx">r</span><span class="p">[</span><span class="nx">o</span><span class="p">]);</span><span class="k">return</span> <span class="nx">s</span><span class="p">})({</span><span class="mi">1</span><span class="o">:</span><span class="p">[</span><span class="kd">function</span><span class="p">(</span><span class="nx">require</span><span class="p">,</span><span class="nx">module</span><span class="p">,</span><span class="nx">exports</span><span class="p">){</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./lib/&#39;</span><span class="p">);</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'><span class="p">},{</span><span class="s2">&quot;./lib/&quot;</span><span class="o">:</span><span class="mi">2</span><span class="p">}],</span><span class="mi">2</span><span class="o">:</span><span class="p">[</span><span class="kd">function</span><span class="p">(</span><span class="nx">require</span><span class="p">,</span><span class="nx">module</span><span class="p">,</span><span class="nx">exports</span><span class="p">){</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'><span class="cm">/**</span></div><div class='line' id='LC9'><span class="cm"> * Module dependencies.</span></div><div class='line' id='LC10'><span class="cm"> */</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'><span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./url&#39;</span><span class="p">);</span></div><div class='line' id='LC13'><span class="kd">var</span> <span class="nx">parser</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;socket.io-parser&#39;</span><span class="p">);</span></div><div class='line' id='LC14'><span class="kd">var</span> <span class="nx">Manager</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./manager&#39;</span><span class="p">);</span></div><div class='line' id='LC15'><span class="kd">var</span> <span class="nx">debug</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;debug&#39;</span><span class="p">)(</span><span class="s1">&#39;socket.io-client&#39;</span><span class="p">);</span></div><div class='line' id='LC16'><br/></div><div class='line' id='LC17'><span class="cm">/**</span></div><div class='line' id='LC18'><span class="cm"> * Module exports.</span></div><div class='line' id='LC19'><span class="cm"> */</span></div><div class='line' id='LC20'><br/></div><div class='line' id='LC21'><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">exports</span> <span class="o">=</span> <span class="nx">lookup</span><span class="p">;</span></div><div class='line' id='LC22'><br/></div><div class='line' id='LC23'><span class="cm">/**</span></div><div class='line' id='LC24'><span class="cm"> * Managers cache.</span></div><div class='line' id='LC25'><span class="cm"> */</span></div><div class='line' id='LC26'><br/></div><div class='line' id='LC27'><span class="kd">var</span> <span class="nx">cache</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">managers</span> <span class="o">=</span> <span class="p">{};</span></div><div class='line' id='LC28'><br/></div><div class='line' id='LC29'><span class="cm">/**</span></div><div class='line' id='LC30'><span class="cm"> * Looks up an existing `Manager` for multiplexing.</span></div><div class='line' id='LC31'><span class="cm"> * If the user summons:</span></div><div class='line' id='LC32'><span class="cm"> *</span></div><div class='line' id='LC33'><span class="cm"> *   `io(&#39;http://localhost/a&#39;);`</span></div><div class='line' id='LC34'><span class="cm"> *   `io(&#39;http://localhost/b&#39;);`</span></div><div class='line' id='LC35'><span class="cm"> *</span></div><div class='line' id='LC36'><span class="cm"> * We reuse the existing instance based on same scheme/port/host,</span></div><div class='line' id='LC37'><span class="cm"> * and we initialize sockets for each namespace.</span></div><div class='line' id='LC38'><span class="cm"> *</span></div><div class='line' id='LC39'><span class="cm"> * @api public</span></div><div class='line' id='LC40'><span class="cm"> */</span></div><div class='line' id='LC41'><br/></div><div class='line' id='LC42'><span class="kd">function</span> <span class="nx">lookup</span><span class="p">(</span><span class="nx">uri</span><span class="p">,</span> <span class="nx">opts</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC43'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">uri</span> <span class="o">==</span> <span class="s1">&#39;object&#39;</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC44'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">opts</span> <span class="o">=</span> <span class="nx">uri</span><span class="p">;</span></div><div class='line' id='LC45'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">uri</span> <span class="o">=</span> <span class="kc">undefined</span><span class="p">;</span></div><div class='line' id='LC46'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC47'><br/></div><div class='line' id='LC48'>&nbsp;&nbsp;<span class="nx">opts</span> <span class="o">=</span> <span class="nx">opts</span> <span class="o">||</span> <span class="p">{};</span></div><div class='line' id='LC49'><br/></div><div class='line' id='LC50'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">parsed</span> <span class="o">=</span> <span class="nx">url</span><span class="p">(</span><span class="nx">uri</span><span class="p">);</span></div><div class='line' id='LC51'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">source</span> <span class="o">=</span> <span class="nx">parsed</span><span class="p">.</span><span class="nx">source</span><span class="p">;</span></div><div class='line' id='LC52'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="nx">parsed</span><span class="p">.</span><span class="nx">id</span><span class="p">;</span></div><div class='line' id='LC53'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">io</span><span class="p">;</span></div><div class='line' id='LC54'><br/></div><div class='line' id='LC55'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">opts</span><span class="p">.</span><span class="nx">forceNew</span> <span class="o">||</span> <span class="nx">opts</span><span class="p">[</span><span class="s1">&#39;force new connection&#39;</span><span class="p">]</span> <span class="o">||</span> <span class="kc">false</span> <span class="o">===</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">multiplex</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC56'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;ignoring socket cache for %s&#39;</span><span class="p">,</span> <span class="nx">source</span><span class="p">);</span></div><div class='line' id='LC57'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">io</span> <span class="o">=</span> <span class="nx">Manager</span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">opts</span><span class="p">);</span></div><div class='line' id='LC58'>&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC59'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">cache</span><span class="p">[</span><span class="nx">id</span><span class="p">])</span> <span class="p">{</span></div><div class='line' id='LC60'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;new io instance for %s&#39;</span><span class="p">,</span> <span class="nx">source</span><span class="p">);</span></div><div class='line' id='LC61'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">cache</span><span class="p">[</span><span class="nx">id</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Manager</span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">opts</span><span class="p">);</span></div><div class='line' id='LC62'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC63'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">io</span> <span class="o">=</span> <span class="nx">cache</span><span class="p">[</span><span class="nx">id</span><span class="p">];</span></div><div class='line' id='LC64'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC65'><br/></div><div class='line' id='LC66'>&nbsp;&nbsp;<span class="k">return</span> <span class="nx">io</span><span class="p">.</span><span class="nx">socket</span><span class="p">(</span><span class="nx">parsed</span><span class="p">.</span><span class="nx">path</span><span class="p">);</span></div><div class='line' id='LC67'><span class="p">}</span></div><div class='line' id='LC68'><br/></div><div class='line' id='LC69'><span class="cm">/**</span></div><div class='line' id='LC70'><span class="cm"> * Protocol version.</span></div><div class='line' id='LC71'><span class="cm"> *</span></div><div class='line' id='LC72'><span class="cm"> * @api public</span></div><div class='line' id='LC73'><span class="cm"> */</span></div><div class='line' id='LC74'><br/></div><div class='line' id='LC75'><span class="nx">exports</span><span class="p">.</span><span class="nx">protocol</span> <span class="o">=</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">protocol</span><span class="p">;</span></div><div class='line' id='LC76'><br/></div><div class='line' id='LC77'><span class="cm">/**</span></div><div class='line' id='LC78'><span class="cm"> * `connect`.</span></div><div class='line' id='LC79'><span class="cm"> *</span></div><div class='line' id='LC80'><span class="cm"> * @param {String} uri</span></div><div class='line' id='LC81'><span class="cm"> * @api public</span></div><div class='line' id='LC82'><span class="cm"> */</span></div><div class='line' id='LC83'><br/></div><div class='line' id='LC84'><span class="nx">exports</span><span class="p">.</span><span class="nx">connect</span> <span class="o">=</span> <span class="nx">lookup</span><span class="p">;</span></div><div class='line' id='LC85'><br/></div><div class='line' id='LC86'><span class="cm">/**</span></div><div class='line' id='LC87'><span class="cm"> * Expose constructors for standalone build.</span></div><div class='line' id='LC88'><span class="cm"> *</span></div><div class='line' id='LC89'><span class="cm"> * @api public</span></div><div class='line' id='LC90'><span class="cm"> */</span></div><div class='line' id='LC91'><br/></div><div class='line' id='LC92'><span class="nx">exports</span><span class="p">.</span><span class="nx">Manager</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./manager&#39;</span><span class="p">);</span></div><div class='line' id='LC93'><span class="nx">exports</span><span class="p">.</span><span class="nx">Socket</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./socket&#39;</span><span class="p">);</span></div><div class='line' id='LC94'><br/></div><div class='line' id='LC95'><span class="p">},{</span><span class="s2">&quot;./manager&quot;</span><span class="o">:</span><span class="mi">3</span><span class="p">,</span><span class="s2">&quot;./socket&quot;</span><span class="o">:</span><span class="mi">5</span><span class="p">,</span><span class="s2">&quot;./url&quot;</span><span class="o">:</span><span class="mi">6</span><span class="p">,</span><span class="s2">&quot;debug&quot;</span><span class="o">:</span><span class="mi">9</span><span class="p">,</span><span class="s2">&quot;socket.io-parser&quot;</span><span class="o">:</span><span class="mi">40</span><span class="p">}],</span><span class="mi">3</span><span class="o">:</span><span class="p">[</span><span class="kd">function</span><span class="p">(</span><span class="nx">require</span><span class="p">,</span><span class="nx">module</span><span class="p">,</span><span class="nx">exports</span><span class="p">){</span></div><div class='line' id='LC96'><br/></div><div class='line' id='LC97'><span class="cm">/**</span></div><div class='line' id='LC98'><span class="cm"> * Module dependencies.</span></div><div class='line' id='LC99'><span class="cm"> */</span></div><div class='line' id='LC100'><br/></div><div class='line' id='LC101'><span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./url&#39;</span><span class="p">);</span></div><div class='line' id='LC102'><span class="kd">var</span> <span class="nx">eio</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;engine.io-client&#39;</span><span class="p">);</span></div><div class='line' id='LC103'><span class="kd">var</span> <span class="nx">Socket</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./socket&#39;</span><span class="p">);</span></div><div class='line' id='LC104'><span class="kd">var</span> <span class="nx">Emitter</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;component-emitter&#39;</span><span class="p">);</span></div><div class='line' id='LC105'><span class="kd">var</span> <span class="nx">parser</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;socket.io-parser&#39;</span><span class="p">);</span></div><div class='line' id='LC106'><span class="kd">var</span> <span class="nx">on</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./on&#39;</span><span class="p">);</span></div><div class='line' id='LC107'><span class="kd">var</span> <span class="nx">bind</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;component-bind&#39;</span><span class="p">);</span></div><div class='line' id='LC108'><span class="kd">var</span> <span class="nx">object</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;object-component&#39;</span><span class="p">);</span></div><div class='line' id='LC109'><span class="kd">var</span> <span class="nx">debug</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;debug&#39;</span><span class="p">)(</span><span class="s1">&#39;socket.io-client:manager&#39;</span><span class="p">);</span></div><div class='line' id='LC110'><br/></div><div class='line' id='LC111'><span class="cm">/**</span></div><div class='line' id='LC112'><span class="cm"> * Module exports</span></div><div class='line' id='LC113'><span class="cm"> */</span></div><div class='line' id='LC114'><br/></div><div class='line' id='LC115'><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">Manager</span><span class="p">;</span></div><div class='line' id='LC116'><br/></div><div class='line' id='LC117'><span class="cm">/**</span></div><div class='line' id='LC118'><span class="cm"> * `Manager` constructor.</span></div><div class='line' id='LC119'><span class="cm"> *</span></div><div class='line' id='LC120'><span class="cm"> * @param {String} engine instance or engine uri/opts</span></div><div class='line' id='LC121'><span class="cm"> * @param {Object} options</span></div><div class='line' id='LC122'><span class="cm"> * @api public</span></div><div class='line' id='LC123'><span class="cm"> */</span></div><div class='line' id='LC124'><br/></div><div class='line' id='LC125'><span class="kd">function</span> <span class="nx">Manager</span><span class="p">(</span><span class="nx">uri</span><span class="p">,</span> <span class="nx">opts</span><span class="p">){</span></div><div class='line' id='LC126'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="p">(</span><span class="k">this</span> <span class="k">instanceof</span> <span class="nx">Manager</span><span class="p">))</span> <span class="k">return</span> <span class="k">new</span> <span class="nx">Manager</span><span class="p">(</span><span class="nx">uri</span><span class="p">,</span> <span class="nx">opts</span><span class="p">);</span></div><div class='line' id='LC127'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">uri</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="s1">&#39;object&#39;</span> <span class="o">==</span> <span class="k">typeof</span> <span class="nx">uri</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC128'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">opts</span> <span class="o">=</span> <span class="nx">uri</span><span class="p">;</span></div><div class='line' id='LC129'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">uri</span> <span class="o">=</span> <span class="kc">undefined</span><span class="p">;</span></div><div class='line' id='LC130'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC131'>&nbsp;&nbsp;<span class="nx">opts</span> <span class="o">=</span> <span class="nx">opts</span> <span class="o">||</span> <span class="p">{};</span></div><div class='line' id='LC132'><br/></div><div class='line' id='LC133'>&nbsp;&nbsp;<span class="nx">opts</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">path</span> <span class="o">||</span> <span class="s1">&#39;/socket.io&#39;</span><span class="p">;</span></div><div class='line' id='LC134'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">nsps</span> <span class="o">=</span> <span class="p">{};</span></div><div class='line' id='LC135'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC136'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">opts</span> <span class="o">=</span> <span class="nx">opts</span><span class="p">;</span></div><div class='line' id='LC137'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">reconnection</span><span class="p">(</span><span class="nx">opts</span><span class="p">.</span><span class="nx">reconnection</span> <span class="o">!==</span> <span class="kc">false</span><span class="p">);</span></div><div class='line' id='LC138'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">reconnectionAttempts</span><span class="p">(</span><span class="nx">opts</span><span class="p">.</span><span class="nx">reconnectionAttempts</span> <span class="o">||</span> <span class="kc">Infinity</span><span class="p">);</span></div><div class='line' id='LC139'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">reconnectionDelay</span><span class="p">(</span><span class="nx">opts</span><span class="p">.</span><span class="nx">reconnectionDelay</span> <span class="o">||</span> <span class="mi">1000</span><span class="p">);</span></div><div class='line' id='LC140'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">reconnectionDelayMax</span><span class="p">(</span><span class="nx">opts</span><span class="p">.</span><span class="nx">reconnectionDelayMax</span> <span class="o">||</span> <span class="mi">5000</span><span class="p">);</span></div><div class='line' id='LC141'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">timeout</span><span class="p">(</span><span class="kc">null</span> <span class="o">==</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">timeout</span> <span class="o">?</span> <span class="mi">20000</span> <span class="o">:</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">timeout</span><span class="p">);</span></div><div class='line' id='LC142'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">readyState</span> <span class="o">=</span> <span class="s1">&#39;closed&#39;</span><span class="p">;</span></div><div class='line' id='LC143'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">uri</span> <span class="o">=</span> <span class="nx">uri</span><span class="p">;</span></div><div class='line' id='LC144'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">connected</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></div><div class='line' id='LC145'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">attempts</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></div><div class='line' id='LC146'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">encoding</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC147'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">packetBuffer</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC148'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">encoder</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">Encoder</span><span class="p">();</span></div><div class='line' id='LC149'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">decoder</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">Decoder</span><span class="p">();</span></div><div class='line' id='LC150'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">open</span><span class="p">();</span></div><div class='line' id='LC151'><span class="p">}</span></div><div class='line' id='LC152'><br/></div><div class='line' id='LC153'><span class="cm">/**</span></div><div class='line' id='LC154'><span class="cm"> * Propagate given event to sockets and emit on `this`</span></div><div class='line' id='LC155'><span class="cm"> *</span></div><div class='line' id='LC156'><span class="cm"> * @api private</span></div><div class='line' id='LC157'><span class="cm"> */</span></div><div class='line' id='LC158'><br/></div><div class='line' id='LC159'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">emitAll</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC160'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emit</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span></div><div class='line' id='LC161'>&nbsp;&nbsp;<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">nsp</span> <span class="k">in</span> <span class="k">this</span><span class="p">.</span><span class="nx">nsps</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC162'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">nsps</span><span class="p">[</span><span class="nx">nsp</span><span class="p">].</span><span class="nx">emit</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">nsps</span><span class="p">[</span><span class="nx">nsp</span><span class="p">],</span> <span class="nx">arguments</span><span class="p">);</span></div><div class='line' id='LC163'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC164'><span class="p">};</span></div><div class='line' id='LC165'><br/></div><div class='line' id='LC166'><span class="cm">/**</span></div><div class='line' id='LC167'><span class="cm"> * Mix in `Emitter`.</span></div><div class='line' id='LC168'><span class="cm"> */</span></div><div class='line' id='LC169'><br/></div><div class='line' id='LC170'><span class="nx">Emitter</span><span class="p">(</span><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">);</span></div><div class='line' id='LC171'><br/></div><div class='line' id='LC172'><span class="cm">/**</span></div><div class='line' id='LC173'><span class="cm"> * Sets the `reconnection` config.</span></div><div class='line' id='LC174'><span class="cm"> *</span></div><div class='line' id='LC175'><span class="cm"> * @param {Boolean} true/false if it should automatically reconnect</span></div><div class='line' id='LC176'><span class="cm"> * @return {Manager} self or value</span></div><div class='line' id='LC177'><span class="cm"> * @api public</span></div><div class='line' id='LC178'><span class="cm"> */</span></div><div class='line' id='LC179'><br/></div><div class='line' id='LC180'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">reconnection</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">v</span><span class="p">){</span></div><div class='line' id='LC181'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_reconnection</span><span class="p">;</span></div><div class='line' id='LC182'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">_reconnection</span> <span class="o">=</span> <span class="o">!!</span><span class="nx">v</span><span class="p">;</span></div><div class='line' id='LC183'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC184'><span class="p">};</span></div><div class='line' id='LC185'><br/></div><div class='line' id='LC186'><span class="cm">/**</span></div><div class='line' id='LC187'><span class="cm"> * Sets the reconnection attempts config.</span></div><div class='line' id='LC188'><span class="cm"> *</span></div><div class='line' id='LC189'><span class="cm"> * @param {Number} max reconnection attempts before giving up</span></div><div class='line' id='LC190'><span class="cm"> * @return {Manager} self or value</span></div><div class='line' id='LC191'><span class="cm"> * @api public</span></div><div class='line' id='LC192'><span class="cm"> */</span></div><div class='line' id='LC193'><br/></div><div class='line' id='LC194'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">reconnectionAttempts</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">v</span><span class="p">){</span></div><div class='line' id='LC195'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_reconnectionAttempts</span><span class="p">;</span></div><div class='line' id='LC196'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">_reconnectionAttempts</span> <span class="o">=</span> <span class="nx">v</span><span class="p">;</span></div><div class='line' id='LC197'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC198'><span class="p">};</span></div><div class='line' id='LC199'><br/></div><div class='line' id='LC200'><span class="cm">/**</span></div><div class='line' id='LC201'><span class="cm"> * Sets the delay between reconnections.</span></div><div class='line' id='LC202'><span class="cm"> *</span></div><div class='line' id='LC203'><span class="cm"> * @param {Number} delay</span></div><div class='line' id='LC204'><span class="cm"> * @return {Manager} self or value</span></div><div class='line' id='LC205'><span class="cm"> * @api public</span></div><div class='line' id='LC206'><span class="cm"> */</span></div><div class='line' id='LC207'><br/></div><div class='line' id='LC208'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">reconnectionDelay</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">v</span><span class="p">){</span></div><div class='line' id='LC209'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_reconnectionDelay</span><span class="p">;</span></div><div class='line' id='LC210'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">_reconnectionDelay</span> <span class="o">=</span> <span class="nx">v</span><span class="p">;</span></div><div class='line' id='LC211'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC212'><span class="p">};</span></div><div class='line' id='LC213'><br/></div><div class='line' id='LC214'><span class="cm">/**</span></div><div class='line' id='LC215'><span class="cm"> * Sets the maximum delay between reconnections.</span></div><div class='line' id='LC216'><span class="cm"> *</span></div><div class='line' id='LC217'><span class="cm"> * @param {Number} delay</span></div><div class='line' id='LC218'><span class="cm"> * @return {Manager} self or value</span></div><div class='line' id='LC219'><span class="cm"> * @api public</span></div><div class='line' id='LC220'><span class="cm"> */</span></div><div class='line' id='LC221'><br/></div><div class='line' id='LC222'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">reconnectionDelayMax</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">v</span><span class="p">){</span></div><div class='line' id='LC223'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_reconnectionDelayMax</span><span class="p">;</span></div><div class='line' id='LC224'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">_reconnectionDelayMax</span> <span class="o">=</span> <span class="nx">v</span><span class="p">;</span></div><div class='line' id='LC225'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC226'><span class="p">};</span></div><div class='line' id='LC227'><br/></div><div class='line' id='LC228'><span class="cm">/**</span></div><div class='line' id='LC229'><span class="cm"> * Sets the connection timeout. `false` to disable</span></div><div class='line' id='LC230'><span class="cm"> *</span></div><div class='line' id='LC231'><span class="cm"> * @return {Manager} self or value</span></div><div class='line' id='LC232'><span class="cm"> * @api public</span></div><div class='line' id='LC233'><span class="cm"> */</span></div><div class='line' id='LC234'><br/></div><div class='line' id='LC235'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">timeout</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">v</span><span class="p">){</span></div><div class='line' id='LC236'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_timeout</span><span class="p">;</span></div><div class='line' id='LC237'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">_timeout</span> <span class="o">=</span> <span class="nx">v</span><span class="p">;</span></div><div class='line' id='LC238'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC239'><span class="p">};</span></div><div class='line' id='LC240'><br/></div><div class='line' id='LC241'><span class="cm">/**</span></div><div class='line' id='LC242'><span class="cm"> * Starts trying to reconnect if reconnection is enabled and we have not</span></div><div class='line' id='LC243'><span class="cm"> * started reconnecting yet</span></div><div class='line' id='LC244'><span class="cm"> *</span></div><div class='line' id='LC245'><span class="cm"> * @api private</span></div><div class='line' id='LC246'><span class="cm"> */</span></div><div class='line' id='LC247'><br/></div><div class='line' id='LC248'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">maybeReconnectOnOpen</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC249'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">openReconnect</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">reconnecting</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="p">.</span><span class="nx">_reconnection</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC250'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// keeps reconnection from firing twice for the same reconnection loop</span></div><div class='line' id='LC251'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">openReconnect</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC252'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">reconnect</span><span class="p">();</span></div><div class='line' id='LC253'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC254'><span class="p">};</span></div><div class='line' id='LC255'><br/></div><div class='line' id='LC256'><br/></div><div class='line' id='LC257'><span class="cm">/**</span></div><div class='line' id='LC258'><span class="cm"> * Sets the current transport `socket`.</span></div><div class='line' id='LC259'><span class="cm"> *</span></div><div class='line' id='LC260'><span class="cm"> * @param {Function} optional, callback</span></div><div class='line' id='LC261'><span class="cm"> * @return {Manager} self</span></div><div class='line' id='LC262'><span class="cm"> * @api public</span></div><div class='line' id='LC263'><span class="cm"> */</span></div><div class='line' id='LC264'><br/></div><div class='line' id='LC265'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">open</span> <span class="o">=</span></div><div class='line' id='LC266'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">connect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">fn</span><span class="p">){</span></div><div class='line' id='LC267'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;readyState %s&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">readyState</span><span class="p">);</span></div><div class='line' id='LC268'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">~</span><span class="k">this</span><span class="p">.</span><span class="nx">readyState</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">&#39;open&#39;</span><span class="p">))</span> <span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC269'><br/></div><div class='line' id='LC270'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;opening %s&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">uri</span><span class="p">);</span></div><div class='line' id='LC271'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">engine</span> <span class="o">=</span> <span class="nx">eio</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">uri</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">opts</span><span class="p">);</span></div><div class='line' id='LC272'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">socket</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">engine</span><span class="p">;</span></div><div class='line' id='LC273'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC274'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">readyState</span> <span class="o">=</span> <span class="s1">&#39;opening&#39;</span><span class="p">;</span></div><div class='line' id='LC275'><br/></div><div class='line' id='LC276'>&nbsp;&nbsp;<span class="c1">// emit `open`</span></div><div class='line' id='LC277'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">openSub</span> <span class="o">=</span> <span class="nx">on</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC278'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">onopen</span><span class="p">();</span></div><div class='line' id='LC279'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">fn</span> <span class="o">&amp;&amp;</span> <span class="nx">fn</span><span class="p">();</span></div><div class='line' id='LC280'>&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC281'><br/></div><div class='line' id='LC282'>&nbsp;&nbsp;<span class="c1">// emit `connect_error`</span></div><div class='line' id='LC283'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">errorSub</span> <span class="o">=</span> <span class="nx">on</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">){</span></div><div class='line' id='LC284'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;connect_error&#39;</span><span class="p">);</span></div><div class='line' id='LC285'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">cleanup</span><span class="p">();</span></div><div class='line' id='LC286'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">readyState</span> <span class="o">=</span> <span class="s1">&#39;closed&#39;</span><span class="p">;</span></div><div class='line' id='LC287'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">emitAll</span><span class="p">(</span><span class="s1">&#39;connect_error&#39;</span><span class="p">,</span> <span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC288'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">fn</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC289'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">err</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;Connection error&#39;</span><span class="p">);</span></div><div class='line' id='LC290'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">err</span><span class="p">.</span><span class="nx">data</span> <span class="o">=</span> <span class="nx">data</span><span class="p">;</span></div><div class='line' id='LC291'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">fn</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span></div><div class='line' id='LC292'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC293'><br/></div><div class='line' id='LC294'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">maybeReconnectOnOpen</span><span class="p">();</span></div><div class='line' id='LC295'>&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC296'><br/></div><div class='line' id='LC297'>&nbsp;&nbsp;<span class="c1">// emit `connect_timeout`</span></div><div class='line' id='LC298'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="kc">false</span> <span class="o">!==</span> <span class="k">this</span><span class="p">.</span><span class="nx">_timeout</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC299'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">timeout</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_timeout</span><span class="p">;</span></div><div class='line' id='LC300'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;connect attempt will timeout after %d&#39;</span><span class="p">,</span> <span class="nx">timeout</span><span class="p">);</span></div><div class='line' id='LC301'><br/></div><div class='line' id='LC302'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// set timer</span></div><div class='line' id='LC303'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">timer</span> <span class="o">=</span> <span class="nx">setTimeout</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC304'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;connect attempt timed out after %d&#39;</span><span class="p">,</span> <span class="nx">timeout</span><span class="p">);</span></div><div class='line' id='LC305'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">openSub</span><span class="p">.</span><span class="nx">destroy</span><span class="p">();</span></div><div class='line' id='LC306'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">socket</span><span class="p">.</span><span class="nx">close</span><span class="p">();</span></div><div class='line' id='LC307'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">socket</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="s1">&#39;timeout&#39;</span><span class="p">);</span></div><div class='line' id='LC308'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">emitAll</span><span class="p">(</span><span class="s1">&#39;connect_timeout&#39;</span><span class="p">,</span> <span class="nx">timeout</span><span class="p">);</span></div><div class='line' id='LC309'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">},</span> <span class="nx">timeout</span><span class="p">);</span></div><div class='line' id='LC310'><br/></div><div class='line' id='LC311'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span></div><div class='line' id='LC312'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">destroy</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC313'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">clearTimeout</span><span class="p">(</span><span class="nx">timer</span><span class="p">);</span></div><div class='line' id='LC314'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC315'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC316'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC317'><br/></div><div class='line' id='LC318'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">openSub</span><span class="p">);</span></div><div class='line' id='LC319'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">errorSub</span><span class="p">);</span></div><div class='line' id='LC320'><br/></div><div class='line' id='LC321'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC322'><span class="p">};</span></div><div class='line' id='LC323'><br/></div><div class='line' id='LC324'><span class="cm">/**</span></div><div class='line' id='LC325'><span class="cm"> * Called upon transport open.</span></div><div class='line' id='LC326'><span class="cm"> *</span></div><div class='line' id='LC327'><span class="cm"> * @api private</span></div><div class='line' id='LC328'><span class="cm"> */</span></div><div class='line' id='LC329'><br/></div><div class='line' id='LC330'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onopen</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC331'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;open&#39;</span><span class="p">);</span></div><div class='line' id='LC332'><br/></div><div class='line' id='LC333'>&nbsp;&nbsp;<span class="c1">// clear old subs</span></div><div class='line' id='LC334'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">cleanup</span><span class="p">();</span></div><div class='line' id='LC335'><br/></div><div class='line' id='LC336'>&nbsp;&nbsp;<span class="c1">// mark as open</span></div><div class='line' id='LC337'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">readyState</span> <span class="o">=</span> <span class="s1">&#39;open&#39;</span><span class="p">;</span></div><div class='line' id='LC338'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;open&#39;</span><span class="p">);</span></div><div class='line' id='LC339'><br/></div><div class='line' id='LC340'>&nbsp;&nbsp;<span class="c1">// add new subs</span></div><div class='line' id='LC341'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">socket</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">engine</span><span class="p">;</span></div><div class='line' id='LC342'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">on</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;ondata&#39;</span><span class="p">)));</span></div><div class='line' id='LC343'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">on</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">decoder</span><span class="p">,</span> <span class="s1">&#39;decoded&#39;</span><span class="p">,</span> <span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;ondecoded&#39;</span><span class="p">)));</span></div><div class='line' id='LC344'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">on</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;onerror&#39;</span><span class="p">)));</span></div><div class='line' id='LC345'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">on</span><span class="p">(</span><span class="nx">socket</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;onclose&#39;</span><span class="p">)));</span></div><div class='line' id='LC346'><span class="p">};</span></div><div class='line' id='LC347'><br/></div><div class='line' id='LC348'><span class="cm">/**</span></div><div class='line' id='LC349'><span class="cm"> * Called with data.</span></div><div class='line' id='LC350'><span class="cm"> *</span></div><div class='line' id='LC351'><span class="cm"> * @api private</span></div><div class='line' id='LC352'><span class="cm"> */</span></div><div class='line' id='LC353'><br/></div><div class='line' id='LC354'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">ondata</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">){</span></div><div class='line' id='LC355'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">decoder</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC356'><span class="p">};</span></div><div class='line' id='LC357'><br/></div><div class='line' id='LC358'><span class="cm">/**</span></div><div class='line' id='LC359'><span class="cm"> * Called when parser fully decodes a packet.</span></div><div class='line' id='LC360'><span class="cm"> *</span></div><div class='line' id='LC361'><span class="cm"> * @api private</span></div><div class='line' id='LC362'><span class="cm"> */</span></div><div class='line' id='LC363'><br/></div><div class='line' id='LC364'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">ondecoded</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">packet</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC365'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;packet&#39;</span><span class="p">,</span> <span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC366'><span class="p">};</span></div><div class='line' id='LC367'><br/></div><div class='line' id='LC368'><span class="cm">/**</span></div><div class='line' id='LC369'><span class="cm"> * Called upon socket error.</span></div><div class='line' id='LC370'><span class="cm"> *</span></div><div class='line' id='LC371'><span class="cm"> * @api private</span></div><div class='line' id='LC372'><span class="cm"> */</span></div><div class='line' id='LC373'><br/></div><div class='line' id='LC374'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onerror</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">){</span></div><div class='line' id='LC375'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nx">err</span><span class="p">);</span></div><div class='line' id='LC376'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emitAll</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nx">err</span><span class="p">);</span></div><div class='line' id='LC377'><span class="p">};</span></div><div class='line' id='LC378'><br/></div><div class='line' id='LC379'><span class="cm">/**</span></div><div class='line' id='LC380'><span class="cm"> * Creates a new socket for the given `nsp`.</span></div><div class='line' id='LC381'><span class="cm"> *</span></div><div class='line' id='LC382'><span class="cm"> * @return {Socket}</span></div><div class='line' id='LC383'><span class="cm"> * @api public</span></div><div class='line' id='LC384'><span class="cm"> */</span></div><div class='line' id='LC385'><br/></div><div class='line' id='LC386'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">socket</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">nsp</span><span class="p">){</span></div><div class='line' id='LC387'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">socket</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nsps</span><span class="p">[</span><span class="nx">nsp</span><span class="p">];</span></div><div class='line' id='LC388'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">socket</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC389'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">socket</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Socket</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">nsp</span><span class="p">);</span></div><div class='line' id='LC390'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">nsps</span><span class="p">[</span><span class="nx">nsp</span><span class="p">]</span> <span class="o">=</span> <span class="nx">socket</span><span class="p">;</span></div><div class='line' id='LC391'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC392'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">socket</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;connect&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC393'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">connected</span><span class="o">++</span><span class="p">;</span></div><div class='line' id='LC394'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC395'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC396'>&nbsp;&nbsp;<span class="k">return</span> <span class="nx">socket</span><span class="p">;</span></div><div class='line' id='LC397'><span class="p">};</span></div><div class='line' id='LC398'><br/></div><div class='line' id='LC399'><span class="cm">/**</span></div><div class='line' id='LC400'><span class="cm"> * Called upon a socket close.</span></div><div class='line' id='LC401'><span class="cm"> *</span></div><div class='line' id='LC402'><span class="cm"> * @param {Socket} socket</span></div><div class='line' id='LC403'><span class="cm"> */</span></div><div class='line' id='LC404'><br/></div><div class='line' id='LC405'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">destroy</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">socket</span><span class="p">){</span></div><div class='line' id='LC406'>&nbsp;&nbsp;<span class="o">--</span><span class="k">this</span><span class="p">.</span><span class="nx">connected</span> <span class="o">||</span> <span class="k">this</span><span class="p">.</span><span class="nx">close</span><span class="p">();</span></div><div class='line' id='LC407'><span class="p">};</span></div><div class='line' id='LC408'><br/></div><div class='line' id='LC409'><span class="cm">/**</span></div><div class='line' id='LC410'><span class="cm"> * Writes a packet.</span></div><div class='line' id='LC411'><span class="cm"> *</span></div><div class='line' id='LC412'><span class="cm"> * @param {Object} packet</span></div><div class='line' id='LC413'><span class="cm"> * @api private</span></div><div class='line' id='LC414'><span class="cm"> */</span></div><div class='line' id='LC415'><br/></div><div class='line' id='LC416'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">packet</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">packet</span><span class="p">){</span></div><div class='line' id='LC417'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;writing packet %j&#39;</span><span class="p">,</span> <span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC418'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC419'><br/></div><div class='line' id='LC420'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">self</span><span class="p">.</span><span class="nx">encoding</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC421'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// encode, then write to engine with result</span></div><div class='line' id='LC422'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">encoding</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC423'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">encoder</span><span class="p">.</span><span class="nx">encode</span><span class="p">(</span><span class="nx">packet</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">encodedPackets</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC424'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">encodedPackets</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC425'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">engine</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">encodedPackets</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span></div><div class='line' id='LC426'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC427'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">encoding</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC428'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">processPacketQueue</span><span class="p">();</span></div><div class='line' id='LC429'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC430'>&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">// add packet to the queue</span></div><div class='line' id='LC431'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">packetBuffer</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC432'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC433'><span class="p">};</span></div><div class='line' id='LC434'><br/></div><div class='line' id='LC435'><span class="cm">/**</span></div><div class='line' id='LC436'><span class="cm"> * If packet buffer is non-empty, begins encoding the</span></div><div class='line' id='LC437'><span class="cm"> * next packet in line.</span></div><div class='line' id='LC438'><span class="cm"> *</span></div><div class='line' id='LC439'><span class="cm"> * @api private</span></div><div class='line' id='LC440'><span class="cm"> */</span></div><div class='line' id='LC441'><br/></div><div class='line' id='LC442'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">processPacketQueue</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC443'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">packetBuffer</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">encoding</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC444'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">pack</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">packetBuffer</span><span class="p">.</span><span class="nx">shift</span><span class="p">();</span></div><div class='line' id='LC445'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">packet</span><span class="p">(</span><span class="nx">pack</span><span class="p">);</span></div><div class='line' id='LC446'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC447'><span class="p">};</span></div><div class='line' id='LC448'><br/></div><div class='line' id='LC449'><span class="cm">/**</span></div><div class='line' id='LC450'><span class="cm"> * Clean up transport subscriptions and packet buffer.</span></div><div class='line' id='LC451'><span class="cm"> *</span></div><div class='line' id='LC452'><span class="cm"> * @api private</span></div><div class='line' id='LC453'><span class="cm"> */</span></div><div class='line' id='LC454'><br/></div><div class='line' id='LC455'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">cleanup</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC456'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">sub</span><span class="p">;</span></div><div class='line' id='LC457'>&nbsp;&nbsp;<span class="k">while</span> <span class="p">(</span><span class="nx">sub</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">shift</span><span class="p">())</span> <span class="nx">sub</span><span class="p">.</span><span class="nx">destroy</span><span class="p">();</span></div><div class='line' id='LC458'><br/></div><div class='line' id='LC459'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">packetBuffer</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC460'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">encoding</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC461'><br/></div><div class='line' id='LC462'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">decoder</span><span class="p">.</span><span class="nx">destroy</span><span class="p">();</span></div><div class='line' id='LC463'><span class="p">};</span></div><div class='line' id='LC464'><br/></div><div class='line' id='LC465'><span class="cm">/**</span></div><div class='line' id='LC466'><span class="cm"> * Close the current socket.</span></div><div class='line' id='LC467'><span class="cm"> *</span></div><div class='line' id='LC468'><span class="cm"> * @api private</span></div><div class='line' id='LC469'><span class="cm"> */</span></div><div class='line' id='LC470'><br/></div><div class='line' id='LC471'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">close</span> <span class="o">=</span></div><div class='line' id='LC472'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">disconnect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC473'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">skipReconnect</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC474'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">engine</span><span class="p">.</span><span class="nx">close</span><span class="p">();</span></div><div class='line' id='LC475'><span class="p">};</span></div><div class='line' id='LC476'><br/></div><div class='line' id='LC477'><span class="cm">/**</span></div><div class='line' id='LC478'><span class="cm"> * Called upon engine close.</span></div><div class='line' id='LC479'><span class="cm"> *</span></div><div class='line' id='LC480'><span class="cm"> * @api private</span></div><div class='line' id='LC481'><span class="cm"> */</span></div><div class='line' id='LC482'><br/></div><div class='line' id='LC483'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onclose</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">reason</span><span class="p">){</span></div><div class='line' id='LC484'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;close&#39;</span><span class="p">);</span></div><div class='line' id='LC485'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">cleanup</span><span class="p">();</span></div><div class='line' id='LC486'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">readyState</span> <span class="o">=</span> <span class="s1">&#39;closed&#39;</span><span class="p">;</span></div><div class='line' id='LC487'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="nx">reason</span><span class="p">);</span></div><div class='line' id='LC488'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_reconnection</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">skipReconnect</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC489'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">reconnect</span><span class="p">();</span></div><div class='line' id='LC490'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC491'><span class="p">};</span></div><div class='line' id='LC492'><br/></div><div class='line' id='LC493'><span class="cm">/**</span></div><div class='line' id='LC494'><span class="cm"> * Attempt a reconnection.</span></div><div class='line' id='LC495'><span class="cm"> *</span></div><div class='line' id='LC496'><span class="cm"> * @api private</span></div><div class='line' id='LC497'><span class="cm"> */</span></div><div class='line' id='LC498'><br/></div><div class='line' id='LC499'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">reconnect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC500'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">reconnecting</span><span class="p">)</span> <span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC501'><br/></div><div class='line' id='LC502'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC503'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">attempts</span><span class="o">++</span><span class="p">;</span></div><div class='line' id='LC504'><br/></div><div class='line' id='LC505'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">attempts</span> <span class="o">&gt;</span> <span class="k">this</span><span class="p">.</span><span class="nx">_reconnectionAttempts</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC506'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;reconnect failed&#39;</span><span class="p">);</span></div><div class='line' id='LC507'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emitAll</span><span class="p">(</span><span class="s1">&#39;reconnect_failed&#39;</span><span class="p">);</span></div><div class='line' id='LC508'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">reconnecting</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC509'>&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC510'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">delay</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">attempts</span> <span class="o">*</span> <span class="k">this</span><span class="p">.</span><span class="nx">reconnectionDelay</span><span class="p">();</span></div><div class='line' id='LC511'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">delay</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">min</span><span class="p">(</span><span class="nx">delay</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">reconnectionDelayMax</span><span class="p">());</span></div><div class='line' id='LC512'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;will wait %dms before reconnect attempt&#39;</span><span class="p">,</span> <span class="nx">delay</span><span class="p">);</span></div><div class='line' id='LC513'><br/></div><div class='line' id='LC514'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">reconnecting</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC515'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">timer</span> <span class="o">=</span> <span class="nx">setTimeout</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC516'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;attempting reconnect&#39;</span><span class="p">);</span></div><div class='line' id='LC517'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">emitAll</span><span class="p">(</span><span class="s1">&#39;reconnect_attempt&#39;</span><span class="p">,</span> <span class="nx">self</span><span class="p">.</span><span class="nx">attempts</span><span class="p">);</span></div><div class='line' id='LC518'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">emitAll</span><span class="p">(</span><span class="s1">&#39;reconnecting&#39;</span><span class="p">,</span> <span class="nx">self</span><span class="p">.</span><span class="nx">attempts</span><span class="p">);</span></div><div class='line' id='LC519'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">){</span></div><div class='line' id='LC520'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC521'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;reconnect attempt error&#39;</span><span class="p">);</span></div><div class='line' id='LC522'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">reconnecting</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC523'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">reconnect</span><span class="p">();</span></div><div class='line' id='LC524'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">emitAll</span><span class="p">(</span><span class="s1">&#39;reconnect_error&#39;</span><span class="p">,</span> <span class="nx">err</span><span class="p">.</span><span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC525'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC526'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;reconnect success&#39;</span><span class="p">);</span></div><div class='line' id='LC527'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">onreconnect</span><span class="p">();</span></div><div class='line' id='LC528'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC529'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC530'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">},</span> <span class="nx">delay</span><span class="p">);</span></div><div class='line' id='LC531'><br/></div><div class='line' id='LC532'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span></div><div class='line' id='LC533'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">destroy</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC534'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">clearTimeout</span><span class="p">(</span><span class="nx">timer</span><span class="p">);</span></div><div class='line' id='LC535'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC536'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC537'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC538'><span class="p">};</span></div><div class='line' id='LC539'><br/></div><div class='line' id='LC540'><span class="cm">/**</span></div><div class='line' id='LC541'><span class="cm"> * Called upon successful reconnect.</span></div><div class='line' id='LC542'><span class="cm"> *</span></div><div class='line' id='LC543'><span class="cm"> * @api private</span></div><div class='line' id='LC544'><span class="cm"> */</span></div><div class='line' id='LC545'><br/></div><div class='line' id='LC546'><span class="nx">Manager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onreconnect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC547'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">attempt</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">attempts</span><span class="p">;</span></div><div class='line' id='LC548'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">attempts</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></div><div class='line' id='LC549'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">reconnecting</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC550'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emitAll</span><span class="p">(</span><span class="s1">&#39;reconnect&#39;</span><span class="p">,</span> <span class="nx">attempt</span><span class="p">);</span></div><div class='line' id='LC551'><span class="p">};</span></div><div class='line' id='LC552'><br/></div><div class='line' id='LC553'><span class="p">},{</span><span class="s2">&quot;./on&quot;</span><span class="o">:</span><span class="mi">4</span><span class="p">,</span><span class="s2">&quot;./socket&quot;</span><span class="o">:</span><span class="mi">5</span><span class="p">,</span><span class="s2">&quot;./url&quot;</span><span class="o">:</span><span class="mi">6</span><span class="p">,</span><span class="s2">&quot;component-bind&quot;</span><span class="o">:</span><span class="mi">7</span><span class="p">,</span><span class="s2">&quot;component-emitter&quot;</span><span class="o">:</span><span class="mi">8</span><span class="p">,</span><span class="s2">&quot;debug&quot;</span><span class="o">:</span><span class="mi">9</span><span class="p">,</span><span class="s2">&quot;engine.io-client&quot;</span><span class="o">:</span><span class="mi">11</span><span class="p">,</span><span class="s2">&quot;object-component&quot;</span><span class="o">:</span><span class="mi">37</span><span class="p">,</span><span class="s2">&quot;socket.io-parser&quot;</span><span class="o">:</span><span class="mi">40</span><span class="p">}],</span><span class="mi">4</span><span class="o">:</span><span class="p">[</span><span class="kd">function</span><span class="p">(</span><span class="nx">require</span><span class="p">,</span><span class="nx">module</span><span class="p">,</span><span class="nx">exports</span><span class="p">){</span></div><div class='line' id='LC554'><br/></div><div class='line' id='LC555'><span class="cm">/**</span></div><div class='line' id='LC556'><span class="cm"> * Module exports.</span></div><div class='line' id='LC557'><span class="cm"> */</span></div><div class='line' id='LC558'><br/></div><div class='line' id='LC559'><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">on</span><span class="p">;</span></div><div class='line' id='LC560'><br/></div><div class='line' id='LC561'><span class="cm">/**</span></div><div class='line' id='LC562'><span class="cm"> * Helper for subscriptions.</span></div><div class='line' id='LC563'><span class="cm"> *</span></div><div class='line' id='LC564'><span class="cm"> * @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter`</span></div><div class='line' id='LC565'><span class="cm"> * @param {String} event name</span></div><div class='line' id='LC566'><span class="cm"> * @param {Function} callback</span></div><div class='line' id='LC567'><span class="cm"> * @api public</span></div><div class='line' id='LC568'><span class="cm"> */</span></div><div class='line' id='LC569'><br/></div><div class='line' id='LC570'><span class="kd">function</span> <span class="nx">on</span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">ev</span><span class="p">,</span> <span class="nx">fn</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC571'>&nbsp;&nbsp;<span class="nx">obj</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="nx">ev</span><span class="p">,</span> <span class="nx">fn</span><span class="p">);</span></div><div class='line' id='LC572'>&nbsp;&nbsp;<span class="k">return</span> <span class="p">{</span></div><div class='line' id='LC573'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">destroy</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC574'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">obj</span><span class="p">.</span><span class="nx">removeListener</span><span class="p">(</span><span class="nx">ev</span><span class="p">,</span> <span class="nx">fn</span><span class="p">);</span></div><div class='line' id='LC575'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC576'>&nbsp;&nbsp;<span class="p">};</span></div><div class='line' id='LC577'><span class="p">}</span></div><div class='line' id='LC578'><br/></div><div class='line' id='LC579'><span class="p">},{}],</span><span class="mi">5</span><span class="o">:</span><span class="p">[</span><span class="kd">function</span><span class="p">(</span><span class="nx">require</span><span class="p">,</span><span class="nx">module</span><span class="p">,</span><span class="nx">exports</span><span class="p">){</span></div><div class='line' id='LC580'><br/></div><div class='line' id='LC581'><span class="cm">/**</span></div><div class='line' id='LC582'><span class="cm"> * Module dependencies.</span></div><div class='line' id='LC583'><span class="cm"> */</span></div><div class='line' id='LC584'><br/></div><div class='line' id='LC585'><span class="kd">var</span> <span class="nx">parser</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;socket.io-parser&#39;</span><span class="p">);</span></div><div class='line' id='LC586'><span class="kd">var</span> <span class="nx">Emitter</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;component-emitter&#39;</span><span class="p">);</span></div><div class='line' id='LC587'><span class="kd">var</span> <span class="nx">toArray</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;to-array&#39;</span><span class="p">);</span></div><div class='line' id='LC588'><span class="kd">var</span> <span class="nx">on</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./on&#39;</span><span class="p">);</span></div><div class='line' id='LC589'><span class="kd">var</span> <span class="nx">bind</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;component-bind&#39;</span><span class="p">);</span></div><div class='line' id='LC590'><span class="kd">var</span> <span class="nx">debug</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;debug&#39;</span><span class="p">)(</span><span class="s1">&#39;socket.io-client:socket&#39;</span><span class="p">);</span></div><div class='line' id='LC591'><span class="kd">var</span> <span class="nx">hasBin</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;has-binary-data&#39;</span><span class="p">);</span></div><div class='line' id='LC592'><span class="kd">var</span> <span class="nx">indexOf</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;indexof&#39;</span><span class="p">);</span></div><div class='line' id='LC593'><br/></div><div class='line' id='LC594'><span class="cm">/**</span></div><div class='line' id='LC595'><span class="cm"> * Module exports.</span></div><div class='line' id='LC596'><span class="cm"> */</span></div><div class='line' id='LC597'><br/></div><div class='line' id='LC598'><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">exports</span> <span class="o">=</span> <span class="nx">Socket</span><span class="p">;</span></div><div class='line' id='LC599'><br/></div><div class='line' id='LC600'><span class="cm">/**</span></div><div class='line' id='LC601'><span class="cm"> * Internal events (blacklisted).</span></div><div class='line' id='LC602'><span class="cm"> * These events can&#39;t be emitted by the user.</span></div><div class='line' id='LC603'><span class="cm"> *</span></div><div class='line' id='LC604'><span class="cm"> * @api private</span></div><div class='line' id='LC605'><span class="cm"> */</span></div><div class='line' id='LC606'><br/></div><div class='line' id='LC607'><span class="kd">var</span> <span class="nx">events</span> <span class="o">=</span> <span class="p">{</span></div><div class='line' id='LC608'>&nbsp;&nbsp;<span class="nx">connect</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC609'>&nbsp;&nbsp;<span class="nx">connect_error</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC610'>&nbsp;&nbsp;<span class="nx">connect_timeout</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC611'>&nbsp;&nbsp;<span class="nx">disconnect</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC612'>&nbsp;&nbsp;<span class="nx">error</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC613'>&nbsp;&nbsp;<span class="nx">reconnect</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC614'>&nbsp;&nbsp;<span class="nx">reconnect_attempt</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC615'>&nbsp;&nbsp;<span class="nx">reconnect_failed</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC616'>&nbsp;&nbsp;<span class="nx">reconnect_error</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span></div><div class='line' id='LC617'>&nbsp;&nbsp;<span class="nx">reconnecting</span><span class="o">:</span> <span class="mi">1</span></div><div class='line' id='LC618'><span class="p">};</span></div><div class='line' id='LC619'><br/></div><div class='line' id='LC620'><span class="cm">/**</span></div><div class='line' id='LC621'><span class="cm"> * Shortcut to `Emitter#emit`.</span></div><div class='line' id='LC622'><span class="cm"> */</span></div><div class='line' id='LC623'><br/></div><div class='line' id='LC624'><span class="kd">var</span> <span class="nx">emit</span> <span class="o">=</span> <span class="nx">Emitter</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">emit</span><span class="p">;</span></div><div class='line' id='LC625'><br/></div><div class='line' id='LC626'><span class="cm">/**</span></div><div class='line' id='LC627'><span class="cm"> * `Socket` constructor.</span></div><div class='line' id='LC628'><span class="cm"> *</span></div><div class='line' id='LC629'><span class="cm"> * @api public</span></div><div class='line' id='LC630'><span class="cm"> */</span></div><div class='line' id='LC631'><br/></div><div class='line' id='LC632'><span class="kd">function</span> <span class="nx">Socket</span><span class="p">(</span><span class="nx">io</span><span class="p">,</span> <span class="nx">nsp</span><span class="p">){</span></div><div class='line' id='LC633'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">io</span> <span class="o">=</span> <span class="nx">io</span><span class="p">;</span></div><div class='line' id='LC634'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">nsp</span> <span class="o">=</span> <span class="nx">nsp</span><span class="p">;</span></div><div class='line' id='LC635'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">json</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span> <span class="c1">// compat</span></div><div class='line' id='LC636'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">ids</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></div><div class='line' id='LC637'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">acks</span> <span class="o">=</span> <span class="p">{};</span></div><div class='line' id='LC638'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">open</span><span class="p">();</span></div><div class='line' id='LC639'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">receiveBuffer</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC640'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">sendBuffer</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC641'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">connected</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC642'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">disconnected</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC643'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subEvents</span><span class="p">();</span></div><div class='line' id='LC644'><span class="p">}</span></div><div class='line' id='LC645'><br/></div><div class='line' id='LC646'><span class="cm">/**</span></div><div class='line' id='LC647'><span class="cm"> * Mix in `Emitter`.</span></div><div class='line' id='LC648'><span class="cm"> */</span></div><div class='line' id='LC649'><br/></div><div class='line' id='LC650'><span class="nx">Emitter</span><span class="p">(</span><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">);</span></div><div class='line' id='LC651'><br/></div><div class='line' id='LC652'><span class="cm">/**</span></div><div class='line' id='LC653'><span class="cm"> * Subscribe to open, close and packet events</span></div><div class='line' id='LC654'><span class="cm"> *</span></div><div class='line' id='LC655'><span class="cm"> * @api private</span></div><div class='line' id='LC656'><span class="cm"> */</span></div><div class='line' id='LC657'><br/></div><div class='line' id='LC658'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">subEvents</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC659'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">io</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">io</span><span class="p">;</span></div><div class='line' id='LC660'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span> <span class="o">=</span> <span class="p">[</span></div><div class='line' id='LC661'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">on</span><span class="p">(</span><span class="nx">io</span><span class="p">,</span> <span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;onopen&#39;</span><span class="p">)),</span></div><div class='line' id='LC662'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">on</span><span class="p">(</span><span class="nx">io</span><span class="p">,</span> <span class="s1">&#39;packet&#39;</span><span class="p">,</span> <span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;onpacket&#39;</span><span class="p">)),</span></div><div class='line' id='LC663'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">on</span><span class="p">(</span><span class="nx">io</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="nx">bind</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;onclose&#39;</span><span class="p">))</span></div><div class='line' id='LC664'>&nbsp;&nbsp;<span class="p">];</span></div><div class='line' id='LC665'><span class="p">};</span></div><div class='line' id='LC666'><br/></div><div class='line' id='LC667'><span class="cm">/**</span></div><div class='line' id='LC668'><span class="cm"> * Called upon engine `open`.</span></div><div class='line' id='LC669'><span class="cm"> *</span></div><div class='line' id='LC670'><span class="cm"> * @api private</span></div><div class='line' id='LC671'><span class="cm"> */</span></div><div class='line' id='LC672'><br/></div><div class='line' id='LC673'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">open</span> <span class="o">=</span></div><div class='line' id='LC674'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">connect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC675'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">connected</span><span class="p">)</span> <span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC676'><br/></div><div class='line' id='LC677'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">io</span><span class="p">.</span><span class="nx">open</span><span class="p">();</span> <span class="c1">// ensure open</span></div><div class='line' id='LC678'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;open&#39;</span> <span class="o">==</span> <span class="k">this</span><span class="p">.</span><span class="nx">io</span><span class="p">.</span><span class="nx">readyState</span><span class="p">)</span> <span class="k">this</span><span class="p">.</span><span class="nx">onopen</span><span class="p">();</span></div><div class='line' id='LC679'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC680'><span class="p">};</span></div><div class='line' id='LC681'><br/></div><div class='line' id='LC682'><span class="cm">/**</span></div><div class='line' id='LC683'><span class="cm"> * Sends a `message` event.</span></div><div class='line' id='LC684'><span class="cm"> *</span></div><div class='line' id='LC685'><span class="cm"> * @return {Socket} self</span></div><div class='line' id='LC686'><span class="cm"> * @api public</span></div><div class='line' id='LC687'><span class="cm"> */</span></div><div class='line' id='LC688'><br/></div><div class='line' id='LC689'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">send</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC690'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">toArray</span><span class="p">(</span><span class="nx">arguments</span><span class="p">);</span></div><div class='line' id='LC691'>&nbsp;&nbsp;<span class="nx">args</span><span class="p">.</span><span class="nx">unshift</span><span class="p">(</span><span class="s1">&#39;message&#39;</span><span class="p">);</span></div><div class='line' id='LC692'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emit</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">args</span><span class="p">);</span></div><div class='line' id='LC693'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC694'><span class="p">};</span></div><div class='line' id='LC695'><br/></div><div class='line' id='LC696'><span class="cm">/**</span></div><div class='line' id='LC697'><span class="cm"> * Override `emit`.</span></div><div class='line' id='LC698'><span class="cm"> * If the event is in `events`, it&#39;s emitted normally.</span></div><div class='line' id='LC699'><span class="cm"> *</span></div><div class='line' id='LC700'><span class="cm"> * @param {String} event name</span></div><div class='line' id='LC701'><span class="cm"> * @return {Socket} self</span></div><div class='line' id='LC702'><span class="cm"> * @api public</span></div><div class='line' id='LC703'><span class="cm"> */</span></div><div class='line' id='LC704'><br/></div><div class='line' id='LC705'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">emit</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">ev</span><span class="p">){</span></div><div class='line' id='LC706'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">events</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">ev</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC707'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">emit</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span></div><div class='line' id='LC708'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC709'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC710'><br/></div><div class='line' id='LC711'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">toArray</span><span class="p">(</span><span class="nx">arguments</span><span class="p">);</span></div><div class='line' id='LC712'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">parserType</span> <span class="o">=</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">EVENT</span><span class="p">;</span> <span class="c1">// default</span></div><div class='line' id='LC713'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">hasBin</span><span class="p">(</span><span class="nx">args</span><span class="p">))</span> <span class="p">{</span> <span class="nx">parserType</span> <span class="o">=</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">BINARY_EVENT</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// binary</span></div><div class='line' id='LC714'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">packet</span> <span class="o">=</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="nx">parserType</span><span class="p">,</span> <span class="nx">data</span><span class="o">:</span> <span class="nx">args</span> <span class="p">};</span></div><div class='line' id='LC715'><br/></div><div class='line' id='LC716'>&nbsp;&nbsp;<span class="c1">// event ack callback</span></div><div class='line' id='LC717'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;function&#39;</span> <span class="o">==</span> <span class="k">typeof</span> <span class="nx">args</span><span class="p">[</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">])</span> <span class="p">{</span></div><div class='line' id='LC718'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;emitting packet with ack id %d&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">ids</span><span class="p">);</span></div><div class='line' id='LC719'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">acks</span><span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">ids</span><span class="p">]</span> <span class="o">=</span> <span class="nx">args</span><span class="p">.</span><span class="nx">pop</span><span class="p">();</span></div><div class='line' id='LC720'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">packet</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">ids</span><span class="o">++</span><span class="p">;</span></div><div class='line' id='LC721'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC722'><br/></div><div class='line' id='LC723'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">connected</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC724'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">packet</span><span class="p">(</span><span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC725'>&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC726'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">sendBuffer</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC727'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC728'><br/></div><div class='line' id='LC729'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC730'><span class="p">};</span></div><div class='line' id='LC731'><br/></div><div class='line' id='LC732'><span class="cm">/**</span></div><div class='line' id='LC733'><span class="cm"> * Sends a packet.</span></div><div class='line' id='LC734'><span class="cm"> *</span></div><div class='line' id='LC735'><span class="cm"> * @param {Object} packet</span></div><div class='line' id='LC736'><span class="cm"> * @api private</span></div><div class='line' id='LC737'><span class="cm"> */</span></div><div class='line' id='LC738'><br/></div><div class='line' id='LC739'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">packet</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">packet</span><span class="p">){</span></div><div class='line' id='LC740'>&nbsp;&nbsp;<span class="nx">packet</span><span class="p">.</span><span class="nx">nsp</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nsp</span><span class="p">;</span></div><div class='line' id='LC741'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">io</span><span class="p">.</span><span class="nx">packet</span><span class="p">(</span><span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC742'><span class="p">};</span></div><div class='line' id='LC743'><br/></div><div class='line' id='LC744'><span class="cm">/**</span></div><div class='line' id='LC745'><span class="cm"> * &quot;Opens&quot; the socket.</span></div><div class='line' id='LC746'><span class="cm"> *</span></div><div class='line' id='LC747'><span class="cm"> * @api private</span></div><div class='line' id='LC748'><span class="cm"> */</span></div><div class='line' id='LC749'><br/></div><div class='line' id='LC750'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onopen</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC751'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;transport is open - connecting&#39;</span><span class="p">);</span></div><div class='line' id='LC752'><br/></div><div class='line' id='LC753'>&nbsp;&nbsp;<span class="c1">// write connect packet if necessary</span></div><div class='line' id='LC754'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;/&#39;</span> <span class="o">!=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nsp</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC755'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">packet</span><span class="p">({</span> <span class="nx">type</span><span class="o">:</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">CONNECT</span> <span class="p">});</span></div><div class='line' id='LC756'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC757'><span class="p">};</span></div><div class='line' id='LC758'><br/></div><div class='line' id='LC759'><span class="cm">/**</span></div><div class='line' id='LC760'><span class="cm"> * Called upon engine `close`.</span></div><div class='line' id='LC761'><span class="cm"> *</span></div><div class='line' id='LC762'><span class="cm"> * @param {String} reason</span></div><div class='line' id='LC763'><span class="cm"> * @api private</span></div><div class='line' id='LC764'><span class="cm"> */</span></div><div class='line' id='LC765'><br/></div><div class='line' id='LC766'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onclose</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">reason</span><span class="p">){</span></div><div class='line' id='LC767'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;close (%s)&#39;</span><span class="p">,</span> <span class="nx">reason</span><span class="p">);</span></div><div class='line' id='LC768'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">connected</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC769'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">disconnected</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC770'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;disconnect&#39;</span><span class="p">,</span> <span class="nx">reason</span><span class="p">);</span></div><div class='line' id='LC771'><span class="p">};</span></div><div class='line' id='LC772'><br/></div><div class='line' id='LC773'><span class="cm">/**</span></div><div class='line' id='LC774'><span class="cm"> * Called with socket packet.</span></div><div class='line' id='LC775'><span class="cm"> *</span></div><div class='line' id='LC776'><span class="cm"> * @param {Object} packet</span></div><div class='line' id='LC777'><span class="cm"> * @api private</span></div><div class='line' id='LC778'><span class="cm"> */</span></div><div class='line' id='LC779'><br/></div><div class='line' id='LC780'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onpacket</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">packet</span><span class="p">){</span></div><div class='line' id='LC781'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">packet</span><span class="p">.</span><span class="nx">nsp</span> <span class="o">!=</span> <span class="k">this</span><span class="p">.</span><span class="nx">nsp</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span></div><div class='line' id='LC782'><br/></div><div class='line' id='LC783'>&nbsp;&nbsp;<span class="k">switch</span> <span class="p">(</span><span class="nx">packet</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC784'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">case</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">CONNECT</span><span class="o">:</span></div><div class='line' id='LC785'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">onconnect</span><span class="p">();</span></div><div class='line' id='LC786'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">break</span><span class="p">;</span></div><div class='line' id='LC787'><br/></div><div class='line' id='LC788'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">case</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">EVENT</span><span class="o">:</span></div><div class='line' id='LC789'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">onevent</span><span class="p">(</span><span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC790'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">break</span><span class="p">;</span></div><div class='line' id='LC791'><br/></div><div class='line' id='LC792'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">case</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">BINARY_EVENT</span><span class="o">:</span></div><div class='line' id='LC793'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">onevent</span><span class="p">(</span><span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC794'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">break</span><span class="p">;</span></div><div class='line' id='LC795'><br/></div><div class='line' id='LC796'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">case</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">ACK</span><span class="o">:</span></div><div class='line' id='LC797'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">onack</span><span class="p">(</span><span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC798'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">break</span><span class="p">;</span></div><div class='line' id='LC799'><br/></div><div class='line' id='LC800'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">case</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">BINARY_ACK</span><span class="o">:</span></div><div class='line' id='LC801'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">onack</span><span class="p">(</span><span class="nx">packet</span><span class="p">);</span></div><div class='line' id='LC802'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">break</span><span class="p">;</span></div><div class='line' id='LC803'><br/></div><div class='line' id='LC804'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">case</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">DISCONNECT</span><span class="o">:</span></div><div class='line' id='LC805'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">ondisconnect</span><span class="p">();</span></div><div class='line' id='LC806'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">break</span><span class="p">;</span></div><div class='line' id='LC807'><br/></div><div class='line' id='LC808'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">case</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">ERROR</span><span class="o">:</span></div><div class='line' id='LC809'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nx">packet</span><span class="p">.</span><span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC810'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">break</span><span class="p">;</span></div><div class='line' id='LC811'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC812'><span class="p">};</span></div><div class='line' id='LC813'><br/></div><div class='line' id='LC814'><span class="cm">/**</span></div><div class='line' id='LC815'><span class="cm"> * Called upon a server event.</span></div><div class='line' id='LC816'><span class="cm"> *</span></div><div class='line' id='LC817'><span class="cm"> * @param {Object} packet</span></div><div class='line' id='LC818'><span class="cm"> * @api private</span></div><div class='line' id='LC819'><span class="cm"> */</span></div><div class='line' id='LC820'><br/></div><div class='line' id='LC821'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onevent</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">packet</span><span class="p">){</span></div><div class='line' id='LC822'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">packet</span><span class="p">.</span><span class="nx">data</span> <span class="o">||</span> <span class="p">[];</span></div><div class='line' id='LC823'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;emitting event %j&#39;</span><span class="p">,</span> <span class="nx">args</span><span class="p">);</span></div><div class='line' id='LC824'><br/></div><div class='line' id='LC825'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="kc">null</span> <span class="o">!=</span> <span class="nx">packet</span><span class="p">.</span><span class="nx">id</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC826'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;attaching ack callback to event&#39;</span><span class="p">);</span></div><div class='line' id='LC827'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">args</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">ack</span><span class="p">(</span><span class="nx">packet</span><span class="p">.</span><span class="nx">id</span><span class="p">));</span></div><div class='line' id='LC828'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC829'><br/></div><div class='line' id='LC830'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">connected</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC831'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">emit</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">args</span><span class="p">);</span></div><div class='line' id='LC832'>&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC833'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">receiveBuffer</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">args</span><span class="p">);</span></div><div class='line' id='LC834'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC835'><span class="p">};</span></div><div class='line' id='LC836'><br/></div><div class='line' id='LC837'><span class="cm">/**</span></div><div class='line' id='LC838'><span class="cm"> * Produces an ack callback to emit with an event.</span></div><div class='line' id='LC839'><span class="cm"> *</span></div><div class='line' id='LC840'><span class="cm"> * @api private</span></div><div class='line' id='LC841'><span class="cm"> */</span></div><div class='line' id='LC842'><br/></div><div class='line' id='LC843'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">ack</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">id</span><span class="p">){</span></div><div class='line' id='LC844'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC845'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">sent</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC846'>&nbsp;&nbsp;<span class="k">return</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC847'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// prevent double callbacks</span></div><div class='line' id='LC848'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">sent</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span></div><div class='line' id='LC849'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">sent</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC850'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">toArray</span><span class="p">(</span><span class="nx">arguments</span><span class="p">);</span></div><div class='line' id='LC851'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;sending ack %j&#39;</span><span class="p">,</span> <span class="nx">args</span><span class="p">);</span></div><div class='line' id='LC852'><br/></div><div class='line' id='LC853'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">type</span> <span class="o">=</span> <span class="nx">hasBin</span><span class="p">(</span><span class="nx">args</span><span class="p">)</span> <span class="o">?</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">BINARY_ACK</span> <span class="o">:</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">ACK</span><span class="p">;</span></div><div class='line' id='LC854'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">packet</span><span class="p">({</span></div><div class='line' id='LC855'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">:</span> <span class="nx">type</span><span class="p">,</span></div><div class='line' id='LC856'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">id</span><span class="o">:</span> <span class="nx">id</span><span class="p">,</span></div><div class='line' id='LC857'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">data</span><span class="o">:</span> <span class="nx">args</span></div><div class='line' id='LC858'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class='line' id='LC859'>&nbsp;&nbsp;<span class="p">};</span></div><div class='line' id='LC860'><span class="p">};</span></div><div class='line' id='LC861'><br/></div><div class='line' id='LC862'><span class="cm">/**</span></div><div class='line' id='LC863'><span class="cm"> * Called upon a server acknowlegement.</span></div><div class='line' id='LC864'><span class="cm"> *</span></div><div class='line' id='LC865'><span class="cm"> * @param {Object} packet</span></div><div class='line' id='LC866'><span class="cm"> * @api private</span></div><div class='line' id='LC867'><span class="cm"> */</span></div><div class='line' id='LC868'><br/></div><div class='line' id='LC869'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onack</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">packet</span><span class="p">){</span></div><div class='line' id='LC870'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;calling ack %s with %j&#39;</span><span class="p">,</span> <span class="nx">packet</span><span class="p">.</span><span class="nx">id</span><span class="p">,</span> <span class="nx">packet</span><span class="p">.</span><span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC871'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">fn</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">acks</span><span class="p">[</span><span class="nx">packet</span><span class="p">.</span><span class="nx">id</span><span class="p">];</span></div><div class='line' id='LC872'>&nbsp;&nbsp;<span class="nx">fn</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">packet</span><span class="p">.</span><span class="nx">data</span><span class="p">);</span></div><div class='line' id='LC873'>&nbsp;&nbsp;<span class="k">delete</span> <span class="k">this</span><span class="p">.</span><span class="nx">acks</span><span class="p">[</span><span class="nx">packet</span><span class="p">.</span><span class="nx">id</span><span class="p">];</span></div><div class='line' id='LC874'><span class="p">};</span></div><div class='line' id='LC875'><br/></div><div class='line' id='LC876'><span class="cm">/**</span></div><div class='line' id='LC877'><span class="cm"> * Called upon server connect.</span></div><div class='line' id='LC878'><span class="cm"> *</span></div><div class='line' id='LC879'><span class="cm"> * @api private</span></div><div class='line' id='LC880'><span class="cm"> */</span></div><div class='line' id='LC881'><br/></div><div class='line' id='LC882'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">onconnect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC883'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">connected</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></div><div class='line' id='LC884'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">disconnected</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span></div><div class='line' id='LC885'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emit</span><span class="p">(</span><span class="s1">&#39;connect&#39;</span><span class="p">);</span></div><div class='line' id='LC886'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">emitBuffered</span><span class="p">();</span></div><div class='line' id='LC887'><span class="p">};</span></div><div class='line' id='LC888'><br/></div><div class='line' id='LC889'><span class="cm">/**</span></div><div class='line' id='LC890'><span class="cm"> * Emit buffered events (received and emitted).</span></div><div class='line' id='LC891'><span class="cm"> *</span></div><div class='line' id='LC892'><span class="cm"> * @api private</span></div><div class='line' id='LC893'><span class="cm"> */</span></div><div class='line' id='LC894'><br/></div><div class='line' id='LC895'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">emitBuffered</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC896'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">i</span><span class="p">;</span></div><div class='line' id='LC897'>&nbsp;&nbsp;<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="k">this</span><span class="p">.</span><span class="nx">receiveBuffer</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC898'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">emit</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">receiveBuffer</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span></div><div class='line' id='LC899'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC900'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">receiveBuffer</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC901'><br/></div><div class='line' id='LC902'>&nbsp;&nbsp;<span class="k">for</span> <span class="p">(</span><span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="k">this</span><span class="p">.</span><span class="nx">sendBuffer</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC903'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">packet</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">sendBuffer</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span></div><div class='line' id='LC904'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC905'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">sendBuffer</span> <span class="o">=</span> <span class="p">[];</span></div><div class='line' id='LC906'><span class="p">};</span></div><div class='line' id='LC907'><br/></div><div class='line' id='LC908'><span class="cm">/**</span></div><div class='line' id='LC909'><span class="cm"> * Called upon server disconnect.</span></div><div class='line' id='LC910'><span class="cm"> *</span></div><div class='line' id='LC911'><span class="cm"> * @api private</span></div><div class='line' id='LC912'><span class="cm"> */</span></div><div class='line' id='LC913'><br/></div><div class='line' id='LC914'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">ondisconnect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC915'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;server disconnect (%s)&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">nsp</span><span class="p">);</span></div><div class='line' id='LC916'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">destroy</span><span class="p">();</span></div><div class='line' id='LC917'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">onclose</span><span class="p">(</span><span class="s1">&#39;io server disconnect&#39;</span><span class="p">);</span></div><div class='line' id='LC918'><span class="p">};</span></div><div class='line' id='LC919'><br/></div><div class='line' id='LC920'><span class="cm">/**</span></div><div class='line' id='LC921'><span class="cm"> * Called upon forced client/server side disconnections,</span></div><div class='line' id='LC922'><span class="cm"> * this method ensures the manager stops tracking us and</span></div><div class='line' id='LC923'><span class="cm"> * that reconnections don&#39;t get triggered for this.</span></div><div class='line' id='LC924'><span class="cm"> *</span></div><div class='line' id='LC925'><span class="cm"> * @api private.</span></div><div class='line' id='LC926'><span class="cm"> */</span></div><div class='line' id='LC927'><br/></div><div class='line' id='LC928'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">destroy</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC929'>&nbsp;&nbsp;<span class="c1">// clean subscriptions to avoid reconnections</span></div><div class='line' id='LC930'>&nbsp;&nbsp;<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC931'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">subs</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">destroy</span><span class="p">();</span></div><div class='line' id='LC932'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC933'><br/></div><div class='line' id='LC934'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">io</span><span class="p">.</span><span class="nx">destroy</span><span class="p">(</span><span class="k">this</span><span class="p">);</span></div><div class='line' id='LC935'><span class="p">};</span></div><div class='line' id='LC936'><br/></div><div class='line' id='LC937'><span class="cm">/**</span></div><div class='line' id='LC938'><span class="cm"> * Disconnects the socket manually.</span></div><div class='line' id='LC939'><span class="cm"> *</span></div><div class='line' id='LC940'><span class="cm"> * @return {Socket} self</span></div><div class='line' id='LC941'><span class="cm"> * @api public</span></div><div class='line' id='LC942'><span class="cm"> */</span></div><div class='line' id='LC943'><br/></div><div class='line' id='LC944'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">close</span> <span class="o">=</span></div><div class='line' id='LC945'><span class="nx">Socket</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">disconnect</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC946'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">connected</span><span class="p">)</span> <span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC947'><br/></div><div class='line' id='LC948'>&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;performing disconnect (%s)&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">nsp</span><span class="p">);</span></div><div class='line' id='LC949'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">packet</span><span class="p">({</span> <span class="nx">type</span><span class="o">:</span> <span class="nx">parser</span><span class="p">.</span><span class="nx">DISCONNECT</span> <span class="p">});</span></div><div class='line' id='LC950'><br/></div><div class='line' id='LC951'>&nbsp;&nbsp;<span class="c1">// remove socket from pool</span></div><div class='line' id='LC952'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">destroy</span><span class="p">();</span></div><div class='line' id='LC953'><br/></div><div class='line' id='LC954'>&nbsp;&nbsp;<span class="c1">// fire events</span></div><div class='line' id='LC955'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">onclose</span><span class="p">(</span><span class="s1">&#39;io client disconnect&#39;</span><span class="p">);</span></div><div class='line' id='LC956'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC957'><span class="p">};</span></div><div class='line' id='LC958'><br/></div><div class='line' id='LC959'><span class="p">},{</span><span class="s2">&quot;./on&quot;</span><span class="o">:</span><span class="mi">4</span><span class="p">,</span><span class="s2">&quot;component-bind&quot;</span><span class="o">:</span><span class="mi">7</span><span class="p">,</span><span class="s2">&quot;component-emitter&quot;</span><span class="o">:</span><span class="mi">8</span><span class="p">,</span><span class="s2">&quot;debug&quot;</span><span class="o">:</span><span class="mi">9</span><span class="p">,</span><span class="s2">&quot;has-binary-data&quot;</span><span class="o">:</span><span class="mi">32</span><span class="p">,</span><span class="s2">&quot;indexof&quot;</span><span class="o">:</span><span class="mi">36</span><span class="p">,</span><span class="s2">&quot;socket.io-parser&quot;</span><span class="o">:</span><span class="mi">40</span><span class="p">,</span><span class="s2">&quot;to-array&quot;</span><span class="o">:</span><span class="mi">43</span><span class="p">}],</span><span class="mi">6</span><span class="o">:</span><span class="p">[</span><span class="kd">function</span><span class="p">(</span><span class="nx">require</span><span class="p">,</span><span class="nx">module</span><span class="p">,</span><span class="nx">exports</span><span class="p">){</span></div><div class='line' id='LC960'><span class="kd">var</span> <span class="nx">global</span><span class="o">=</span><span class="k">typeof</span> <span class="nx">self</span> <span class="o">!==</span> <span class="s2">&quot;undefined&quot;</span> <span class="o">?</span> <span class="nx">self</span> <span class="o">:</span> <span class="k">typeof</span> <span class="nb">window</span> <span class="o">!==</span> <span class="s2">&quot;undefined&quot;</span> <span class="o">?</span> <span class="nb">window</span> <span class="o">:</span> <span class="p">{};</span></div><div class='line' id='LC961'><span class="cm">/**</span></div><div class='line' id='LC962'><span class="cm"> * Module dependencies.</span></div><div class='line' id='LC963'><span class="cm"> */</span></div><div class='line' id='LC964'><br/></div><div class='line' id='LC965'><span class="kd">var</span> <span class="nx">parseuri</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;parseuri&#39;</span><span class="p">);</span></div><div class='line' id='LC966'><span class="kd">var</span> <span class="nx">debug</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;debug&#39;</span><span class="p">)(</span><span class="s1">&#39;socket.io-client:url&#39;</span><span class="p">);</span></div><div class='line' id='LC967'><br/></div><div class='line' id='LC968'><span class="cm">/**</span></div><div class='line' id='LC969'><span class="cm"> * Module exports.</span></div><div class='line' id='LC970'><span class="cm"> */</span></div><div class='line' id='LC971'><br/></div><div class='line' id='LC972'><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">url</span><span class="p">;</span></div><div class='line' id='LC973'><br/></div><div class='line' id='LC974'><span class="cm">/**</span></div><div class='line' id='LC975'><span class="cm"> * URL parser.</span></div><div class='line' id='LC976'><span class="cm"> *</span></div><div class='line' id='LC977'><span class="cm"> * @param {String} url</span></div><div class='line' id='LC978'><span class="cm"> * @param {Object} An object meant to mimic window.location.</span></div><div class='line' id='LC979'><span class="cm"> *                 Defaults to window.location.</span></div><div class='line' id='LC980'><span class="cm"> * @api public</span></div><div class='line' id='LC981'><span class="cm"> */</span></div><div class='line' id='LC982'><br/></div><div class='line' id='LC983'><span class="kd">function</span> <span class="nx">url</span><span class="p">(</span><span class="nx">uri</span><span class="p">,</span> <span class="nx">loc</span><span class="p">){</span></div><div class='line' id='LC984'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">obj</span> <span class="o">=</span> <span class="nx">uri</span><span class="p">;</span></div><div class='line' id='LC985'><br/></div><div class='line' id='LC986'>&nbsp;&nbsp;<span class="c1">// default to window.location</span></div><div class='line' id='LC987'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">loc</span> <span class="o">=</span> <span class="nx">loc</span> <span class="o">||</span> <span class="nx">global</span><span class="p">.</span><span class="nx">location</span><span class="p">;</span></div><div class='line' id='LC988'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="kc">null</span> <span class="o">==</span> <span class="nx">uri</span><span class="p">)</span> <span class="nx">uri</span> <span class="o">=</span> <span class="nx">loc</span><span class="p">.</span><span class="nx">protocol</span> <span class="o">+</span> <span class="s1">&#39;//&#39;</span> <span class="o">+</span> <span class="nx">loc</span><span class="p">.</span><span class="nx">hostname</span><span class="p">;</span></div><div class='line' id='LC989'><br/></div><div class='line' id='LC990'>&nbsp;&nbsp;<span class="c1">// relative path support</span></div><div class='line' id='LC991'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;string&#39;</span> <span class="o">==</span> <span class="k">typeof</span> <span class="nx">uri</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC992'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;/&#39;</span> <span class="o">==</span> <span class="nx">uri</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC993'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">!=</span> <span class="k">typeof</span> <span class="nx">loc</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC994'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">uri</span> <span class="o">=</span> <span class="nx">loc</span><span class="p">.</span><span class="nx">hostname</span> <span class="o">+</span> <span class="nx">uri</span><span class="p">;</span></div><div class='line' id='LC995'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC996'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC997'><br/></div><div class='line' id='LC998'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="sr">/^(https?|wss?):\/\//</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">uri</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC999'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;protocol-less url %s&#39;</span><span class="p">,</span> <span class="nx">uri</span><span class="p">);</span></div><div class='line' id='LC1000'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">!=</span> <span class="k">typeof</span> <span class="nx">loc</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC1001'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">uri</span> <span class="o">=</span> <span class="nx">loc</span><span class="p">.</span><span class="nx">protocol</span> <span class="o">+</span> <span class="s1">&#39;//&#39;</span> <span class="o">+</span> <span class="nx">uri</span><span class="p">;</span></div><div class='line' id='LC1002'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class='line' id='LC1003'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">uri</span> <span class="o">=</span> <span class="s1">&#39;https://&#39;</span> <span class="o">+</span> <span class="nx">uri</span><span class="p">;</span></div><div class='line' id='LC1004'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC1005'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC1006'><br/></div><div class='line' id='LC1007'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1">// parse</span></div><div class='line' id='LC1008'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">debug</span><span class="p">(</span><span class="s1">&#39;parse %s&#39;</span><span class="p">,</span> <span class="nx">uri</span><span class="p">);</span></div><div class='line' id='LC1009'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">obj</span> <span class="o">=</span> <span class="nx">parseuri</span><span class="p">(</span><span class="nx">uri</span><span class="p">);</span></div><div class='line' id='LC1010'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC1011'><br/></div><div class='line' id='LC1012'>&nbsp;&nbsp;<span class="c1">// make sure we treat `localhost:80` and `localhost` equally</span></div><div class='line' id='LC1013'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">obj</span><span class="p">.</span><span class="nx">port</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC1014'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="sr">/^(http|ws)$/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">obj</span><span class="p">.</span><span class="nx">protocol</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC1015'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">obj</span><span class="p">.</span><span class="nx">port</span> <span class="o">=</span> <span class="s1">&#39;80&#39;</span><span class="p">;</span></div><div class='line' id='LC1016'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC1017'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="sr">/^(http|ws)s$/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">obj</span><span class="p">.</span><span class="nx">protocol</span><span class="p">))</span> <span class="p">{</span></div><div class='line' id='LC1018'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">obj</span><span class="p">.</span><span class="nx">port</span> <span class="o">=</span> <span class="s1">&#39;443&#39;</span><span class="p">;</span></div><div class='line' id='LC1019'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC1020'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC1021'><br/></div><div class='line' id='LC1022'>&nbsp;&nbsp;<span class="nx">obj</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">path</span> <span class="o">||</span> <span class="s1">&#39;/&#39;</span><span class="p">;</span></div><div class='line' id='LC1023'><br/></div><div class='line' id='LC1024'>&nbsp;&nbsp;<span class="c1">// define unique id</span></div><div class='line' id='LC1025'>&nbsp;&nbsp;<span class="nx">obj</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">protocol</span> <span class="o">+</span> <span class="s1">&#39;://&#39;</span> <span class="o">+</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">host</span> <span class="o">+</span> <span class="s1">&#39;:&#39;</span> <span class="o">+</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">port</span><span class="p">;</span></div><div class='line' id='LC1026'>&nbsp;&nbsp;<span class="c1">// define href</span></div><div class='line' id='LC1027'>&nbsp;&nbsp;<span class="nx">obj</span><span class="p">.</span><span class="nx">href</span> <span class="o">=</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">protocol</span> <span class="o">+</span> <span class="s1">&#39;://&#39;</span> <span class="o">+</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">host</span> <span class="o">+</span> <span class="p">(</span><span class="nx">loc</span> <span class="o">&amp;&amp;</span> <span class="nx">loc</span><span class="p">.</span><span class="nx">port</span> <span class="o">==</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">port</span> <span class="o">?</span> <span class="s1">&#39;&#39;</span> <span class="o">:</span> <span class="p">(</span><span class="s1">&#39;:&#39;</span> <span class="o">+</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">port</span><span class="p">));</span></div><div class='line' id='LC1028'><br/></div><div class='line' id='LC1029'>&nbsp;&nbsp;<span class="k">return</span> <span class="nx">obj</span><span class="p">;</span></div><div class='line' id='LC1030'><span class="p">}</span></div><div class='line' id='LC1031'><br/></div><div class='line' id='LC1032'><span class="p">},{</span><span class="s2">&quot;debug&quot;</span><span class="o">:</span><span class="mi">9</span><span class="p">,</span><span class="s2">&quot;parseuri&quot;</span><span class="o">:</span><span class="mi">38</span><span class="p">}],</span><span class="mi">7</span><span class="o">:</span><span class="p">[</span><span class="kd">function</span><span class="p">(</span><span class="nx">require</span><span class="p">,</span><span class="nx">module</span><span class="p">,</span><span class="nx">exports</span><span class="p">){</span></div><div class='line' id='LC1033'><span class="cm">/**</span></div><div class='line' id='LC1034'><span class="cm"> * Slice reference.</span></div><div class='line' id='LC1035'><span class="cm"> */</span></div><div class='line' id='LC1036'><br/></div><div class='line' id='LC1037'><span class="kd">var</span> <span class="nx">slice</span> <span class="o">=</span> <span class="p">[].</span><span class="nx">slice</span><span class="p">;</span></div><div class='line' id='LC1038'><br/></div><div class='line' id='LC1039'><span class="cm">/**</span></div><div class='line' id='LC1040'><span class="cm"> * Bind `obj` to `fn`.</span></div><div class='line' id='LC1041'><span class="cm"> *</span></div><div class='line' id='LC1042'><span class="cm"> * @param {Object} obj</span></div><div class='line' id='LC1043'><span class="cm"> * @param {Function|String} fn or string</span></div><div class='line' id='LC1044'><span class="cm"> * @return {Function}</span></div><div class='line' id='LC1045'><span class="cm"> * @api public</span></div><div class='line' id='LC1046'><span class="cm"> */</span></div><div class='line' id='LC1047'><br/></div><div class='line' id='LC1048'><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">fn</span><span class="p">){</span></div><div class='line' id='LC1049'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;string&#39;</span> <span class="o">==</span> <span class="k">typeof</span> <span class="nx">fn</span><span class="p">)</span> <span class="nx">fn</span> <span class="o">=</span> <span class="nx">obj</span><span class="p">[</span><span class="nx">fn</span><span class="p">];</span></div><div class='line' id='LC1050'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;function&#39;</span> <span class="o">!=</span> <span class="k">typeof</span> <span class="nx">fn</span><span class="p">)</span> <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;bind() requires a function&#39;</span><span class="p">);</span></div><div class='line' id='LC1051'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span></div><div class='line' id='LC1052'>&nbsp;&nbsp;<span class="k">return</span> <span class="kd">function</span><span class="p">(){</span></div><div class='line' id='LC1053'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="nx">fn</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">args</span><span class="p">.</span><span class="nx">concat</span><span class="p">(</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">)));</span></div><div class='line' id='LC1054'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC1055'><span class="p">};</span></div><div class='line' id='LC1056'><br/></div><div class='line' id='LC1057'><span class="p">},{}],</span><span class="mi">8</span><span class="o">:</span><span class="p">[</span><span class="kd">function</span><span class="p">(</span><span class="nx">require</span><span class="p">,</span><span class="nx">module</span><span class="p">,</span><span class="nx">exports</span><span class="p">){</span></div><div class='line' id='LC1058'><br/></div><div class='line' id='LC1059'><span class="cm">/**</span></div><div class='line' id='LC1060'><span class="cm"> * Expose `Emitter`.</span></div><div class='line' id='LC1061'><span class="cm"> */</span></div><div class='line' id='LC1062'><br/></div><div class='line' id='LC1063'><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nx">Emitter</span><span class="p">;</span></div><div class='line' id='LC1064'><br/></div><div class='line' id='LC1065'><span class="cm">/**</span></div><div class='line' id='LC1066'><span class="cm"> * Initialize a new `Emitter`.</span></div><div class='line' id='LC1067'><span class="cm"> *</span></div><div class='line' id='LC1068'><span class="cm"> * @api public</span></div><div class='line' id='LC1069'><span class="cm"> */</span></div><div class='line' id='LC1070'><br/></div><div class='line' id='LC1071'><span class="kd">function</span> <span class="nx">Emitter</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC1072'>&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="k">return</span> <span class="nx">mixin</span><span class="p">(</span><span class="nx">obj</span><span class="p">);</span></div><div class='line' id='LC1073'><span class="p">};</span></div><div class='line' id='LC1074'><br/></div><div class='line' id='LC1075'><span class="cm">/**</span></div><div class='line' id='LC1076'><span class="cm"> * Mixin the emitter properties.</span></div><div class='line' id='LC1077'><span class="cm"> *</span></div><div class='line' id='LC1078'><span class="cm"> * @param {Object} obj</span></div><div class='line' id='LC1079'><span class="cm"> * @return {Object}</span></div><div class='line' id='LC1080'><span class="cm"> * @api private</span></div><div class='line' id='LC1081'><span class="cm"> */</span></div><div class='line' id='LC1082'><br/></div><div class='line' id='LC1083'><span class="kd">function</span> <span class="nx">mixin</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC1084'>&nbsp;&nbsp;<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">key</span> <span class="k">in</span> <span class="nx">Emitter</span><span class="p">.</span><span class="nx">prototype</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC1085'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">Emitter</span><span class="p">.</span><span class="nx">prototype</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span></div><div class='line' id='LC1086'>&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC1087'>&nbsp;&nbsp;<span class="k">return</span> <span class="nx">obj</span><span class="p">;</span></div><div class='line' id='LC1088'><span class="p">}</span></div><div class='line' id='LC1089'><br/></div><div class='line' id='LC1090'><span class="cm">/**</span></div><div class='line' id='LC1091'><span class="cm"> * Listen on the given `event` with `fn`.</span></div><div class='line' id='LC1092'><span class="cm"> *</span></div><div class='line' id='LC1093'><span class="cm"> * @param {String} event</span></div><div class='line' id='LC1094'><span class="cm"> * @param {Function} fn</span></div><div class='line' id='LC1095'><span class="cm"> * @return {Emitter}</span></div><div class='line' id='LC1096'><span class="cm"> * @api public</span></div><div class='line' id='LC1097'><span class="cm"> */</span></div><div class='line' id='LC1098'><br/></div><div class='line' id='LC1099'><span class="nx">Emitter</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">on</span> <span class="o">=</span></div><div class='line' id='LC1100'><span class="nx">Emitter</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">addEventListener</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">,</span> <span class="nx">fn</span><span class="p">){</span></div><div class='line' id='LC1101'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">_callbacks</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_callbacks</span> <span class="o">||</span> <span class="p">{};</span></div><div class='line' id='LC1102'>&nbsp;&nbsp;<span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_callbacks</span><span class="p">[</span><span class="nx">event</span><span class="p">]</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_callbacks</span><span class="p">[</span><span class="nx">event</span><span class="p">]</span> <span class="o">||</span> <span class="p">[])</span></div><div class='line' id='LC1103'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">fn</span><span class="p">);</span></div><div class='line' id='LC1104'>&nbsp;&nbsp;<span class="k">return</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC1105'><span class="p">};</span></div><div class='line' id='LC1106'><br/></div><div class='line' id='LC1107'><span class="cm">/**</span></div><div class='line' id='LC1108'><span class="cm"> * Adds an `event` listener that will be invoked a single</span></div><div class='line' id='LC1109'><span class="cm"> * time then automatically removed.</span></div><div class='line' id='LC1110'><span class="cm"> *</span></div><div class='line' id='LC1111'><span class="cm"> * @param {String} event</span></div><div class='line' id='LC1112'><span class="cm"> * @param {Function} fn</span></div><div class='line' id='LC1113'><span class="cm"> * @return {Emitter}</span></div><div class='line' id='LC1114'><span class="cm"> * @api public</span></div><div class='line' id='LC1115'><span class="cm"> */</span></div><div class='line' id='LC1116'><br/></div><div class='line' id='LC1117'><span class="nx">Emitter</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">once</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">,</span> <span class="nx">fn</span><span class="p">){</span></div><div class='line' id='LC1118'>&nbsp;&nbsp;<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span></div><div class='line' id='LC1119'>&nbsp;&nbsp;<span class="k">this</span><span class="p">.</span><span class="nx">_callbacks</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_callbacks</span> <span class="o">||</span> <span class="p">{};</span></div><div class='line' id='LC1120'><br/></div><div class='line' id='LC1121'>&nbsp;&nbsp;<span class="kd">function</span> <span class="nx">on</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC1122'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">self</span><span class="p">.</span><span class="nx">
GCDAsyncUdpSocket.h https://github.com/spark/ios-app.git | C++ Header | 995 lines
121 * The socket queue is optional.
122 * If you pass NULL, GCDAsyncSocket will automatically create its own socket queue.
123 * If you choose to provide a socket queue, the socket queue must not be a concurrent queue,
822 * Here's how you would accomplish something like that:
823 * - (dispatch_queue_t)newSocketQueueForConnectionFromAddress:(NSData *)address onSocket:(GCDAsyncSocket *)sock
824 * {
832 * }
833 * - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket
834 * {
968 **/
969- (void)udpSocket:(GCDAsyncUdpSocket *)sock didNotConnect:(NSError *)error;
970
973 **/
974- (void)udpSocket:(GCDAsyncUdpSocket *)sock didSendDataWithTag:(long)tag;
975
test.chrome.socket.js https://github.com/engmsaleh/mobile-chrome-apps.git | JavaScript | 602 lines
223    it('getInfo works', function(done) {
224      chrome.socket.getInfo(sockets[0].socketId, function(socketInfo) {
225        expect(socketInfo.socketType).toEqual('tcp');
234
235          chrome.socket.getInfo(sockets[0].socketId, function(socketInfo) {
236            expect(socketInfo.socketType).toEqual('tcp');
265
266              chrome.socket.getInfo(sockets[1].socketId, function(socketInfo) {
267                expect(socketInfo.socketType).toEqual('tcp');
273
274                chrome.socket.write(sockets[1].socketId, data, function(writeResult) {
275                });
356
357        chrome.socket.getInfo(sockets[0].socketId, function(socketInfo) {
358          expect(socketInfo.socketType).toEqual('udp');
SocketFetcher.java https://github.com/subgraph/sgmail.git | Java | 727 lines
293	if (writeTimeout != -1)	// wrap original
294	    socket = new WriteTimeoutSocket(socket, writeTimeout);
295	if (localaddr != null)
328		ssf = (SSLSocketFactory)SSLSocketFactory.getDefault();
329	    socket = ssf.createSocket(socket, host, port, true);
330	    sf = ssf;
377     */
378    public static Socket startTLS(Socket socket) throws IOException {
379	return startTLS(socket, new Properties(), "socket");
467
468	    socket = ssf.createSocket(socket, host, port, true);
469	    configureSSLSocket(socket, host, props, prefix, ssf);
502	    return;
503	SSLSocket sslsocket = (SSLSocket)socket;
504
inet.erl https://github.com/alricb/Erlang-OTP.git | Erlang | 1,343 lines
159-spec sockname(Socket) -> {ok, {Address, Port}} | {error, posix()} when
160      Socket :: socket(),
161      Address :: ip_address(),
353	{ok, OptionValues} | {error, posix()} when
354      Socket :: socket(),
355      Options :: [stat_option()],
435
436-spec getll(Socket :: socket()) -> {'ok', socket()}.
437
437
438getll(Socket) when is_port(Socket) ->
439    {ok, Socket}.
444
445-spec getfd(Socket :: socket()) ->
446	{'ok', non_neg_integer()} | {'error', posix()}.
socket.h https://github.com/jay/wxWidgets.git | C++ Header | 1,471 lines
191*/
192class wxSocketServer : public wxSocketBase
193{
294    */
295    wxSocketClient(wxSocketFlags flags = wxSOCKET_NONE);
296
477
478    @see wxSocketBase, wxSocketClient, wxSocketServer
479*/
718
719    @see wxSocketEvent, wxSocketClient, wxSocketServer, @sample{sockets},
720         @ref wxSocketFlags, ::wxSocketEventFlags, ::wxSocketError
1415    */
1416    wxSOCKET_T GetSocket() const;
1417
socket.c https://github.com/shehperd/Espruino.git | C | 1,184 lines
124		
125		if(SOCKET_STATUS_ACTIVE != get_socket_active_status(sd))
126			return -1;
358//!          addr is addrlen bytes long. Traditionally, this is called when a 
359//!          socket is created with socket, it exists in a name space (address 
360//!          family) but has no name assigned.
517//!  @brief  initiate a connection on a socket 
518//!          Function connects the socket referred to by the socket descriptor 
519//!          sd, to the address specified by addr. The addrlen argument 
525//!          If the socket is of type SOCK_STREAM, this call attempts to make a 
526//!          connection to another socket. The other socket is specified  by 
527//!          address, which is an address in the communications space of the
956//!                 function receives a message from a connection-mode or
957//!                 connectionless-mode socket. Note that raw sockets are not
958//!                 supported.
w5500.h https://github.com/shehperd/Espruino.git | C++ Header | 2,055 lines
181/**
182 * @defgroup Socket_register_access_function Socket register access functions
183 * @ingroup WIZCHIP_IO_Functions
687 * If WOL mode is enabled and the received magic packet over UDP has been normally processed, the Interrupt PIN (INTn) asserts to low.
688 * When using WOL mode, the UDP Socket should be opened with any source port number. (Refer to Socket n Mode Register (@ref Sn_MR) for opening Socket.)
689 * @note The magic packet over UDP supported by W5500 consists of 6 bytes synchronization stream (xFFFFFFFFFFFF and
967 * @details SEND transmits all the data in the Socket n TX buffer.\n
968 * For more details, please refer to Socket n TX Free Size Register (@ref Sn_TX_FSR), Socket n,
969 * TX Write Pointer Register(@ref Sn_TX_WR), and Socket n TX Read Pointer Register(@ref Sn_TX_RD).
993 * @details RECV completes the processing of the received data in Socket n RX Buffer by using a RX read pointer register (@ref Sn_RX_RD).\n
994 * For more details, refer to Socket n RX Received Size Register (@ref Sn_RX_RSR), Socket n RX Write Pointer Register (@ref Sn_RX_WR),
995 * and Socket n RX Read Pointer Register (@ref Sn_RX_RD).
1130 * @brief MAC raw mode socket
1131 * @details This indicates Socket 0 is opened in MACRAW mode (S0_MR(P[3:0]) = 100and is valid only in Socket 0.\n
1132 * It changes to SOCK_MACRAW when S0_MR(P[3:0] = 100and OPEN command is ordered.\n
socket.h https://github.com/shehperd/Espruino.git | C++ Header | 462 lines
4//! \brief SOCKET APIs Header file.
5//! \details SOCKET APIs like as berkeley socket api. 
6//! \version 1.0.0
42/**
43 * @defgroup WIZnet_socket_APIs 1. WIZnet socket APIs
44 * @brief WIZnet socket APIs are based on Berkeley socket APIs,  thus it has much similar name and interface.
61 * There are @b bind() and @b accept() functions in @b Berkeley SOCKET API but,
62 * not in @b WIZnet SOCKET API. Because socket() of WIZnet is not only creating a SOCKET but also binding a local port number,
63 * and listen() of WIZnet is not only listening to connection request from client but also accepting the connection request. \n
73 * If there're many listen SOCKET with same listen port number and a client requests a connection,
74 * the SOCKET which has the smallest SOCKET number accepts the request and is changed as communication SOCKET. \n
75 * Following figure shows network flow diagram by WIZnet SOCKET API.
362{
363   SO_FLAG,           ///< Valid only in getsockopt(), For set flag of socket refer to <I>flag</I> in @ref socket().
364   SO_TTL,              ///< Set/Get TTL. @ref Sn_TTL  ( @ref setSn_TTL(), @ref getSn_TTL() )
udp.py https://github.com/adaschevici/twisted.git | Python | 508 lines
408        self.socket.setsockopt(
409            socket.SOL_SOCKET, socket.SO_BROADCAST, enabled)
410
419        return operator.truth(
420            self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST))
421
438        i = socket.inet_aton(addr)
439        self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, i)
440        return 1
496        if self.listenMultiple:
497            skt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
498            if hasattr(socket, "SO_REUSEPORT"):
499                try:
500                    skt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
501                except socket.error as le:
tcp.py https://github.com/adaschevici/twisted.git | Python | 1,181 lines
131                # instead of the standard FIN shutdown sequence.
132                self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
133                                       struct.pack("ii", 1, 0))
318    def setTcpKeepAlive(self, enabled):
319        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, enabled)
320
335    @ivar addressFamily: The address family constant (C{socket.AF_INET},
336        C{socket.AF_INET6}, C{socket.AF_UNIX}) of the underlying socket of this
337        client connection.
339
340    @ivar socketType: The socket type constant (C{socket.SOCK_STREAM} or
341        C{socket.SOCK_DGRAM}) of the underlying socket.
554
555        err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
556        if err:
connection.js https://github.com/justinleoye/node-apn.git | JavaScript | 781 lines
250		this.socket.on("drain", this.socketDrained.bind(this, this.socket, true));
251		this.socket.once("close", this.socketClosed.bind(this, this.socket));
252
283
284		this.socket.socketId = this.socketId++;
285		this.socket.currentId = 0;
394Connection.prototype.socketAvailable = function(socket) {
395	if (!socket || !socket.writable || socket.busy || socket.transmissionErrorOccurred) {
396		return false;
404Connection.prototype.socketDrained = function(socket, serviceBuffer) {
405	debug("Socket drained", socket.socketId);
406	socket.busy = false;
430 Connection.prototype.socketTimeout = function(socket) {
431	debug("Socket timeout", socket.socketId);
432	this.emit('timeout');
uipc_socket.c https://github.com/brauceunix/libuinet.git | C | 3,903 lines
37 *
38 * soalloc() sets of socket layer state for a socket, called only by
39 * socreate() and sonewconn().  Socket layer private.
40 *
41 * sodealloc() tears down socket layer state for a socket, called only by
42 * sofree() and sonewconn().  Socket layer private.
84 * the socket have been released, and is the public interface to attempt to
85 * free a socket when a reference is removed.  This is a socket layer private
86 * interface.
3740void
3741sotoxsocket(struct socket *so, struct xsocket *xso)
3742{
3772void
3773so_listeners_apply_all(struct socket *so, void (*func)(struct socket *, void *), void *arg)
3774{
net.py https://github.com/omgwtftbh/miro.git | Python | 662 lines
276            try:
277                self.socket = socket.socket(family, socket.SOCK_STREAM)
278            except socket.error, e:
298            try:
299                self.socket = socket.socket(entry[0], socket.SOCK_STREAM)
300            except socket.error, e:
319            self.socketConnectTimeout.cancel()
320            rv = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
321            if rv == 0:
346        try:
347            self.socket = socket.socket(family, socket.SOCK_STREAM)
348            self.socket.bind((host, port))
358        else:
359            raise ValueError("Unknown socket family: %s", self.socket.family)
360        self.socket.listen(63)
zsockopt.c https://github.com/jricher42/czmq.git | C | 3,884 lines
112    &&  zsocket_type (zocket) != ZMQ_REQ) {
113        printf ("ZMQ_PROBE_ROUTER is not valid on %s sockets\n", zsocket_type_str (zocket));
114        assert (false);
1806    &&  zsocket_type (zocket) != ZMQ_ROUTER) {
1807        printf ("ZMQ_IDENTITY is not valid on %s sockets\n", zsocket_type_str (zocket));
1808        assert (false);
2227    if (zsocket_type (zocket) != ZMQ_XPUB) {
2228        printf ("ZMQ_XPUB_VERBOSE is not valid on %s sockets\n", zsocket_type_str (zocket));
2229        assert (false);
3005    if (zsocket_type (zocket) != ZMQ_SUB) {
3006        printf ("ZMQ_SUBSCRIBE is not valid on %s sockets\n", zsocket_type_str (zocket));
3007        assert (false);
3023    if (zsocket_type (zocket) != ZMQ_SUB) {
3024        printf ("ZMQ_UNSUBSCRIBE is not valid on %s sockets\n", zsocket_type_str (zocket));
3025        assert (false);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21