Fixed iwc, update problem
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
#
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user