1 line
4.2 KiB
Plaintext
Executable File
1 line
4.2 KiB
Plaintext
Executable File
{"version":3,"file":"Connectors/PeerJsConnector.js","sources":["Connectors/PeerJsConnector.coffee"],"names":[],"mappings":"CAIA,WAAA,GAAA,EAAA,GAAwB,SAAC,GAEvB,GAAA,GAAA,QAAA,GAAW,GAAA,OAAM,IAAK,oBAKhB,EAAA,WAQS,QAAA,GAAE,EAAS,EAAK,EAAqB,GAEhD,GAAA,EAFY,MAAC,OAAA,EAAQ,KAAC,GAAA,EAAI,KAAC,mBAAA,EAAoB,KAAC,MAAA,EAEhD,KAAC,KAAO,EACR,KAAC,eAED,KAAC,KAAK,GAAG,aAAc,SAAA,SAAA,UAAC,SACtB,GAAK,KAAK,OACV,EAAC,cAAc,KAFM,OAIvB,EAAQ,SAAA,SAAA,UAAC,SACP,GAAC,KAAK,KADA,MAER,KAAC,mBAAmB,KAAK,SAX3B,GAAA,UAaA,cAAe,SAAC,GACd,MAAO,OAAA,KAAA,YAAA,IAAsB,IAAQ,KAAC,MAAM,YAC1C,KAAC,cAAc,EAAK,QAAQ,IAD9B,QAdF,EAAA,UAiBA,oBAAqB,WACnB,GAAA,GAAA,CAAA,UAAA,IAAA,MAAA,YACE,EAAA,KAAA,aAnBJ,EAAA,UAqBA,cAAe,SAAC,GACd,GAAA,SAAA,MAAC,YAAY,EAAK,MAAQ,EAE1B,EAAK,GAAG,OAAQ,SAAA,SAAA,UAAC,GACf,GAAA,GAAA,EAAA,EAAA,EAAA,CAAA,IAAW,QAAR,QACD,SAAQ,IAAI,uDACT,IAAG,MAAA,EAAA,SACN,GAAC,OAAO,oBAAoB,EAAK,GAC9B,IAAG,MAAA,EAAA,SACN,GAAC,OAAO,QAAQ,EAAK,GAClB,IAAG,MAAA,EAAA,MAAH,KACH,EAAA,EAAA,MAAA,KAAA,EAAA,EAAA,EAAA,EAAA,OAAA,EAAA,EAAA,WACE,EAAA,KAAA,EAAC,cAAc,aAEjB,KAAU,IAAA,OAAM,gCAXJ,OAahB,EAAS,SAAA,SAAA,kBACP,GAAK,MACH,GAAI,EAAC,MAAM,mBAAmB,YAChC,EAAK,MACH,MAAO,EAAC,0BAJH,MAMT,WAAW,EAAQ,MA3CrB,EAAA,UAiDA,KAAM,SAAC,GACL,GAAA,GAAA,EAAA,EAAA,CAAA,IAAG,EAAE,IAAI,UAAW,KAAC,GAAG,aAA6C,gBAA5B,GAAS,IAAI,UAAtD,CACE,EAAA,KAAA,YAAA,SAAA,IAAA,UACE,EAAA,KAAA,EAAK,MACH,GAAI,gBArDZ,EAAA,UA2DA,QAAS,SAAC,GACR,MAAG,GAAE,IAAI,UAAa,KAAC,GAAG,YACxB,KAAC,OAAO,QAAQ,GADlB,aAGJ,EAAK,GAAG,OAAQ,SAAC,SACf,GAAS,EAAiB,MAG9B,OAAO,QAAU,EACd,mBAAA,SAAA,OAAA,SACM,MAAA,OAAA,IACL,OAAO,MACT,OAAO,EAAE,sBAAwB","sourcesContent":["\n#\n# @param {Function} callback The callback is called when the connector is initialized.\n#\ncreatePeerJsConnector = (callback)->\n\n peer = new Peer {key: 'h7nlefbgavh1tt9'}\n\n #\n # @see http://peerjs.com\n #\n class PeerJsConnector\n\n #\n # @param {Engine} engine The transformation engine\n # @param {HistoryBuffer} HB\n # @param {Array<Function>} execution_listener You must ensure that whenever an operation is executed, every function in this Array is called.\n # @param {Yatta} yatta The Yatta framework.\n #\n constructor: (@engine, @HB, @execution_listener, @yatta)->\n\n @peer = peer\n @connections = {}\n\n @peer.on 'connection', (conn)=>\n conn.send \"hey\" # is never send. But without it it won't work either..\n @addConnection conn\n\n send_ = (o)=>\n @send o\n @execution_listener.push send_\n\n connectToPeer: (id)->\n if not @connections[id]? and id isnt @yatta.getUserId()\n @addConnection peer.connect id\n\n getAllConnectionIds: ()->\n for conn_id of @connections\n conn_id\n\n addConnection: (conn)->\n @connections[conn.peer] = conn\n\n conn.on 'data', (data)=>\n if data is \"hey\"\n console.log \"Yatta: Connection received with init message (debug)\" # I can remove this hey stuff when this happens.\n else if data.HB?\n @engine.applyOpsCheckDouble data.HB\n else if data.op?\n @engine.applyOp data.op\n else if data.conns?\n for conn_id in data.conns\n @connectToPeer conn_id\n else\n throw new Error \"Can't parse this operation\"\n\n sendHB = ()=>\n conn.send\n HB: @yatta.getHistoryBuffer()._encode()\n conn.send\n conns: @getAllConnectionIds()\n\n setTimeout sendHB, 1000\n\n #\n # This function is called whenever an operation was executed.\n # @param {Operation} o The operation that was executed.\n #\n send: (o)->\n if o.uid.creator is @HB.getUserId() and (typeof o.uid.op_number isnt \"string\")\n for conn_id,conn of @connections\n conn.send\n op: o\n\n #\n # This function is called whenever an operation was received from another peer.\n # @param {Operation} o The operation that was received.\n #\n receive: (o)->\n if o.uid.creator isnt @HB.getUserId()\n @engine.applyOp o\n\n peer.on 'open', (id)->\n callback PeerJsConnector, id\n\n\nmodule.exports = createPeerJsConnector\nif window?\n if not window.Y?\n window.Y = {}\n window.Y.createPeerJsConnector = createPeerJsConnector\n\n"],"sourceRoot":"/source/"} |