init :octocat:
This commit is contained in:
commit
d5cf2c88ff
9 changed files with 11239 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules
|
||||
|
12
build/browser/test.html
Normal file
12
build/browser/test.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!--
|
||||
To change this template use Tools | Templates.
|
||||
-->
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<script src="./y-webrtc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
10959
build/browser/y-webrtc.js
Normal file
10959
build/browser/y-webrtc.js
Normal file
File diff suppressed because one or more lines are too long
66
build/node/y-webrtc.js
Normal file
66
build/node/y-webrtc.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
|
||||
var SimpleWebRTC = require('simplewebrtc');
|
||||
|
||||
function WebRTC(room, webrtc_options){
|
||||
|
||||
var swr = new SimpleWebRTC({
|
||||
debug: true
|
||||
})
|
||||
this.swr = swr;
|
||||
var self = this;
|
||||
|
||||
var channel;
|
||||
|
||||
swr.on('createdPeer',function(conn){
|
||||
|
||||
swr.joinRoom(room, function(){
|
||||
swr.on("channelOpen", function(){
|
||||
var when_bound_to_y = function(){
|
||||
self.init({
|
||||
role : "slave",
|
||||
syncMethod : "syncAll",
|
||||
user_id : conn.id
|
||||
})
|
||||
}
|
||||
|
||||
swr.on("channelMessage", function(peer, room, message){
|
||||
if(message.type === "yjs"){
|
||||
console.log(message.payload);
|
||||
}
|
||||
if(this.is_bound_to_y && message.type === "yjs"){
|
||||
this.receiveMessage(peer.id, JSON.parse(message.payload))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
WebRTC.prototype.send = function(uid, message){
|
||||
var peer = this.swr.webrtc.getPeers(uid)[0];
|
||||
peer.sendDirectly("simplewebrtc", "yjs", "message");
|
||||
}
|
||||
|
||||
WebRTC.prototype.broadcast = function(message){
|
||||
this.swr.sendDirectlyToAll("simplewebrtc","yjs",message);
|
||||
}
|
||||
|
||||
if(window != null){
|
||||
if(window.Y != null){
|
||||
window.Y.WebRTC = WebRTC;
|
||||
} else {
|
||||
// console.err("You must first include Y, and then the WebRTC Connector!")
|
||||
}
|
||||
}
|
||||
if(module != null){
|
||||
module.exports = WebRTC;
|
||||
}
|
||||
|
||||
window.webrtc = new WebRTC("stuffy", {
|
||||
debug: true
|
||||
});
|
56
gulpfile.coffee
Normal file
56
gulpfile.coffee
Normal file
|
@ -0,0 +1,56 @@
|
|||
|
||||
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'])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
88
lib/y-webrtc.js
Normal file
88
lib/y-webrtc.js
Normal file
|
@ -0,0 +1,88 @@
|
|||
|
||||
var SimpleWebRTC = require('simplewebrtc');
|
||||
|
||||
function WebRTC(room, webrtc_options){
|
||||
if(webrtc_options === undefined){
|
||||
webrtc_options = {}
|
||||
}
|
||||
|
||||
if(webrtc_options.url === undefined){
|
||||
webrtc_options.url = "http://yatta.ninja:8888"
|
||||
}
|
||||
|
||||
var swr = new SimpleWebRTC(webrtc_options);
|
||||
this.swr = swr;
|
||||
var self = this;
|
||||
|
||||
var channel;
|
||||
|
||||
swr.once('connectionReady',function(user_id){
|
||||
swr.joinRoom(room)
|
||||
|
||||
swr.once('joinedRoom', function(){
|
||||
swr.once('')
|
||||
var when_bound_to_y = function(){
|
||||
self.init({
|
||||
role : "slave",
|
||||
syncMethod : "syncAll",
|
||||
user_id : user_id
|
||||
});
|
||||
for(i in self.swr.webrtc.peers){
|
||||
self.userJoined(self.swr.webrtc.peers[i].id, "slave");
|
||||
}
|
||||
};
|
||||
|
||||
if(self.is_bound_to_y !== undefined && self.is_bound_to_y){
|
||||
when_bound_to_y()
|
||||
} else {
|
||||
self.on_bound_to_y = when_bound_to_y;
|
||||
}
|
||||
|
||||
swr.on("channelMessage", function(peer, room, message){
|
||||
if(self.is_bound_to_y && message.type === "yjs"){
|
||||
self.receiveMessage(peer.id, message.payload);
|
||||
}
|
||||
});
|
||||
});
|
||||
swr.on("createdPeer", function(peer){
|
||||
if(self.is_initialized){
|
||||
self.userJoined(peer.id, "slave");
|
||||
}
|
||||
});
|
||||
swr.on("peerStreamRemoved",function(peer){
|
||||
if(self.is_initialized){
|
||||
self.userLeft(peer.id);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
WebRTC.prototype.send = function(uid, message){
|
||||
var self = this;
|
||||
var send = function(){
|
||||
var peer = self.swr.webrtc.getPeers(uid)[0];
|
||||
if(peer){
|
||||
var success = peer.sendDirectly("simplewebrtc", "yjs", message);
|
||||
}
|
||||
if(!success){
|
||||
window.setTimeout(send,500)
|
||||
}
|
||||
}
|
||||
send()
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
39
package.json
Normal file
39
package.json
Normal file
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "y-webrtc",
|
||||
"version": "0.4.0",
|
||||
"description": "WebRTC Connector for Yjs",
|
||||
"main": "y-webrtc.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/rwth-acis/y-webrtc.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Yjs",
|
||||
"Connector"
|
||||
],
|
||||
"author": "Kevin Jahns <kevin.jahns@rwth-aachen.de>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/rwth-acis/y-webrtc/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rwth-acis/y-webrtc",
|
||||
"dependencies": {
|
||||
"simplewebrtc": "^1.13.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coffee-script": "^1.9.0",
|
||||
"gulp": "^3.8.11",
|
||||
"gulp-browserify": "^0.5.1",
|
||||
"gulp-coffee": "^2.3.1",
|
||||
"gulp-coffeelint": "^0.4.0",
|
||||
"gulp-ignore": "^1.2.1",
|
||||
"gulp-jshint": "^1.9.2",
|
||||
"gulp-plumber": "^0.6.6",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"gulp-uglify": "^1.1.0",
|
||||
"jshint": "^2.6.0"
|
||||
}
|
||||
}
|
12
test.html
Normal file
12
test.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!--
|
||||
To change this template use Tools | Templates.
|
||||
-->
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<script src="./y-webrtc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
5
y-webrtc.js
Normal file
5
y-webrtc.js
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue