Sha256: 2d66c7c303d0f14af2f5a3fa0e6c4e662f1d5222576fa82c8a71cdfaab80e7b8
Contents?: true
Size: 1.64 KB
Versions: 5
Compression:
Stored size: 1.64 KB
Contents
### HTTP Interface for the WebSocketRails client. ### class WebSocketRails.HttpConnection httpFactories: -> [ -> new XMLHttpRequest(), -> new ActiveXObject("Msxml2.XMLHTTP"), -> new ActiveXObject("Msxml3.XMLHTTP"), -> new ActiveXObject("Microsoft.XMLHTTP") ] createXMLHttpObject: => xmlhttp = false factories = @httpFactories() for factory in factories try xmlhttp = factory() catch e continue break xmlhttp constructor: (@url, @dispatcher) -> @_url = @url @_conn = @createXMLHttpObject() @last_pos = 0 @message_queue = [] @_conn.onreadystatechange = @parse_stream @_conn.open "GET", @_url, true @_conn.send() parse_stream: => if @_conn.readyState == 3 data = @_conn.responseText.substring @last_pos @last_pos = @_conn.responseText.length data = data.replace( /\]\]\[\[/g, "],[" ) decoded_data = JSON.parse data @dispatcher.new_message decoded_data trigger: (event) => if @dispatcher.state != 'connected' @message_queue.push event else @post_data @dispatcher.connection_id, event.serialize() post_data: (connection_id, payload) -> $.ajax @_url, type: 'POST' data: client_id: connection_id data: payload success: -> flush_queue: (connection_id) => for event in @message_queue # Events queued before connecting do not have the correct # connection_id set yet. We need to update it before dispatching. if connection_id? event.connection_id = @dispatcher.connection_id @trigger event @message_queue = []
Version data entries
5 entries across 5 versions & 1 rubygems