added dist branch
This commit is contained in:
parent
9fd7d890a1
commit
f59d8a1ec3
14 changed files with 5 additions and 26359 deletions
4
.gitmodules
vendored
Normal file
4
.gitmodules
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
[submodule "dist"]
|
||||
path = dist
|
||||
url = https://github.com/y-js/y-webrtc.git
|
||||
branch = dist
|
21
LICENSE.txt
21
LICENSE.txt
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Kevin Jahns <kevin.jahns@rwth-aachen.de>.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +0,0 @@
|
|||
|
||||
<polymer-element name="y-webrtc" hidden attributes="connector room debug">
|
||||
<template>
|
||||
</template>
|
||||
<script src="./y-webrtc-polymer.js"></script>
|
||||
</polymer-element>
|
File diff suppressed because one or more lines are too long
|
@ -1,20 +0,0 @@
|
|||
var WebRTC = require('./y-webrtc');
|
||||
|
||||
new Polymer('y-webrtc',{
|
||||
ready: function(){
|
||||
this.is_initialized = false;
|
||||
this.initialize();
|
||||
},
|
||||
initialize: function(){
|
||||
if(!this.is_initialized && this.room !== undefined){
|
||||
this.is_initialized = true;
|
||||
this.connector = new WebRTC(this.room);
|
||||
if(this.debug !== undefined){
|
||||
this.connector.debug = this.debug;
|
||||
}
|
||||
}
|
||||
},
|
||||
roomChanged: function(){
|
||||
this.initialize();
|
||||
}
|
||||
});
|
|
@ -1,123 +0,0 @@
|
|||
|
||||
var SimpleWebRTC = require('simplewebrtc');
|
||||
|
||||
function WebRTC(room, webrtc_options){
|
||||
if(webrtc_options === undefined){
|
||||
webrtc_options = {};
|
||||
}
|
||||
|
||||
// connect per default to our server
|
||||
if(webrtc_options.url === undefined){
|
||||
webrtc_options.url = "https://yatta.ninja:8888";
|
||||
}
|
||||
|
||||
var swr = new SimpleWebRTC(webrtc_options);
|
||||
this.swr = swr;
|
||||
var self = this;
|
||||
|
||||
var channel;
|
||||
|
||||
swr.once('connectionReady',function(user_id){
|
||||
// SimpleWebRTC (swr) is initialized
|
||||
swr.joinRoom(room);
|
||||
|
||||
swr.once('joinedRoom', function(){
|
||||
// the client joined the specified room
|
||||
var when_bound_to_y = function(){
|
||||
// when the connector is bound to Y,
|
||||
// e.g. by creating a new instance of Y,
|
||||
// initialize the connector with the required parameters.
|
||||
// You always should specify `role`, `syncMethod`, and `user_id`
|
||||
self.init({
|
||||
role : "slave",
|
||||
syncMethod : "syncAll",
|
||||
user_id : user_id
|
||||
});
|
||||
var i;
|
||||
// notify the connector class about all the users that already
|
||||
// joined the session
|
||||
for(i in self.swr.webrtc.peers){
|
||||
self.userJoined(self.swr.webrtc.peers[i].id, "slave");
|
||||
}
|
||||
};
|
||||
|
||||
if(self.is_bound_to_y){
|
||||
// The connector is already bound to Y, so we can execute
|
||||
// `when_bound_to_y` immediately
|
||||
when_bound_to_y();
|
||||
} else {
|
||||
// The connector has not yet been bound to Y
|
||||
self.on_bound_to_y = when_bound_to_y;
|
||||
}
|
||||
|
||||
swr.on("channelMessage", function(peer, room, message){
|
||||
// The client received a message
|
||||
// Check if the connector is already initialized,
|
||||
// only then forward the message to the connector class
|
||||
if(self.is_initialized && message.type === "yjs"){
|
||||
self.receiveMessage(peer.id, message.payload);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
swr.on("createdPeer", function(peer){
|
||||
// a new peer/client joined the session.
|
||||
// Notify the connector class, if the connector
|
||||
// is already initialized
|
||||
if(self.is_initialized){
|
||||
// note: Since the WebRTC Connector only supports the SyncAll
|
||||
// syncmethod, every client is a slave.
|
||||
self.userJoined(peer.id, "slave");
|
||||
}
|
||||
});
|
||||
|
||||
swr.on("peerStreamRemoved",function(peer){
|
||||
// a client left the session.
|
||||
// Notify the connector class, if the connector
|
||||
// is already initialized
|
||||
if(self.is_initialized){
|
||||
self.userLeft(peer.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Specify how to send a message to a specific user (by uid)
|
||||
WebRTC.prototype.send = function(uid, message){
|
||||
var self = this;
|
||||
// we have to make sure that the message is sent under all circumstances
|
||||
var send = function(){
|
||||
// check if the clients still exists
|
||||
var peer = self.swr.webrtc.getPeers(uid)[0];
|
||||
var success;
|
||||
if(peer){
|
||||
// success is true, if the message is successfully sent
|
||||
success = peer.sendDirectly("simplewebrtc", "yjs", message);
|
||||
}
|
||||
if(!success){
|
||||
// resend the message if it didn't work
|
||||
window.setTimeout(send,500);
|
||||
}
|
||||
};
|
||||
// try to send the message
|
||||
send();
|
||||
};
|
||||
|
||||
// specify how to broadcast a message to all users
|
||||
// (it may send the message back to itself).
|
||||
// The webrtc connecor tries to send it to every single clients directly
|
||||
WebRTC.prototype.broadcast = function(message){
|
||||
this.swr.sendDirectlyToAll("simplewebrtc","yjs",message);
|
||||
};
|
||||
|
||||
if(window !== undefined){
|
||||
if(window.Y !== undefined){
|
||||
window.Y.WebRTC = WebRTC;
|
||||
} else {
|
||||
console.err("You must first include Y, and then the WebRTC Connector!");
|
||||
}
|
||||
}
|
||||
if(module !== undefined){
|
||||
module.exports = WebRTC;
|
||||
}
|
||||
|
1
dist
Submodule
1
dist
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit bbacd36b0b0f6ee8ef82305c5bc9b80535199715
|
|
@ -1,56 +0,0 @@
|
|||
|
||||
gulp = require 'gulp'
|
||||
uglify = require 'gulp-uglify'
|
||||
plumber = require 'gulp-plumber'
|
||||
browserify = require 'gulp-browserify'
|
||||
rename = require 'gulp-rename'
|
||||
ignore = require 'gulp-ignore'
|
||||
jshint = require 'gulp-jshint'
|
||||
|
||||
paths =
|
||||
webrtc: ['./lib/y-webrtc*.js']
|
||||
|
||||
buildConnector = (connector_name)->
|
||||
()->
|
||||
gulp.src(paths[connector_name])
|
||||
.pipe plumber()
|
||||
.pipe jshint()
|
||||
.pipe jshint.reporter()
|
||||
|
||||
gulp.src(paths[connector_name])
|
||||
.pipe(plumber())
|
||||
.pipe(browserify(
|
||||
insertGlobals: true
|
||||
debug: true
|
||||
))
|
||||
.pipe gulp.dest('./build/browser/')
|
||||
.pipe uglify()
|
||||
.pipe gulp.dest('./')
|
||||
|
||||
gulp.src './*.html'
|
||||
.pipe gulp.dest './build/browser/'
|
||||
|
||||
gulp.task 'build_node', ->
|
||||
gulp.src(['./lib/**'])
|
||||
.pipe plumber()
|
||||
.pipe gulp.dest './build/node/'
|
||||
|
||||
gulp.task 'webrtc', [], buildConnector 'webrtc'
|
||||
|
||||
gulp.task 'build_browser', ['webrtc']
|
||||
gulp.task 'build', ['build_browser', 'build_node']
|
||||
|
||||
# Rerun the task when a file changes
|
||||
gulp.task 'watch', ()->
|
||||
gulp.watch(paths.webrtc, ['webrtc'])
|
||||
|
||||
gulp.task('default', ['watch', 'build'])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
var WebRTC = require('./y-webrtc');
|
||||
|
||||
new Polymer('y-webrtc',{
|
||||
ready: function(){
|
||||
this.is_initialized = false;
|
||||
this.initialize();
|
||||
},
|
||||
initialize: function(){
|
||||
if(!this.is_initialized && this.room !== undefined){
|
||||
this.is_initialized = true;
|
||||
this.connector = new WebRTC(this.room);
|
||||
if(this.debug !== undefined){
|
||||
this.connector.debug = this.debug;
|
||||
}
|
||||
}
|
||||
},
|
||||
roomChanged: function(){
|
||||
this.initialize();
|
||||
}
|
||||
});
|
123
lib/y-webrtc.js
123
lib/y-webrtc.js
|
@ -1,123 +0,0 @@
|
|||
|
||||
var SimpleWebRTC = require('simplewebrtc');
|
||||
|
||||
function WebRTC(room, webrtc_options){
|
||||
if(webrtc_options === undefined){
|
||||
webrtc_options = {};
|
||||
}
|
||||
|
||||
// connect per default to our server
|
||||
if(webrtc_options.url === undefined){
|
||||
webrtc_options.url = "https://yatta.ninja:8888";
|
||||
}
|
||||
|
||||
var swr = new SimpleWebRTC(webrtc_options);
|
||||
this.swr = swr;
|
||||
var self = this;
|
||||
|
||||
var channel;
|
||||
|
||||
swr.once('connectionReady',function(user_id){
|
||||
// SimpleWebRTC (swr) is initialized
|
||||
swr.joinRoom(room);
|
||||
|
||||
swr.once('joinedRoom', function(){
|
||||
// the client joined the specified room
|
||||
var when_bound_to_y = function(){
|
||||
// when the connector is bound to Y,
|
||||
// e.g. by creating a new instance of Y,
|
||||
// initialize the connector with the required parameters.
|
||||
// You always should specify `role`, `syncMethod`, and `user_id`
|
||||
self.init({
|
||||
role : "slave",
|
||||
syncMethod : "syncAll",
|
||||
user_id : user_id
|
||||
});
|
||||
var i;
|
||||
// notify the connector class about all the users that already
|
||||
// joined the session
|
||||
for(i in self.swr.webrtc.peers){
|
||||
self.userJoined(self.swr.webrtc.peers[i].id, "slave");
|
||||
}
|
||||
};
|
||||
|
||||
if(self.is_bound_to_y){
|
||||
// The connector is already bound to Y, so we can execute
|
||||
// `when_bound_to_y` immediately
|
||||
when_bound_to_y();
|
||||
} else {
|
||||
// The connector has not yet been bound to Y
|
||||
self.on_bound_to_y = when_bound_to_y;
|
||||
}
|
||||
|
||||
swr.on("channelMessage", function(peer, room, message){
|
||||
// The client received a message
|
||||
// Check if the connector is already initialized,
|
||||
// only then forward the message to the connector class
|
||||
if(self.is_initialized && message.type === "yjs"){
|
||||
self.receiveMessage(peer.id, message.payload);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
swr.on("createdPeer", function(peer){
|
||||
// a new peer/client joined the session.
|
||||
// Notify the connector class, if the connector
|
||||
// is already initialized
|
||||
if(self.is_initialized){
|
||||
// note: Since the WebRTC Connector only supports the SyncAll
|
||||
// syncmethod, every client is a slave.
|
||||
self.userJoined(peer.id, "slave");
|
||||
}
|
||||
});
|
||||
|
||||
swr.on("peerStreamRemoved",function(peer){
|
||||
// a client left the session.
|
||||
// Notify the connector class, if the connector
|
||||
// is already initialized
|
||||
if(self.is_initialized){
|
||||
self.userLeft(peer.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Specify how to send a message to a specific user (by uid)
|
||||
WebRTC.prototype.send = function(uid, message){
|
||||
var self = this;
|
||||
// we have to make sure that the message is sent under all circumstances
|
||||
var send = function(){
|
||||
// check if the clients still exists
|
||||
var peer = self.swr.webrtc.getPeers(uid)[0];
|
||||
var success;
|
||||
if(peer){
|
||||
// success is true, if the message is successfully sent
|
||||
success = peer.sendDirectly("simplewebrtc", "yjs", message);
|
||||
}
|
||||
if(!success){
|
||||
// resend the message if it didn't work
|
||||
window.setTimeout(send,500);
|
||||
}
|
||||
};
|
||||
// try to send the message
|
||||
send();
|
||||
};
|
||||
|
||||
// specify how to broadcast a message to all users
|
||||
// (it may send the message back to itself).
|
||||
// The webrtc connecor tries to send it to every single clients directly
|
||||
WebRTC.prototype.broadcast = function(message){
|
||||
this.swr.sendDirectlyToAll("simplewebrtc","yjs",message);
|
||||
};
|
||||
|
||||
if(window !== undefined){
|
||||
if(window.Y !== undefined){
|
||||
window.Y.WebRTC = WebRTC;
|
||||
} else {
|
||||
console.err("You must first include Y, and then the WebRTC Connector!");
|
||||
}
|
||||
}
|
||||
if(module !== undefined){
|
||||
module.exports = WebRTC;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +0,0 @@
|
|||
|
||||
<polymer-element name="y-webrtc" hidden attributes="connector room debug">
|
||||
<template>
|
||||
</template>
|
||||
<script src="./y-webrtc-polymer.js"></script>
|
||||
</polymer-element>
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue