diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.jshintignore @@ -0,0 +1 @@ +node_modules diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..006e4c0 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,15 @@ +{ + "asi": false, + "expr": true, + "loopfunc": true, + "curly": false, + "evil": true, + "white": true, + "undef": true, + "browser": true, + "node": true, + "trailing": true, + "indent": 4, + "latedef": true, + "newcap": true +} diff --git a/examples/muc.js b/examples/muc.js index 23ea936..4018a32 100644 --- a/examples/muc.js +++ b/examples/muc.js @@ -1,7 +1,8 @@ +/* jshint -W117 */ var BOSH_SERVICE = '/http-bind', - DOMAIN = window.location.hostname; + DOMAIN = window.location.hostname, CONFERENCEDOMAIN = 'conference.' + DOMAIN, - ice_config = {iceServers: [{url: 'stun:stun.l.google.com:19302'}]}, + ice_config = {iceServers: [{url: 'stun:stun.l.google.com:19302'}]}, RTC = null, RTCPeerConnection = null, AUTOACCEPT = true, @@ -45,64 +46,37 @@ function onConnect(status) { } } -function onConnected(event) { - doJoin(); - setTimeout(function() { - $(window).bind('hashchange', onHashChange); - }, 500); +function onHashChange() { + setStatus('hashChange: ' + window.location.hash); + if (Object.keys(connection.jingle.sessions).length === 0) { + window.location.reload(); + } } -function doJoin() { - var roomnode = null, - pres; - if (location.hash.length > 1) { - roomnode = location.hash.substr(1).toLowerCase(); - if (roomnode.indexOf('/') != -1) { - setStatus('invalid location, must not contain "/"'); - connection.disconnect(); - return; - } - if (roomnode.indexOf('@') != -1) { // allow #room@host - roomjid = roomnode; - } - } else { - roomnode = Math.random().toString(36).substr(2, 8); - location.hash = roomnode; - } - if (roomjid == null) { - roomjid = roomnode + '@' + CONFERENCEDOMAIN; +function onJoinComplete() { + setStatus('onJoinComplete'); + if (list_members.length < 1) { + setStatus('waiting for peer'); + return; } - setStatus('Joining ' + location.hash); - myroomjid = roomjid + '/' + Strophe.getNodeFromJid(connection.jid); - list_members = new Array(); - console.log('joining', roomjid); - - // muc stuff - connection.addHandler(onPresence, null, 'presence', null, null, roomjid, {matchBare: true}); - connection.addHandler(onPresenceUnavailable, null, 'presence', 'unavailable', null, roomjid, {matchBare: true}); - connection.addHandler(onPresenceError, null, 'presence', 'error', null, roomjid, {matchBare: true}); - - pres = $pres({to: myroomjid }) - .c('x', {xmlns: 'http://jabber.org/protocol/muc'}); - connection.send(pres); -} -function onHashChange() { - setStatus('hashChange: ' + window.location.hash); - if (Object.keys(connection.jingle.sessions).length == 0) { - window.location.reload(); + setStatus('initiating call'); + var i, sess, num; + num = MULTIPARTY ? list_members.length : 1; + for (i = 0; i < num; i++) { + connection.jingle.initiate(list_members[i], myroomjid); } } function onPresence(pres) { var from = pres.getAttribute('from'), type = pres.getAttribute('type'); - if (type != null) { + if (type !== null) { return true; } if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="201"]').length) { // http://xmpp.org/extensions/xep-0045.html#createroom-instant - var create = $iq({type: 'set', to:roomjid}) + var create = $iq({type: 'set', to: roomjid}) .c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'}) .c('x', {xmlns: 'jabber:x:data', type: 'submit'}); connection.send(create); // fire away @@ -117,7 +91,7 @@ function onPresence(pres) { function onPresenceUnavailable(pres) { connection.jingle.terminateByJid($(pres).attr('from')); - if (Object.keys(connection.jingle.sessions).length == 0) { + if (Object.keys(connection.jingle.sessions).length === 0) { setStatus('everyone left'); } for (var i = 0; i < list_members.length; i++) { @@ -134,19 +108,39 @@ function onPresenceError(pres) { return true; } -function onJoinComplete() { - setStatus('onJoinComplete'); - if (list_members.length < 1) { - setStatus('waiting for peer'); - return; +function doJoin() { + var roomnode = null, + pres; + if (location.hash.length > 1) { + roomnode = location.hash.substr(1).toLowerCase(); + if (roomnode.indexOf('/') != -1) { + setStatus('invalid location, must not contain "/"'); + connection.disconnect(); + return; + } + if (roomnode.indexOf('@') != -1) { // allow #room@host + roomjid = roomnode; + } + } else { + roomnode = Math.random().toString(36).substr(2, 8); + location.hash = roomnode; } - - setStatus('initiating call'); - var i, sess, num; - num = MULTIPARTY ? list_members.length : 1; - for (i = 0; i < num; i++) { - connection.jingle.initiate(list_members[i], myroomjid); + if (roomjid === null) { + roomjid = roomnode + '@' + CONFERENCEDOMAIN; } + setStatus('Joining ' + location.hash); + myroomjid = roomjid + '/' + Strophe.getNodeFromJid(connection.jid); + list_members = []; + console.log('joining', roomjid); + + // muc stuff + connection.addHandler(onPresence, null, 'presence', null, null, roomjid, {matchBare: true}); + connection.addHandler(onPresenceUnavailable, null, 'presence', 'unavailable', null, roomjid, {matchBare: true}); + connection.addHandler(onPresenceError, null, 'presence', 'error', null, roomjid, {matchBare: true}); + + pres = $pres({to: myroomjid }) + .c('x', {xmlns: 'http://jabber.org/protocol/muc'}); + connection.send(pres); } function onMediaReady(event, stream) { @@ -167,25 +161,25 @@ function onMediaReady(event, stream) { doConnect(); if (typeof hark === "function") { - var options = { interval:400 }; + var options = { interval: 400 }; var speechEvents = hark(stream, options); - speechEvents.on('speaking', function() { - console.log('speaking'); + speechEvents.on('speaking', function () { + console.log('speaking'); }); - speechEvents.on('stopped_speaking', function() { - console.log('stopped_speaking'); + speechEvents.on('stopped_speaking', function () { + console.log('stopped_speaking'); }); - speechEvents.on('volume_change', function(volume, treshold) { + speechEvents.on('volume_change', function (volume, treshold) { //console.log('volume', volume, treshold); - if (volume < -60) { // vary between -60 and -35 - $('#ownvolume').css('width', 0); - } else if (volume > -35) { - $('#ownvolume').css('width', '100%'); - } else { - $('#ownvolume').css('width', (volume+100)*100/25-160+ '%'); - } + if (volume < -60) { // vary between -60 and -35 + $('#ownvolume').css('width', 0); + } else if (volume > -35) { + $('#ownvolume').css('width', '100%'); + } else { + $('#ownvolume').css('width', (volume + 100) * 100 / 25 - 160 + '%'); + } }); } else { console.warn('without hark, you are missing quite a nice feature'); @@ -207,87 +201,20 @@ function onCallIncoming(event, sid) { //connection.jingle.terminate(sid); } -function onCallActive(event, videoelem, sid) { - setStatus('call active ' + sid); - $(videoelem).appendTo('#largevideocontainer'); - arrangeVideos('#largevideocontainer >'); - connection.jingle.sessions[sid].getStats(1000); -} - -function onCallTerminated(event, sid, reason) { - setStatus('call terminated ' + sid + (reason ? (': ' + reason) : '')); - if (Object.keys(connection.jingle.sessions).length == 0) { - setStatus('all calls terminated'); - } - $('#largevideocontainer #largevideo_' + sid).remove(); - arrangeVideos('#largevideocontainer >'); -} - -function onRemoteStreamAdded(event, data, sid) { - setStatus('Remote stream for session ' + sid + ' added.'); - if ($('#largevideo_' + sid).length != 0) { - console.log('ignoring duplicate onRemoteStreamAdded...'); // FF 20 - return; - } - // after remote stream has been added, wait for ice to become connected - // old code for compat with FF22 beta - var el = $("