Merge branch 'merge-polling-with-master' of github.com:antobinary/bigbluebutton into merge-polling-with-master

This commit is contained in:
Richard Alam 2014-05-14 21:26:38 +00:00
commit f3e13db080
13 changed files with 371 additions and 6 deletions

View File

@ -30,6 +30,23 @@ app.configure ->
app.use express.methodOverride()
app.use express.cookieParser()
# Enables CORS
enableCORS = (req, res, next) ->
res.header('Access-Control-Allow-Origin', '*') #TODO: must restrict this!!!!!!
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS') #TODO: must restrict this!!!!!!
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With') #TODO: must restrict this!!!!!!
# intercept OPTIONS method
if ('OPTIONS' is req.method)
res.send(200)
else
next()
# enable CORS!
app.use(enableCORS)
# redis
app.use express.session(
secret: config.app.sessionSecret

View File

@ -13,6 +13,9 @@ module.exports = class MainRouter
_registerRoutes: () ->
@app.get "/", @_index
@app.get "/html5.client", @_landingPageHandler
# Base route to render the HTML5 client.
#
# This method is registered as a route on express.
@ -21,3 +24,20 @@ module.exports = class MainRouter
_index: (req, res) =>
res.render "index",
title: config.appName
# A route to enter the HTML5 client from a landing page
#
# @internal
_landingPageHandler: (req, res) ->
meetingId = req.query.meeting_id
userId = req.query.user_id
authToken = req.query.auth_token
console.log "\n\nLANDING PAGE PROVIDED:\n" +
"meeting_id=#{meetingId}\n" +
"user_id=#{userId}\n" +
"auth_token=#{authToken}\n\n"
#render a blank page page.html
res.render "session",
title: config.appName

View File

@ -30,3 +30,14 @@ returns an array of stringified json recordings (see above for the structure of
if there are no recordings for the given meetingID, the message
"No recordings for meetingid=some_random_string" appears
Running Tests
=============
while the application is running // $ coffee index.coffee
open another console and enter:
$ cake test
or
$ ./node_modules/.bin/mocha --require coffee-script/register --compilers coffee:coffee-script/register --require should --colors --ignore-leaks --timeout 15000 --reporter spec test/routetests.coffee
(where test/routetests.coffee is the collecion of tests you want to execute)

View File

@ -12,16 +12,65 @@ server.route(routes.routes)
# parseurls endpoint test
describe 'add endpoint', ->
describe 'checking recordings', ->
it 'add - should add two numbers together', ->
it 'recordings for a given meetingid', ->
server.inject({method: 'GET', url: '192.168.0.203:4000/recordings?meetingid=fbdbde6fd7b6499723a101c4c962f03843b4879c'}, (res) ->
#console.log "json:" + res.payload
array = [
{
'format': 'presentation'
'timestamp':'1396619572523'
}, {
'format': 'capture'
'timestamp':'1396623833044'
}, {
'format': 'presentation'
'timestamp':'1396620788271'
}, {
'format': 'presentation'
'timestamp':'1396622260421'
}, {
'format': 'capture'
'timestamp':'1396623833035'
}, {
'format': 'capture'
'timestamp':'1396623830000'
}, {
'format': 'capture'
'timestamp':'1396619572523'
}, {
'format': 'capture'
'timestamp':'1396622260421'
}, {
'format': 'capture'
'timestamp':'1396620788271'
}, {
'format': 'presentation'
'timestamp':'1396623833035'
}, {
'format': 'capture'
'timestamp':'1396623831111'
}
]
parsedOnce = JSON.parse(res.payload)
index = 0
while index < parsedOnce.length
assert.deepEqual(JSON.stringify(array[index]), parsedOnce[index])
index++
#console.log index
)
###it 'add - should add two numbers together', ->
server.inject({method: 'PUT', url: '/sum/add/5/5'}, (res) ->
console.log "json:" +JSON.stringify(res.payload)
assert.deepEqual({'equals': 10}, JSON.parse(res.payload))
done()
)
)###
it 'add - should error if a string is passed', (done) ->
server.inject({method: 'PUT', url: '/sum/add/100/x'}, (res) ->
###it 'add - should error if a string is passed', (done) ->
server.inject({method: 'PUT', url: '/sum/add/100/1'}, (res) ->
console.log "json:" +JSON.stringify(res)
assert.deepEqual({
'statusCode': 400
'error': 'Bad Request'
@ -34,4 +83,4 @@ describe 'add endpoint', ->
}
}, JSON.parse(res.payload))
done()
)
)###

26
labs/demos/README.md Normal file
View File

@ -0,0 +1,26 @@
Instructions
============
Modify the file "config.json" so the fields for IP and salt are
matching your bbb-web configuration
PORT is used in the next steps (assuming you use 4000)
Run:
$ coffee index.coffee
Browse to port 4000 in the browser
Enter a name in the textbox and click "Send"
Return to the terminal where you ran index.coffee
Verify that the username displayed is the same you entered in the browser
A pop-up in the browser should display the url and parameters for joining via the html5 client
Terminal:
Click on the link for creating a meeting
Click on the link for joining a meeting via the Flash client
The XML in the browser should inform you whether the attempt was successful

7
labs/demos/config.json Normal file
View File

@ -0,0 +1,7 @@
{
"settings": {
"IP": "http://192.168.0.203",
"PORT": "4000",
"salt": "74a91f30f165423067bf3039722e33e0"
}
}

28
labs/demos/index.coffee Normal file
View File

@ -0,0 +1,28 @@
connect = require 'connect'
express = require 'express'
http = require 'http'
config = require './config.json'
handlers = require './lib/handlers'
app = express()
app.set('port', config.settings.PORT)
app.set('views', '/views')
app.use(connect.bodyParser())
app.get('/', handlers.index)
app.post('/login', handlers.login)
http.createServer(app).listen(app.get('port'), () ->
console.log('Express server listening on port ' + app.get('port'))
)
app.get("/*", (req, res, next) ->
file = req.params[0]
console.log "\t :: Express :: file requested : " + file
if file is "public/js/app.js" or file is "config.json"
#Send the requesting client the file.
res.sendfile __dirname + "/" + file
next
)

View File

@ -0,0 +1,64 @@
request = require 'request'
sha1 = require 'js-sha1'
urlEncode = (value) ->
encodeURIComponent(value).replace(/%20/g, '+').replace(/[!'()]/g, escape).replace(/\*/g, "%2A")
sortKeys = (params) ->
keys = [];
for own propName of params
keys.push(propName)
keys.sort()
buildBaseString = (params) ->
keysSorted = sortKeys params
baseString = ""
for key in keysSorted
propVal = params[key]
baseString += urlEncode(key) + "=" + urlEncode(propVal) + "&"
#console.log(propName + "=" + query[propName])
console.log("baseString=[" + baseString.slice(0, -1) + "]")
baseString.slice(0, -1)
calculateChecksum = (api, baseString, sharedSecret) ->
qStr = api + baseString + sharedSecret
console.log("[" + qStr + "]")
sha1(qStr)
create = (params, bbb, options, callback) ->
baseStr = buildBaseString(params)
checksum = calculateChecksum("create", baseStr, bbb.secret)
queryStr = baseStr + "&checksum=" + checksum
console.log(queryStr)
reqStr = bbb.server + "create?" + queryStr
console.log(reqStr)
request(reqStr, (error, response, body) ->
callback error, response, body
)
join = (params, bbb, options, callback) ->
baseStr = buildBaseString(params)
checksum = calculateChecksum("join", baseStr, bbb.secret)
queryStr = baseStr + "&checksum=" + checksum
console.log(queryStr)
reqStr = bbb.server + "join?" + queryStr
console.log(reqStr)
request(reqStr, (error, response, body) ->
callback error, response, body
)
exports.create = create
exports.join = join

View File

@ -0,0 +1,51 @@
xml2js = require 'xml2js'
bbbapi = require './bbbapi'
testapi = require './testapi'
index = (request, response) ->
response.sendfile('./views/index.html')
login = (req, resp) ->
createParams = testapi.createParams
joinParams = testapi.joinParams
serverAndSecret = testapi.serverAndSecret
#use the name from the textbox
console.log "\n\nThe Username passed was=" + JSON.stringify(req.body.name) + "\n\n"
joinParams.fullName = JSON.stringify req.body.name
#calling createapi
bbbapi.create(createParams, serverAndSecret, {}, (errorOuter, responseOuter, bodyOuter) ->
#console.log JSON.stringify(response)
bbbapi.join(joinParams, serverAndSecret, {}, (error, response, body) ->
xml = '' + response.body
#console.log "\n\nxml=" + xml
{parseString} = require 'xml2js'
parseString(xml, (err, result) ->
meeting_id = result.response.meeting_id
user_id = result.response.user_id
auth_token = result.response.auth_token
console.log "\nmeeting_id = " + meeting_id +
"\nuser_id = " + user_id +
"\nauth_token = " + auth_token
#url = "http:/192.168.0.203/html5.client?meeting_id=" + meeting_id + "&user_id=" + user_id + "&auth_token=" + auth_token
url = "192.168.0.203:3000/html5.client?meeting_id=" + meeting_id + "&user_id=" + user_id + "&auth_token=" + auth_token
json =
resp.json({
success: {
url: url
},
failure: {
message: "Something went terribly wrong"
}
})
)
)
)
exports.index = index
exports.login = login

View File

@ -0,0 +1,33 @@
sha1 = require 'js-sha1'
bbbapi = require './bbbapi'
config = require '../config.json'
bbbServer = config.settings.IP + "/bigbluebutton/api/"
sharedSecret = config.settings.salt
console.log "will be creating a meeting on server: " + bbbServer
str = "name=Demo+Meeting&meetingID=Demo+Meeting&voiceBridge=70827&attendeePW=ap&moderatorPW=mp&record=false"
console.log(sha1("create" + str + sharedSecret))
createParams = {}
createParams.attendeePW = "ap"
createParams.moderatorPW = "mp"
createParams.record = false
createParams.voiceBridge = 70827
createParams.name = "Demo Meeting"
createParams.meetingID = "Demo Meeting"
joinParams = {}
joinParams.password = "mp"
joinParams.fullName = "Richard"
joinParams.meetingID = "Demo Meeting"
joinParams.redirect = false
serverAndSecret = {server: bbbServer, secret: sharedSecret}
exports.createParams = createParams
exports.serverAndSecret = serverAndSecret
exports.joinParams = joinParams

16
labs/demos/package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "html5LangingPage",
"version": "0.0.2",
"private": true,
"scripts": {
"start": "coffee index.coffee"
},
"dependencies": {
"express": "4.1.2",
"hapi": "4.1.0",
"js-sha1": "0.1.1",
"xml2js": "0.4.2",
"request": "2.34.0",
"connect": "2.15.0"
}
}

View File

@ -0,0 +1,22 @@
var myModule = angular.module('landingPage', []);
myModule.controller('MainCtrl', function($scope, $http, $location, $window) {
$scope.postUsername = function() {
var account = {
"name": $scope.username,
"password": 'oOoOoO'
};
jQuery.getJSON("config.json", function (json) {
$http.post('/login', account).success(function(res) {
//alert(res.success.url);
//TODO check if I really need $location
$scope.myurl = res.success.url;
});
});
}
});

View File

@ -0,0 +1,21 @@
<!doctype html>
<html ng-app="landingPage">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.7/angular.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="../public/js/app.js"></script>
</head>
<body>
<div>
<label>Username:</label>
<input type="text" ng-model="username" placeholder="Enter a name here">
</div>
<div ng-controller="MainCtrl">
<form ng-submit="postUsername()">
<input type="submit" value="Send"> <br /><br />
<a ng-href="http://{{myurl}}">HTML5 CLIENT</a>
</form>
</div>
</body>
</html>