Log and report events like sending and receiving updates

This commit is contained in:
James Allen 2014-03-31 13:30:47 +01:00
parent 81cb986f89
commit 869a4c8c18
3 changed files with 34 additions and 12 deletions

View file

@ -81,6 +81,12 @@ define [
delete @_joinCallbacks delete @_joinCallbacks
_onUpdateApplied: (update) -> _onUpdateApplied: (update) ->
@ide.pushEvent "received-update",
doc_id: @doc_id
remote_doc_id: update?.doc
wantToBeJoined: @wantToBeJoined
update: update
if update?.doc == @doc_id and @doc? if update?.doc == @doc_id and @doc?
@doc.processUpdateFromServer update @doc.processUpdateFromServer update
@ -93,6 +99,8 @@ define [
@doc?.updateConnectionState "disconnected" @doc?.updateConnectionState "disconnected"
_onReconnect: () -> _onReconnect: () ->
@ide.pushEvent "reconnected:afterJoinProject"
@connected = true @connected = true
if @wantToBeJoined or @doc?.hasBufferedOps() if @wantToBeJoined or @doc?.hasBufferedOps()
@_joinDoc (error) => @_joinDoc (error) =>
@ -137,10 +145,22 @@ define [
_bindToShareJsDocEvents: () -> _bindToShareJsDocEvents: () ->
@doc.on "error", (error, meta) => @_onError error, meta @doc.on "error", (error, meta) => @_onError error, meta
@doc.on "externalUpdate", () => @trigger "externalUpdate" @doc.on "externalUpdate", () =>
@doc.on "remoteop", () => @trigger "remoteop" @ide.pushEvent "externalUpdate",
@doc.on "op:sent", () => @trigger "op:sent" doc_id: @doc_id
@doc.on "op:acknowledged", () => @trigger "op:acknowledged" @trigger "externalUpdate"
@doc.on "remoteop", () =>
@ide.pushEvent "remoteop",
doc_id: @doc_id
@trigger "remoteop"
@doc.on "op:sent", () =>
@ide.pushEvent "op:sent",
doc_id: @doc_id
@trigger "op:sent"
@doc.on "op:acknowledged", () =>
@ide.pushEvent "op:acknowledged",
doc_id: @doc_id
@trigger "op:acknowledged"
_onError: (error, meta = {}) -> _onError: (error, meta = {}) ->
console.error "ShareJS error", error, meta console.error "ShareJS error", error, meta

View file

@ -161,14 +161,18 @@ define [
buttons: [ text: "OK" ] buttons: [ text: "OK" ]
} }
recentEvents: []
pushEvent: (type, meta = {}) ->
@recentEvents.push type: type, meta: meta, date: new Date()
if @recentEvents.length > 10
@recentEvents.shift()
reportError: (error, meta = {}) -> reportError: (error, meta = {}) ->
meta.client_id = @socket?.socket?.sessionid meta.client_id = @socket?.socket?.sessionid
meta.transport = @socket?.socket?.transport?.name meta.transport = @socket?.socket?.transport?.name
meta.client_now = new Date() meta.client_now = new Date()
meta.last_connected = @connectionManager.lastConnected meta.recent_events = @recentEvents
meta.second_last_connected = @connectionManager.secondLastConnected
meta.last_disconnected = @connectionManager.lastDisconnected
meta.second_last_disconnected = @connectionManager.secondLastDisconnected
errorObj = {} errorObj = {}
for key in Object.getOwnPropertyNames(error) for key in Object.getOwnPropertyNames(error)
errorObj[key] = error[key] errorObj[key] = error[key]

View file

@ -8,15 +8,13 @@ define [
@socket = @ide.socket @socket = @ide.socket
@socket.on "connect", () => @socket.on "connect", () =>
@connected = true @connected = true
@secondLastConnected = @lastConnected @ide.pushEvent("connected")
@lastConnected = new Date()
@hideModal() @hideModal()
@cancelReconnect() @cancelReconnect()
@socket.on 'disconnect', () => @socket.on 'disconnect', () =>
@connected = false @connected = false
@secondLastDisconnected = @lastDisconnected @ide.pushEvent("disconnected")
@lastDisconnected = new Date()
@ide.trigger "disconnect" @ide.trigger "disconnect"
setTimeout(=> setTimeout(=>
ga('send', 'event', 'editor-interaction', 'disconnect') ga('send', 'event', 'editor-interaction', 'disconnect')