Changeset - a609c419d7b6
[Not reviewed]
default
0 1 0
Drew Perttula - 6 years ago 2019-05-30 08:31:58
drewp@bigasterisk.com
support rdfdb 0.19.0 telling us our connection id in its logs
Ignore-this: dafead665ead86a7c00afbc051222f8f
1 file changed with 10 insertions and 6 deletions:
0 comments (0 inline, 0 general)
light9/web/rdfdbclient.coffee
Show inline comments
 
@@ -25,15 +25,14 @@ toJsonPatch = (jsPatch, cb) ->
 
      cb())
 
    
 
  async.parallel([writeDels, writeAdds], (err) ->
 
    cb(JSON.stringify(out))
 
  )
 

	
 
parseJsonPatch = (jsonPatch, cb) ->
 
parseJsonPatch = (input, cb) ->
 
  # note response cb doesn't have an error arg.
 
  input = JSON.parse(jsonPatch)
 
  patch = {delQuads: [], addQuads: []}
 

	
 
  parseAdds = (cb) =>
 
    parser = N3.Parser()
 
    parser.parse input.patch.adds, (error, quad, prefixes) =>
 
      if (quad)
 
@@ -55,20 +54,20 @@ class window.RdfDbClient
 
  constructor: (@patchSenderUrl, @clearGraphOnNewConnection, @applyPatch,
 
                @setStatus) ->
 
    @_patchesToSend = []
 
    @_lastPingMs = -1
 
    @_patchesReceived = 0
 
    @_patchesSent = 0
 

	
 
    @_connectionId = '??'
 
    @_reconnectionTimeout = null
 
    @_newConnection()
 

	
 
  _updateStatus: ->
 
    ws = (if not @ws? then 'no' else switch @ws.readyState
 
      when @ws.CONNECTING then 'connecting'
 
      when @ws.OPEN then 'open'
 
      when @ws.OPEN then "open as #{@_connectionId}"
 
      when @ws.CLOSING then 'closing'
 
      when @ws.CLOSED then 'close'
 
      )
 

	
 
    ping = if @_lastPingMs > 0 then @_lastPingMs else '...'
 
    @setStatus("#{ws};
 
@@ -118,14 +117,19 @@ class window.RdfDbClient
 
  _onMessage: (evt) ->
 
    msg = evt.data
 
    if msg == 'PONG'
 
      @_lastPingMs = Date.now() + @_lastPingMs
 
      @_updateStatus()
 
      return
 
    parseJsonPatch(msg, @applyPatch.bind(@))
 
    @_patchesReceived++
 
      
 
    input = JSON.parse(msg)
 
    if input.connectedAs
 
      @_connectionId = input.connectedAs
 
    else
 
      parseJsonPatch(input, @applyPatch.bind(@))
 
      @_patchesReceived++
 
    @_updateStatus()
 

	
 
  _continueSending: ->
 
    if @ws.readyState != @ws.OPEN
 
      setTimeout(@_continueSending.bind(@), 500)
 
      return
0 comments (0 inline, 0 general)