Finished support for new connector type
This commit is contained in:
40
bower_components/connector/.bower.json
vendored
Normal file
40
bower_components/connector/.bower.json
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "connector",
|
||||
"authors": [
|
||||
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"
|
||||
],
|
||||
"description": "Connect to other users via a generic connector. The interface is standardized, so you can use other connectors without changing your code.",
|
||||
"main": [
|
||||
"peerjs-connector/peerjs-connector.min.js",
|
||||
"peerjs-connector/peerjs-connector.html"
|
||||
],
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"peerjs"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"dependencies": {
|
||||
"polymer": "Polymer/polymer#~0.5.1"
|
||||
},
|
||||
"homepage": "https://github.com/DadaMonad/Connector",
|
||||
"_release": "35f8d81ce7",
|
||||
"_resolution": {
|
||||
"type": "branch",
|
||||
"branch": "master",
|
||||
"commit": "35f8d81ce73ecac317b3dd7fabf32a871a4926a6"
|
||||
},
|
||||
"_source": "git://github.com/DadaMonad/Connector.git",
|
||||
"_target": "*",
|
||||
"_originalSource": "DadaMonad/Connector",
|
||||
"_direct": true
|
||||
}
|
||||
13
bower_components/connector/README.md
vendored
Normal file
13
bower_components/connector/README.md
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
# Connector-Interface
|
||||
The idea is, to create different implementations of the Connector interface that enable communication within a group.
|
||||
It has a minimal interface and covers some frequently occuring problems thay you probably will encounter if you use communitcation protocols directly.
|
||||
|
||||
E.g. You can exchange the PeerJs-Connector with the XMPP-Connector only by changing few lines of code.
|
||||
|
||||
It is the communication interface used by [Yatta](https://github.com/DadaMonad/Yatta).
|
||||
|
||||
Currently we have interfaces for:
|
||||
* PeerJs
|
||||
|
||||
More information about the Connector interface will follow. (Trust the update frequency, this could be a lie)
|
||||
30
bower_components/connector/bower.json
vendored
Normal file
30
bower_components/connector/bower.json
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "connector",
|
||||
"version": "0.0.0",
|
||||
"authors": [
|
||||
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"
|
||||
],
|
||||
"description": "Connect to other users via a generic connector. The interface is standardized, so you can use other connectors without changing your code.",
|
||||
"main": [
|
||||
"peerjs-connector/peerjs-connector.min.js",
|
||||
"peerjs-connector/peerjs-connector.html"
|
||||
],
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"peerjs"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"dependencies": {
|
||||
"polymer": "Polymer/polymer#~0.5.1"
|
||||
}
|
||||
}
|
||||
50
bower_components/connector/gulpfile.coffee
vendored
Normal file
50
bower_components/connector/gulpfile.coffee
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
gulp = require 'gulp'
|
||||
coffee = require 'gulp-coffee'
|
||||
concat = require 'gulp-concat'
|
||||
uglify = require 'gulp-uglify'
|
||||
sourcemaps = require 'gulp-sourcemaps'
|
||||
plumber = require 'gulp-plumber'
|
||||
browserify = require 'gulp-browserify'
|
||||
rename = require 'gulp-rename'
|
||||
|
||||
paths =
|
||||
peerjs: ['./lib/peerjs-connector/**/*.coffee']
|
||||
test: ['./lib/test-connector/**/*.coffee']
|
||||
|
||||
|
||||
|
||||
buildConnector = (connector_name)->
|
||||
()->
|
||||
gulp.src(paths[connector_name], {read: false})
|
||||
.pipe(plumber())
|
||||
.pipe browserify
|
||||
transform: ['coffeeify']
|
||||
extensions: ['.coffee']
|
||||
debug: true
|
||||
.pipe rename
|
||||
extname: ".js"
|
||||
.pipe gulp.dest('./'+connector_name+'-connector')
|
||||
.pipe uglify()
|
||||
.pipe rename
|
||||
extname: ".min.js"
|
||||
.pipe gulp.dest('./'+connector_name+'-connector')
|
||||
|
||||
gulp.task 'peerjs', [], buildConnector 'peerjs'
|
||||
gulp.task 'test', [], buildConnector 'test'
|
||||
gulp.task 'build', ['peerjs','test']
|
||||
|
||||
# Rerun the task when a file changes
|
||||
gulp.task 'watch', ()->
|
||||
gulp.watch(paths.peerjs, ['peerjs'])
|
||||
gulp.watch(paths.test, ['test'])
|
||||
|
||||
gulp.task('default', ['watch', 'build'])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
77
bower_components/connector/lib/connector.coffee
vendored
Normal file
77
bower_components/connector/lib/connector.coffee
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
|
||||
class Connector
|
||||
|
||||
constructor: ()->
|
||||
# is set to true when this is synced with all other connections
|
||||
@is_synced = false
|
||||
# compute all of these functions when all connections are synced.
|
||||
@compute_when_synced = []
|
||||
# Peerjs Connections: key: conn-id, value: conn
|
||||
@connections = {}
|
||||
# Connections, that have been initialized, but have not been (fully) synced yet.
|
||||
@unsynced_connections = {}
|
||||
# List of functions that shall process incoming data
|
||||
@receive_handlers = []
|
||||
# A list of functions that are executed (left to right) when syncing with a peer.
|
||||
@sync_process_order = []
|
||||
|
||||
#
|
||||
# Execute a function _when_ we are connected. If not connected, wait until connected.
|
||||
# @param f {Function} Will be executed on the PeerJs-Connector context.
|
||||
#
|
||||
whenSynced: (args)->
|
||||
if @is_synced
|
||||
args[0].apply this, args[1..]
|
||||
else
|
||||
@compute_when_synced.push args
|
||||
|
||||
#
|
||||
# Execute an function _when_ a message is received.
|
||||
# @param f {Function} Will be executed on the PeerJs-Connector context. f will be called with (sender_id, broadcast {true|false}, message).
|
||||
#
|
||||
whenReceiving: (f)->
|
||||
@receive_handlers.push f
|
||||
|
||||
#
|
||||
# Send a message to a (sub)-set of all connected peers.
|
||||
# @param peers {Array<connection_ids>} A set of ids.
|
||||
# @param message {Object} The message to send.
|
||||
#
|
||||
multicast: (peers, message)->
|
||||
@whenSynced [_send, peers, message]
|
||||
|
||||
#
|
||||
# Send a message to one of the connected peers.
|
||||
# @param peers {connection_id} A connection id.
|
||||
# @param message {Object} The message to send.
|
||||
#
|
||||
unicast: (peer, message)->
|
||||
@whenSynced [_send, peer, message]
|
||||
|
||||
#
|
||||
# Broadcast a message to all connected peers.
|
||||
# @param message {Object} The message to broadcast.
|
||||
#
|
||||
broadcast: (message)->
|
||||
@whenSynced [()=>
|
||||
for peerid,peer of @connections
|
||||
@_send peerid, message]
|
||||
|
||||
#
|
||||
# Define how you want to handle the sync process of two users.
|
||||
# This is a synchronous handshake. Every user will perform exactly the same actions at the same time. E.g.
|
||||
# @example
|
||||
# whenSyncing(function(){ // first call must not have parameters!
|
||||
# return this.id; // Send the id of this connector.
|
||||
# },function(peerid){ // you receive the peerid of the other connections.
|
||||
# // you can do something with the peerid
|
||||
# // return "you are my friend"; // you could send another massage.
|
||||
# }); // this is the end of the sync process.
|
||||
#
|
||||
whenSyncing: ()->
|
||||
for i in [(arguments.length-1)..0]
|
||||
@sync_process_order.unshift arguments[i]
|
||||
|
||||
|
||||
|
||||
module.exports = Connector
|
||||
29
bower_components/connector/lib/peerjs-connector/peerjs-connector-polymer.coffee
vendored
Normal file
29
bower_components/connector/lib/peerjs-connector/peerjs-connector-polymer.coffee
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
new Polymer 'peerjs-connector',
|
||||
join: (id)->
|
||||
idChanged: (old_val,new_val)->
|
||||
if this.is_initialized
|
||||
throw new Error "You must not set the user_id twice!"
|
||||
else
|
||||
this.initializeConnection()
|
||||
|
||||
initializeConnection: ()->
|
||||
if this.conn_id?
|
||||
console.log("now initializing")
|
||||
options = {}
|
||||
writeIfAvailable = (name, value)->
|
||||
if value?
|
||||
options[name] = value
|
||||
writeIfAvailable 'key', this.key
|
||||
writeIfAvailable 'host', this.host
|
||||
writeIfAvailable 'port', this.port
|
||||
writeIfAvailable 'path', this.path
|
||||
writeIfAvailable 'secure', this.secure
|
||||
writeIfAvailable 'debug', this.debug
|
||||
this.is_initialized = true;
|
||||
this.connector = new PeerJsConnector this.conn_id, options
|
||||
|
||||
ready: ()->
|
||||
if this.conn_id != null
|
||||
this.initializeConnection()
|
||||
|
||||
108
bower_components/connector/lib/peerjs-connector/peerjs-connector.coffee
vendored
Normal file
108
bower_components/connector/lib/peerjs-connector/peerjs-connector.coffee
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
Connector = require '../connector'
|
||||
|
||||
window.PeerJsConnector = class PeerJsConnector extends Connector
|
||||
|
||||
constructor: (@id, options)->
|
||||
super()
|
||||
that = this
|
||||
# The following two functions should be performed at the end of the syncing process.
|
||||
# In peerjs all connection ids must be send.
|
||||
@sync_process_order.push ()->
|
||||
peers = for peerid,conn of that.connections
|
||||
peerid
|
||||
peers
|
||||
# Then connect to the connection ids.
|
||||
@sync_process_order.push (peers)->
|
||||
for peerid in peers
|
||||
that.join peerid
|
||||
true
|
||||
# Create the Peerjs instance
|
||||
@conn = new Peer @id, options
|
||||
# TODO: improve error handling, what happens if disconnected? provide feedback
|
||||
@conn.on 'error', (err)->
|
||||
throw new Error "Peerjs connector: #{err}"
|
||||
@conn.on 'disconnected', ()->
|
||||
throw new Error "Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either.."
|
||||
@conn.on 'disconnect', ()->
|
||||
that.conn.reconnect()
|
||||
@conn.on 'connection', @_addConnection
|
||||
|
||||
#
|
||||
# Join a communication room. In case of peerjs, you just have to join to one other client. This connector will join to the other peers automatically.
|
||||
# @param id {String} The connection id of another client.
|
||||
#
|
||||
join: (peerid)->
|
||||
if not @unsynced_connections[peerid]? and not @connections[peerid]? and peerid isnt @id
|
||||
peer = @conn.connect peerid, {reliable: true}
|
||||
@unsynced_connections[peerid] = peer
|
||||
@_addConnection peer
|
||||
true
|
||||
else
|
||||
false
|
||||
|
||||
#
|
||||
# Send a message to a peer or set of peers. This is peerjs specific.
|
||||
# @overload _send(peerid, message)
|
||||
# @param peerid {String} PeerJs connection id of _another_ peer
|
||||
# @param message {Object} Some object that shall be send
|
||||
# @overload _send(peerids, message)
|
||||
# @param peerids {Array<String>} PeerJs connection ids of _other_ peers
|
||||
# @param message {Object} Some object that shall be send
|
||||
#
|
||||
_send: (peer_s, message)->
|
||||
if peer_s.constructor is [].constructor
|
||||
# Throw errors _after_ the message has been send to all other peers.
|
||||
# Just in case a connection is invalid.
|
||||
errors = []
|
||||
for peer in peer_s
|
||||
try
|
||||
@connection[peer].send message
|
||||
catch error
|
||||
errors.push(error+"")
|
||||
if errors.length > 0
|
||||
throw new Error errors
|
||||
else
|
||||
@connections[peer_s].send message
|
||||
|
||||
#
|
||||
# @private
|
||||
# This is a helper function that is only related to the peerjs connector.
|
||||
# Connect to another peer.
|
||||
_addConnection: (peer)=>
|
||||
peer.on 'open', ()=>
|
||||
that = @
|
||||
peer.send that.sync_process_order[0]()
|
||||
current_sync_i = 1
|
||||
peer.on 'data', (data)->
|
||||
console.log("receive data: #{JSON.stringify data}")
|
||||
if current_sync_i < that.sync_process_order.length
|
||||
peer.send that.sync_process_order[current_sync_i++].call that, data
|
||||
else if current_sync_i is that.sync_process_order.length
|
||||
# All sync functions have been called. Increment current_sync_i one last time
|
||||
current_sync_i++
|
||||
# add it to the connections object
|
||||
delete that.unsynced_connections[peer.peer]
|
||||
that.connections[peer.peer] = peer
|
||||
# when the conn closes, delete it from the connections object
|
||||
peer.on 'close', ()->
|
||||
delete that.connections[peer.peer]
|
||||
# helper fkt. true iff os is an object that does not hold enumerable properties
|
||||
isEmpty = (os)->
|
||||
for o of os
|
||||
return false
|
||||
return true
|
||||
if isEmpty(that.unsynced_connections)
|
||||
# there are no unsynced connections. we are now synced.
|
||||
# therefore execute all fkts in this.compute_when_synced
|
||||
that.is_synced = true
|
||||
for comp in that.compute_when_synced
|
||||
comp[0].apply that, comp[1..]
|
||||
that.compute_when_synced = []
|
||||
else
|
||||
# you received a new message, that is not a sync message.
|
||||
# notify the receive_handlers
|
||||
for f in that.receive_handlers
|
||||
f peer.peer, data
|
||||
|
||||
|
||||
|
||||
98
bower_components/connector/lib/test-connector/test-connector.coffee
vendored
Normal file
98
bower_components/connector/lib/test-connector/test-connector.coffee
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
|
||||
_ = require "underscore"
|
||||
Connector = require '../connector'
|
||||
|
||||
#
|
||||
# A trivial Connector that simulates network delay.
|
||||
#
|
||||
class TestConnector extends Connector
|
||||
|
||||
#
|
||||
# @param id {String} Some unique id
|
||||
# @param user_connectors {Array<TestConnector>} List of TestConnectors instances
|
||||
#
|
||||
constructor: (@id)->
|
||||
super()
|
||||
# If you think of operations, this will mirror the
|
||||
# execiton order of operations (when a message is send, or received it is put into this)
|
||||
@execution_order = []
|
||||
# The messages are buffered under the name of teh sending user.
|
||||
@receive_buffer = {}
|
||||
@connections = {}
|
||||
|
||||
@whenReceiving (user, message)=>
|
||||
@execution_order.push message
|
||||
@is_synced = true
|
||||
|
||||
# join another user connector
|
||||
join: (conn)->
|
||||
@_addConnection conn.id, conn
|
||||
for cid,c of conn.connections
|
||||
@_addConnection cid, c
|
||||
for comp in @compute_when_synced
|
||||
comp[0].apply @, comp[1..]
|
||||
|
||||
|
||||
#
|
||||
# @private
|
||||
# This is a helper function that is only related to the peerjs connector.
|
||||
# Connect to another peer.
|
||||
_addConnection: (id, user_connector)->
|
||||
if not @connections[id]? and id isnt @id
|
||||
data = null
|
||||
user_data = null
|
||||
for i in [0...@sync_process_order.length]
|
||||
data_ = @sync_process_order[i].call @, user_data
|
||||
user_data = user_connector.sync_process_order[i].call user_connector, data
|
||||
data = data_
|
||||
@connections[id]=user_connector
|
||||
user_connector.connections[@id] = @
|
||||
|
||||
#
|
||||
# Get the ops in the execution order.
|
||||
#
|
||||
getOpsInExecutionOrder: ()->
|
||||
@execution_order
|
||||
|
||||
#
|
||||
# Send a message to another peer
|
||||
# @param {Operation} o The operation that was executed.
|
||||
#
|
||||
_send: (uid, message)->
|
||||
rb = @connections[uid].receive_buffer
|
||||
rb[@id] ?= []
|
||||
rb[@id].push message
|
||||
|
||||
#
|
||||
# Flush one operation from the line of a specific user.
|
||||
#
|
||||
flushOne: (uid)->
|
||||
if @receive_buffer[uid]?.length > 0
|
||||
message = @receive_buffer[uid].shift()
|
||||
for f in @receive_handlers
|
||||
f uid, message
|
||||
|
||||
#
|
||||
# Flush one operation on a random line.
|
||||
#
|
||||
flushOneRandom: ()->
|
||||
connlist = for cid,c of @receive_buffer
|
||||
cid
|
||||
@flushOne connlist[(_.random 0, (connlist.length-1))]
|
||||
|
||||
#
|
||||
# Flush all operations on every line.
|
||||
#
|
||||
flushAll: ()->
|
||||
for n,messages of @receive_buffer
|
||||
for message in messages
|
||||
for f in @receive_handlers
|
||||
f n, message
|
||||
@receive_buffer = {}
|
||||
|
||||
|
||||
if window?
|
||||
window.TestConnector = TestConnector
|
||||
|
||||
if module?
|
||||
module.exports = TestConnector
|
||||
29
bower_components/connector/package.json
vendored
Normal file
29
bower_components/connector/package.json
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "connector",
|
||||
"version": "0.0.0",
|
||||
"description": "Connect to other users via a generic interface. The interface is standardized, so you can use other connectors without changing your code. ",
|
||||
"main": "peerjs-connector/peerjs-connector.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
"peerjs"
|
||||
],
|
||||
"author": "Kevin Jahns <kevin.jahns@rwth-aachen.de>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"peerjs": "~0.3.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp-sourcemaps": "~1.2.8",
|
||||
"gulp-concat": "~2.4.1",
|
||||
"gulp-coffee": "~2.2.0",
|
||||
"gulp-uglify": "~1.0.1",
|
||||
"gulp": "~3.8.10",
|
||||
"coffee-script": "~1.8.0",
|
||||
"gulp-plumber": "~0.6.6",
|
||||
"gulp-browserify": "~0.5.0",
|
||||
"coffeeify": "~1.0.0",
|
||||
"underscore": "~1.7.0"
|
||||
}
|
||||
}
|
||||
41
bower_components/connector/peerjs-connector/peerjs-connector-polymer.js
vendored
Normal file
41
bower_components/connector/peerjs-connector/peerjs-connector-polymer.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
new Polymer('peerjs-connector', {
|
||||
join: function(id) {},
|
||||
idChanged: function(old_val, new_val) {
|
||||
if (this.is_initialized) {
|
||||
throw new Error("You must not set the user_id twice!");
|
||||
} else {
|
||||
return this.initializeConnection();
|
||||
}
|
||||
},
|
||||
initializeConnection: function() {
|
||||
var options, writeIfAvailable;
|
||||
if (this.conn_id != null) {
|
||||
console.log("now initializing");
|
||||
options = {};
|
||||
writeIfAvailable = function(name, value) {
|
||||
if (value != null) {
|
||||
return options[name] = value;
|
||||
}
|
||||
};
|
||||
writeIfAvailable('key', this.key);
|
||||
writeIfAvailable('host', this.host);
|
||||
writeIfAvailable('port', this.port);
|
||||
writeIfAvailable('path', this.path);
|
||||
writeIfAvailable('secure', this.secure);
|
||||
writeIfAvailable('debug', this.debug);
|
||||
this.is_initialized = true;
|
||||
return this.connector = new PeerJsConnector(this.conn_id, options);
|
||||
}
|
||||
},
|
||||
ready: function() {
|
||||
if (this.conn_id !== null) {
|
||||
return this.initializeConnection();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
},{}]},{},[1])
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjoz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G4gICAgICB3cml0ZUlmQXZhaWxhYmxlICdwYXRoJywgdGhpcy5wYXRoXG4gICAgICB3cml0ZUlmQXZhaWxhYmxlICdzZWN1cmUnLCB0aGlzLnNlY3VyZVxuICAgICAgd3JpdGVJZkF2YWlsYWJsZSAnZGVidWcnLCB0aGlzLmRlYnVnXG4gICAgICB0aGlzLmlzX2luaXRpYWxpemVkID0gdHJ1ZTtcbiAgICAgIHRoaXMuY29ubmVjdG9yID0gbmV3IFBlZXJKc0Nvbm5lY3RvciB0aGlzLmNvbm5faWQsIG9wdGlvbnNcbiAgICBcbiAgcmVhZHk6ICgpLT5cbiAgICBpZiB0aGlzLmNvbm5faWQgIT0gbnVsbFxuICAgICAgdGhpcy5pbml0aWFsaXplQ29ubmVjdGlvbigpXG4gIFxuIl19
|
||||
1
bower_components/connector/peerjs-connector/peerjs-connector-polymer.min.js
vendored
Normal file
1
bower_components/connector/peerjs-connector/peerjs-connector-polymer.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function i(n,t,e){function r(u,s){if(!t[u]){if(!n[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(o)return o(u,!0);throw new Error("Cannot find module '"+u+"'")}var h=t[u]={exports:{}};n[u][0].call(h.exports,function(i){var t=n[u][1][i];return r(t?t:i)},h,h.exports,i,n,t,e)}return t[u].exports}for(var o="function"==typeof require&&require,u=0;u<e.length;u++)r(e[u]);return r}({1:[function(){new Polymer("peerjs-connector",{join:function(){},idChanged:function(){if(this.is_initialized)throw new Error("You must not set the user_id twice!");return this.initializeConnection()},initializeConnection:function(){var i,n;return null!=this.conn_id?(console.log("now initializing"),i={},n=function(n,t){return null!=t?i[n]=t:void 0},n("key",this.key),n("host",this.host),n("port",this.port),n("path",this.path),n("secure",this.secure),n("debug",this.debug),this.is_initialized=!0,this.connector=new PeerJsConnector(this.conn_id,i)):void 0},ready:function(){return null!==this.conn_id?this.initializeConnection():void 0}})},{}]},{},[1]);
|
||||
10
bower_components/connector/peerjs-connector/peerjs-connector.html
vendored
Normal file
10
bower_components/connector/peerjs-connector/peerjs-connector.html
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<link rel="import" href="../bower_components/polymer/polymer.html">
|
||||
|
||||
<polymer-element name="peerjs-connector" hidden attributes="conn_id connector key host port path secure debug">
|
||||
<script src="../bower_components/peerjs/peer.min.js"></script>
|
||||
<script src="./peerjs-connector.js"></script>
|
||||
<template>
|
||||
</template>
|
||||
<script src="./peerjs-connector-polymer.min.js"></script>
|
||||
|
||||
</polymer-element>
|
||||
211
bower_components/connector/peerjs-connector/peerjs-connector.js
vendored
Normal file
211
bower_components/connector/peerjs-connector/peerjs-connector.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
bower_components/connector/peerjs-connector/peerjs-connector.min.js
vendored
Normal file
1
bower_components/connector/peerjs-connector/peerjs-connector.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function n(e,t,r){function o(i,s){if(!t[i]){if(!e[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(c)return c(i,!0);throw new Error("Cannot find module '"+i+"'")}var h=t[i]={exports:{}};e[i][0].call(h.exports,function(n){var t=e[i][1][n];return o(t?t:n)},h,h.exports,n,e,t,r)}return t[i].exports}for(var c="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(n,e){var t;t=function(){function n(){this.is_synced=!1,this.compute_when_synced=[],this.connections={},this.unsynced_connections={},this.receive_handlers=[],this.sync_process_order=[]}return n.prototype.whenSynced=function(n){return this.is_synced?n[0].apply(this,n.slice(1)):this.compute_when_synced.push(n)},n.prototype.whenReceiving=function(n){return this.receive_handlers.push(n)},n.prototype.multicast=function(n,e){return this.whenSynced([_send,n,e])},n.prototype.unicast=function(n,e){return this.whenSynced([_send,n,e])},n.prototype.broadcast=function(n){return this.whenSynced([function(e){return function(){var t,r,o,c;o=e.connections,c=[];for(r in o)t=o[r],c.push(e._send(r,n));return c}}(this)])},n.prototype.whenSyncing=function(){var n,e,t,r;for(r=[],n=e=t=arguments.length-1;0>=t?0>=e:e>=0;n=0>=t?++e:--e)r.push(this.sync_process_order.unshift(arguments[n]));return r},n}(),e.exports=t},{}],2:[function(n){var e,t,r=function(n,e){return function(){return n.apply(e,arguments)}},o={}.hasOwnProperty,c=function(n,e){function t(){this.constructor=n}for(var r in e)o.call(e,r)&&(n[r]=e[r]);return t.prototype=e.prototype,n.prototype=new t,n.__super__=e.prototype,n};e=n("../connector"),window.PeerJsConnector=t=function(n){function e(n,t){var o;this.id=n,this._addConnection=r(this._addConnection,this),e.__super__.constructor.call(this),o=this,this.sync_process_order.push(function(){var n,e,t;return t=function(){var t,r;t=o.connections,r=[];for(e in t)n=t[e],r.push(e);return r}()}),this.sync_process_order.push(function(n){var e,t,r;for(t=0,r=n.length;r>t;t++)e=n[t],o.join(e);return!0}),this.conn=new Peer(this.id,t),this.conn.on("error",function(n){throw new Error("Peerjs connector: "+n)}),this.conn.on("disconnected",function(){throw new Error("Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either..")}),this.conn.on("disconnect",function(){return o.conn.reconnect()}),this.conn.on("connection",this._addConnection)}return c(e,n),e.prototype.join=function(n){var e;return null==this.unsynced_connections[n]&&null==this.connections[n]&&n!==this.id?(e=this.conn.connect(n,{reliable:!0}),this.unsynced_connections[n]=e,this._addConnection(e),!0):!1},e.prototype._send=function(n,e){var t,r,o,c,i;if(n.constructor!==[].constructor)return this.connections[n].send(e);for(r=[],c=0,i=n.length;i>c;c++){o=n[c];try{this.connection[o].send(e)}catch(s){t=s,r.push(t+"")}}if(r.length>0)throw new Error(r)},e.prototype._addConnection=function(n){return n.on("open",function(e){return function(){var t,r;return r=e,n.send(r.sync_process_order[0]()),t=1,n.on("data",function(e){var o,c,i,s,u,h,p,f,d,a;if(console.log("receive data: "+JSON.stringify(e)),t<r.sync_process_order.length)return n.send(r.sync_process_order[t++].call(r,e));if(t!==r.sync_process_order.length){for(d=r.receive_handlers,a=[],u=0,p=d.length;p>u;u++)c=d[u],a.push(c(n.peer,e));return a}if(t++,delete r.unsynced_connections[n.peer],r.connections[n.peer]=n,n.on("close",function(){return delete r.connections[n.peer]}),(i=function(n){var e;for(e in n)return!1;return!0})(r.unsynced_connections)){for(r.is_synced=!0,f=r.compute_when_synced,s=0,h=f.length;h>s;s++)o=f[s],o[0].apply(r,o.slice(1));return r.compute_when_synced=[]}})}}(this))},e}(e)},{"../connector":1}]},{},[2]);
|
||||
1617
bower_components/connector/test-connector/test-connector.js
vendored
Normal file
1617
bower_components/connector/test-connector/test-connector.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
bower_components/connector/test-connector/test-connector.min.js
vendored
Normal file
1
bower_components/connector/test-connector/test-connector.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user