webrtc.io
Advanced tools
Comparing version 0.0.1 to 0.0.2-1
//SERVER | ||
var WebSocketServer = require('ws').Server | ||
var iolog = function(){}; | ||
var iolog = function() {}; | ||
for(var i=0; i < process.argv.length; i++){ | ||
for (var i = 0; i < process.argv.length; i++) { | ||
var arg = process.argv[i]; | ||
if(arg === "-debug"){ | ||
iolog = function(msg){console.log(msg)} | ||
if (arg === "-debug") { | ||
iolog = function(msg) { | ||
console.log(msg) | ||
} | ||
console.log('Debug mode on!'); | ||
@@ -22,3 +24,3 @@ } | ||
rtc.rooms = []; | ||
rtc.rooms = {}; | ||
@@ -46,5 +48,5 @@ // Holds callbacks for certain events. | ||
module.exports.listen = function(port) { | ||
module.exports.listen = function(server) { | ||
var manager = new WebSocketServer({ | ||
port: port | ||
server: server | ||
}); | ||
@@ -80,29 +82,25 @@ | ||
// remove from rooms | ||
for(var room in rtc.rooms) { | ||
// remove from rooms and send remove_peer_connected to all sockets in room | ||
for (var key in rtc.rooms) { | ||
var room = rtc.rooms[key]; | ||
var exist = room.indexOf(socket.id); | ||
if(exist !== -1){ | ||
rtc.rooms.splice(rtc.rooms.indexOf(room), 1); | ||
} | ||
} | ||
// remove the disconnected socket from the sockets array and send out | ||
// a notification to all connected peers that socket was removed. | ||
for (var j = 0; j < rtc.sockets.length; j++) { | ||
var id = rtc.sockets[j].id; | ||
if (id === socket.id) { | ||
rtc.sockets.splice(j, 1); | ||
j--; | ||
} else { | ||
rtc.sockets[j].send(JSON.stringify({ | ||
"eventName": "remove_peer_connected", | ||
"socketId": socket.id | ||
}), function(error) { | ||
if (error) { | ||
console.log(error); | ||
} | ||
}); | ||
if (exist !== -1) { | ||
room.splice(room.indexOf(socket.id), 1); | ||
for (var j = 0; j < room.length; j++) { | ||
console.log(room[j]); | ||
var soc = rtc.getSocket(room[j]); | ||
soc.send(JSON.stringify({ | ||
"eventName": "remove_peer_connected", | ||
"socketId": socket.id | ||
}), function(error) { | ||
if (error) { | ||
console.log(error); | ||
} | ||
}); | ||
} | ||
break; | ||
} | ||
} | ||
// call the disconnect callback | ||
@@ -127,4 +125,4 @@ rtc.fire('disconnect', rtc); | ||
rtc.rooms[data.room] = roomList; | ||
for (var i = 0; i < roomList.length; i++) { | ||
@@ -138,3 +136,3 @@ var id = roomList[i]; | ||
connectionsId.push(id); | ||
var soc = rtc.getSocket(data.room, id); | ||
var soc = rtc.getSocket(id); | ||
@@ -168,3 +166,3 @@ // inform the peers that they have a new peer | ||
iolog('send_ice_candidate'); | ||
var soc = rtc.getSocket(data.room, data.socketId); | ||
var soc = rtc.getSocket(data.socketId); | ||
@@ -191,3 +189,3 @@ if (soc) { | ||
iolog('send_offer'); | ||
var soc = rtc.getSocket(data.room, data.socketId); | ||
var soc = rtc.getSocket(data.socketId); | ||
@@ -212,3 +210,3 @@ if (soc) { | ||
iolog('send_answer'); | ||
var soc = rtc.getSocket(data.room, data.socketId); | ||
var soc = rtc.getSocket( data.socketId); | ||
@@ -231,2 +229,4 @@ if (soc) { | ||
// generate a 4 digit hex code randomly | ||
function S4() { | ||
@@ -237,2 +237,4 @@ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); | ||
// make a REALLY COMPLICATED AND RANDOM id, kudos to dennis | ||
function id() { | ||
@@ -242,3 +244,3 @@ return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); | ||
rtc.getSocket = function(room, id) { | ||
rtc.getSocket = function(id) { | ||
var connections = rtc.sockets; | ||
@@ -256,2 +258,2 @@ if (!connections) { | ||
} | ||
} | ||
} |
{ | ||
"name": "webrtc.io", | ||
"version": "0.0.1", | ||
"version": "0.0.2-1", | ||
"description": "Abstraction for webRTC.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,7 +22,7 @@ # webRTC.io | ||
## Demo | ||
This is a multi-person chat room demo written using our webRTC.io library. [Example Site](http://multiwebrtc.nodejitsu.com) & [Repository](http://www.github.com/dennismartensson/webrtc.io-demo/) (browser support section still applies!) | ||
This is a multi-person chat room demo written using our webRTC.io library. [Example Site](http://multiwebrtc.nodejitsu.com) & [Repository](http://www.github.com/webRTC/webrtc.io-demo/) (browser support section still applies!) | ||
## Installation | ||
```bash | ||
npm install | ||
npm install webRTC.io | ||
``` | ||
@@ -36,11 +36,9 @@ for absurdly detailed instruction on setting up the demo, go to the demo repo. | ||
```html | ||
<video id="local" autoplay></video> | ||
<script src="/socket.io/socket.io.js"></script> | ||
<script src="/webrtc.io/webrtc.io.js"></script> | ||
<script src="/webrtc.io.js"></script> | ||
<script> | ||
rtc.createStream('local'); | ||
rtc.connect('http://yourserveraddress'); | ||
rtc.on('ready', function() { | ||
// all streams are loaded | ||
}); | ||
rtc.createStream({"video": true, "audio":true}, function(stream){ | ||
// get local stream for manipulation | ||
} | ||
rtc.connect('ws://yourserveraddress:8001', optionalRoom); | ||
//then a bunch of callbacks are available | ||
</script> | ||
@@ -52,10 +50,4 @@ ``` | ||
```javascript | ||
var io = require('webrtc.io').listen(8000); | ||
// this is a simple wrapper around socket.io, so you can define your own events | ||
// like so: | ||
io.sockets.on('connection', function(socket) { | ||
socket.on('chat', function(nick, message) { | ||
socket.broadcast.emit('chat', nick, message); | ||
}); | ||
}); | ||
var webRTC = require('webrtc.io').listen(8001); | ||
//then a bunch of callbacks are available | ||
``` | ||
@@ -68,12 +60,4 @@ | ||
We've done house calls in the past (also known as walking down the hall)... we'll totally do it again if you fly us out! | ||
### Collaborators | ||
[@dennismatensson](https://github.com/dennismartensson) | ||
[@cavedweller](https://github.com/cavedweller) | ||
[@sarenji](https://github.com/sarenji) | ||
### License | ||
Copyright (C) 2012 Ben Brittain, Dennis Mårtensson, David Peter | ||
Copyright (C) 2012 [Ben Brittain](https://github.com/cavedweller), [Dennis Mårtensson](https://github.com/dennismartensson), [David Peter](https://github.com/sarenji) | ||
@@ -80,0 +64,0 @@ 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: |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
9953
199
65
1