Fixed iwc, update problem

This commit is contained in:
Kevin Jahns
2014-08-14 19:33:10 +02:00
parent 6bbee4ef40
commit 089ae137dc
53 changed files with 265 additions and 419 deletions

View File

@@ -8,8 +8,6 @@ createIwcConnector = (callback, initial_user_id)->
duiClient = new DUIClient()
#@duiClient = new iwc.Client()
duiClient.connect (intent)->
#console.log "intent received iwc: #{JSON.stringify(intent)}"
#console.log "#{JSON.stringify(@iwcHandler)}"
iwcHandler[intent.action]?.map (f)->
setTimeout ()->
f intent
@@ -40,6 +38,12 @@ createIwcConnector = (callback, initial_user_id)->
@send o
@execution_listener.push send_
receiveHB = (json)=>
HB = json?.extras.HB
this.engine.applyOpsCheckDouble HB
iwcHandler["Yatta_push_HB_element"] = [receiveHB]
receive_ = (intent)=>
o = intent.extras
@receive o
@@ -94,26 +98,22 @@ createIwcConnector = (callback, initial_user_id)->
flags: ["PUBLISH_GLOBAL"]
extras: {}
init = ()->
send_get_HB_intent = ()->
duiClient.sendIntent(get_HB_intent)
is_initialized = false
receiveHB = (json)->
proposed_user_id = null
if initial_user_id?
proposed_user_id = initial_user_id
else
proposed_user_id = duiClient.getIwcClient()._componentName
received_HB = json?.extras.HB
if not is_initialized
is_initialized = true
callback IwcConnector, proposed_user_id
iwcHandler["Yatta_push_HB_element"] = [receiveHB]
setTimeout receiveHB, 4000
init = ()->
setTimeout send_get_HB_intent, 1000
proposed_user_id = null
if initial_user_id?
proposed_user_id = initial_user_id
else
# proposed_user_id = duiClient.getIwcClient()._componentName #TODO: This is stupid! why can't i use this?
proposed_user_id = Math.floor(Math.random()*1000000)
callback IwcConnector, proposed_user_id
setTimeout init, (1000)
undefined
module.exports = createIwcConnector
window?.createConnector = createIwcConnector
window?.createIwcConnector = createIwcConnector

View File

@@ -23,11 +23,12 @@ createPeerJsConnector = (callback)->
@connections = []
@peer.on 'connection', (conn)=>
console.log "received conn"
conn.send "hey"
@addConnection conn
send_ = (o)=>
@send o
@execution_listener.push send_
@@ -39,8 +40,8 @@ createPeerJsConnector = (callback)->
@connections.push conn
conn.on 'data', (data)=>
console.log "data: #{data}"
if data.HB?
if data is "hey"
else if data.HB?
@engine.applyOpsCheckDouble data.HB
else if data.op?
@engine.applyOp data.op
@@ -48,7 +49,6 @@ createPeerJsConnector = (callback)->
throw new Error "Can't parse this operation"
sendHB = ()=>
console.log "sending..."
conn.send
HB: @yatta.getHistoryBuffer()._encode()
setTimeout sendHB, 1000
@@ -59,9 +59,7 @@ createPeerJsConnector = (callback)->
#
send: (o)->
if o.uid.creator is @HB.getUserId() and (typeof o.uid.op_number isnt "string")
console.log "trying to send ops"
for conn in @connections
console.log "sent op"
conn.send
op: o
@@ -74,7 +72,6 @@ createPeerJsConnector = (callback)->
@engine.applyOp o
peer.on 'open', (id)->
console.log id
callback PeerJsConnector, id

View File

@@ -42,7 +42,7 @@ class Engine
#
applyOpsCheckDouble: (ops_json)->
for o in ops_json
if @HB.getOperation(o.uid)?
if not @HB.getOperation(o.uid)?
@applyOp o
#

View File

@@ -308,7 +308,7 @@ module.exports = (HB)->
@prev_cl.next_cl = @
@next_cl.prev_cl = @
super # notify the execution_listeners
@
#
# Defines an object that is cannot be changed. You can use this to set an immutable string, or a number.

View File

@@ -264,7 +264,6 @@ module.exports = (HB)->
else
@content.setReplaceManager?(@parent)
super
@
#
# Encode this operation in such a way that it can be parsed by remote peers.