µ¿ÀÛ ¿Ϸá
This commit is contained in:
@@ -28,19 +28,21 @@ function pageReady() {
|
||||
}
|
||||
|
||||
function getUserMediaSuccess(stream) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + '[getUserMediaSuccess] ' + stream);
|
||||
|
||||
localStream = stream;
|
||||
localVideo.src = window.URL.createObjectURL(stream);
|
||||
}
|
||||
|
||||
function start(isCaller) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + "[start] caller? " + isCaller);
|
||||
peerConnection = new RTCPeerConnection(peerConnectionConfig);
|
||||
peerConnection.onicecandidate = gotIceCandidate;
|
||||
peerConnection.onaddstream = gotRemoteStream;
|
||||
peerConnection.addStream(localStream);
|
||||
|
||||
if(isCaller) {
|
||||
if(isCaller)
|
||||
peerConnection.createOffer(gotDescription, errorHandler);
|
||||
}
|
||||
}
|
||||
|
||||
function gotMessageFromServer(message) {
|
||||
@@ -57,23 +59,25 @@ function gotMessageFromServer(message) {
|
||||
}
|
||||
|
||||
function gotIceCandidate(event) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + '[gotIceCandidate] ' + event);
|
||||
if(event.candidate != null) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + '[gotIceCandidate] ' + event.candidate);
|
||||
serverConnection.send(JSON.stringify({'ice': event.candidate}));
|
||||
}
|
||||
}
|
||||
|
||||
function gotDescription(description) {
|
||||
console.log('got description');
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + '[gotDescription] got description');
|
||||
peerConnection.setLocalDescription(description, function () {
|
||||
serverConnection.send(JSON.stringify({'sdp': description}));
|
||||
}, function() {console.log('set description error')});
|
||||
}, function() {console.log('['+(new Date().toLocaleString())+'] ' + '[gotDescription] set description error')});
|
||||
}
|
||||
|
||||
function gotRemoteStream(event) {
|
||||
console.log('got remote stream');
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + '[gotRemoteStream] got remote stream');
|
||||
remoteVideo.src = window.URL.createObjectURL(event.stream);
|
||||
}
|
||||
|
||||
function errorHandler(error) {
|
||||
console.log(error);
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + "[errorHandler] " + error);
|
||||
}
|
||||
|
||||
@@ -1,62 +1,3 @@
|
||||
var max_print_r_depth = 2
|
||||
function print_r(obj, t, d) {
|
||||
|
||||
// define tab spacing
|
||||
var tab = t || '';
|
||||
|
||||
// define depth
|
||||
var depth = d || 1;
|
||||
|
||||
// check if it's array
|
||||
var isArr = Object.prototype.toString.call(obj) === '[object Array]';
|
||||
|
||||
// use {} for object, [] for array
|
||||
var str = isArr ? ('Array\n' + tab + '[ \n') : ('Object\n' + tab + '{ \n');
|
||||
|
||||
// walk through it's properties
|
||||
for (var prop in obj) {
|
||||
if (obj.hasOwnProperty(prop)) {
|
||||
var val1 = obj[prop];
|
||||
var val2 = '';
|
||||
var type = Object.prototype.toString.call(val1);
|
||||
switch (type) {
|
||||
|
||||
// recursive if object/array
|
||||
case '[object Array]':
|
||||
case '[object Object]':
|
||||
if(depth <= max_print_r_depth)
|
||||
val2 = print_r(val1, (tab + ' '), depth+1);
|
||||
else
|
||||
val2 = type;
|
||||
break;
|
||||
|
||||
case '[object String]':
|
||||
if(val1.length > 40)
|
||||
val2 = '\'' + val1.substring(0, 40) + '\'';
|
||||
else
|
||||
val2 = '\'' + val1 + '\'';
|
||||
break;
|
||||
|
||||
case '[object Function]':
|
||||
case '[object Uint8Array]':
|
||||
val2 = type;
|
||||
break;
|
||||
|
||||
default:
|
||||
val2 = val1;
|
||||
}
|
||||
str += tab + ' ' + prop + ' => ' + val2 + ',\n';
|
||||
}
|
||||
}
|
||||
|
||||
// remove extra comma for last property
|
||||
str = str.substring(0, str.length - 2) + '\n' + tab;
|
||||
|
||||
return isArr ? (str + ']') : (str + '}');
|
||||
}
|
||||
|
||||
|
||||
|
||||
var localVideo;
|
||||
var remoteVideo;
|
||||
var peerConnection;
|
||||
@@ -90,19 +31,19 @@ function pageReady(ch) {
|
||||
}
|
||||
|
||||
function onConnection(data) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + '[onConnect]' + data.toString());
|
||||
serverConnection.send( JSON.stringify({ channel: channel }) );
|
||||
// console.log('['+(new Date().toLocaleString())+'] ' + '[onConnect]' + data.toString());
|
||||
serverConnection.send( JSON.stringify({ 'channel': channel }) );
|
||||
}
|
||||
|
||||
function getUserMediaSuccess(stream) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + '[getUserMediaSuccess] ' + stream);
|
||||
// console.log('['+(new Date().toLocaleString())+'] ' + '[getUserMediaSuccess] ' + stream);
|
||||
|
||||
localStream = stream;
|
||||
localVideo.src = window.URL.createObjectURL(stream);
|
||||
}
|
||||
|
||||
function start(isCaller) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + "[start] caller? " + isCaller);
|
||||
// console.log('['+(new Date().toLocaleString())+'] ' + "[start] caller? " + isCaller);
|
||||
peerConnection = new RTCPeerConnection(peerConnectionConfig);
|
||||
peerConnection.onicecandidate = gotIceCandidate;
|
||||
peerConnection.onaddstream = gotRemoteStream;
|
||||
@@ -111,8 +52,6 @@ function start(isCaller) {
|
||||
|
||||
if(isCaller)
|
||||
peerConnection.createOffer(gotDescription, errorHandler);
|
||||
else
|
||||
serverConnection.send( JSON.stringify({ channel: channel }) );
|
||||
}
|
||||
|
||||
function gotMessageFromServer(message) {
|
||||
@@ -127,18 +66,14 @@ function gotMessageFromServer(message) {
|
||||
peerConnection.createAnswer(gotDescription, errorHandler);
|
||||
}, errorHandler);
|
||||
} else if(signal.ice) {
|
||||
console.log(signal.ice.candidate)
|
||||
var iceCandidate = new RTCIceCandidate(signal.ice);
|
||||
console.log('test2');
|
||||
peerConnection.addIceCandidate(iceCandidate);
|
||||
console.log('test3')
|
||||
peerConnection.addIceCandidate(new RTCIceCandidate(signal.ice));
|
||||
}
|
||||
}
|
||||
|
||||
function gotIceCandidate(event) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + '[gotIceCandidate] ' + event);
|
||||
// console.log('['+(new Date().toLocaleString())+'] ' + '[gotIceCandidate] ' + event);
|
||||
if(event.candidate != null) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + '[gotIceCandidate] ' + event.candidate);
|
||||
// console.log('['+(new Date().toLocaleString())+'] ' + '[gotIceCandidate] ' + event.candidate);
|
||||
serverConnection.send(JSON.stringify({'ice': event.candidate}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
var utils = require('./utils');
|
||||
|
||||
var WebSocketServer = require('ws').Server;
|
||||
|
||||
var wss = new WebSocketServer({port: 3434});
|
||||
|
||||
wss.broadcast = function(data, channel) {
|
||||
// if(!channel)
|
||||
// {
|
||||
// console.log('empty channel. skipped.');
|
||||
// return;
|
||||
// }
|
||||
if(!channel)
|
||||
{
|
||||
console.log('empty channel. skipped.');
|
||||
return;
|
||||
}
|
||||
|
||||
for(var i in this.clients) {
|
||||
// if(this.clients[i].channel == channel)
|
||||
{
|
||||
console.log('channel1 : ' + this.clients[i].channel);
|
||||
console.log('channel2 : ' + channel);
|
||||
|
||||
console.log('channel : ' + channel + 'client\'s channel : ' + this.clients[i].channel);
|
||||
|
||||
if(this.clients[i].channel == channel)
|
||||
{
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + 'send : [' + channel +'] '+ data);
|
||||
this.clients[i].send(data);
|
||||
}
|
||||
@@ -25,24 +24,17 @@ wss.broadcast = function(data, channel) {
|
||||
|
||||
wss.on('connection', function(ws) {
|
||||
ws.on('message', function(message) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + 'received: %s\n', message);
|
||||
try {
|
||||
var obj = JSON.parse(message);
|
||||
utils.ObjDump(obj);
|
||||
if(obj.channel != null)
|
||||
{
|
||||
var channel = obj.channel;
|
||||
// console.log('['+(new Date().toLocaleString())+'] ' + 'received: %s\n', message);
|
||||
|
||||
// if(wss.channel == null)
|
||||
// wss.channel = new Object();
|
||||
// if(wss.channel[channel] == null)
|
||||
// wss.channel[channel] = new Array();
|
||||
// wss.channel[channel].push(ws);
|
||||
ws.channel = channel;
|
||||
console.log('new channel : ' + ws.channel);
|
||||
if(typeof message == "string") {
|
||||
// console.log('string message : ' + message);
|
||||
|
||||
var obj = JSON.parse(message);
|
||||
// utils.ObjDump(obj);
|
||||
if(obj.channel) {
|
||||
ws.channel = obj.channel;
|
||||
return;
|
||||
}
|
||||
} catch (ex) {
|
||||
console.log('['+(new Date().toLocaleString())+'] ' + ex);
|
||||
}
|
||||
|
||||
wss.broadcast(message, ws.channel);
|
||||
|
||||
Reference in New Issue
Block a user