Cleanup of the API Demos

git-svn-id: http://bigbluebutton.googlecode.com/svn/trunk@3453 af16638f-c34d-0410-8cfa-b39d5352b314
This commit is contained in:
Fred Dixon 2010-01-23 19:19:14 +00:00
parent cbe0c2bde8
commit ffd55fd5a1
5 changed files with 338 additions and 291 deletions

View File

@ -28,31 +28,33 @@ Author: Fred Dixon <ffdixon@bigbluebutton.org>
<%@ include file="bbb_api_conf.jsp"%>
<%!
//
// Create a meeting that does not require passwords
//
public String getJoinURL(String username, String meetingID) {
String checksum = "";
//
// Create a meeting and return a URL to join it
//
public String getJoinURL(String username, String meetingID, String welcome) {
String base_url_create = BigBlueButtonURL + "api/create?";
String base_url_join = BigBlueButtonURL + "api/join?";
String welcome_param = "";
String checksum = "";
Random random = new Random();
Integer voiceBridge = 70000 + random.nextInt(79999);
Integer voiceBridge = 70000 + random.nextInt(9999);
String create_parameters = "name=" + username + "&meetingID=" + meetingID
+ "&attendeePW=ap&moderatorPW=mp&voiceBridge="+voiceBridge;
if ( (welcome != null) && ! welcome.equals("")) {
welcome_param = "&welcome=" + urlEncode(welcome);
}
String create_parameters = "name=" + urlEncode(username) + "&meetingID=" + urlEncode(meetingID)
+ welcome_param + "&attendeePW=ap&moderatorPW=mp&voiceBridge="+voiceBridge;
Document doc = null;
try {
// Attempt to create a meeting of that name
String xml = getURL(base_url_create + create_parameters + "&checksum=" + checksum(create_parameters + salt) );
doc = parseXml(xml);
} catch (Exception e) {
e.printStackTrace();
}
@ -73,13 +75,15 @@ public String getJoinURL(String username, String meetingID) {
return base_url_join + join_parameters + "&checksum=" + checksum(join_parameters + salt);
}
return "";
return doc.getElementsByTagName("messageKey").item(0).getTextContent().trim()
+ ": " + doc.getElementsByTagName("message").item(0).getTextContent().trim();
}
public static String checksum(String s) {
String checksum = "";
try {
checksum = DigestUtils.shaHex(s);
checksum = org.apache.commons.codec.digest.DigestUtils.shaHex(s);
// checksum = DigestUtils.shaHex(s);
} catch (Exception e) {
e.printStackTrace();
}
@ -188,4 +192,15 @@ public String getJoinURL(String username, String meetingID) {
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new InputSource(new StringReader(xml)));
return doc;
}%>
}
public static String urlEncode(String s) {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
%>

View File

@ -26,7 +26,7 @@ Author: Fred Dixon <ffdixon@bigbluebutton.org>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>BigBlueButton API Demos</title>
<title>Join a Course</title>
</head>
<body>
@ -40,11 +40,10 @@ if (request.getParameterMap().isEmpty()) {
// Assume we want to create a meeting
//
%>
<a href="demo1.jsp">Join a Course</a> | <a href="demo2.jsp">Join a Selected Course</a> | <a href="demo3.jsp">Create Your Own Meeting</a> | <a href="/">Home</a>
<h2>Demo #1: Join a Course</h2>
<a href="demo1.jsp">Join a Meeting</a> | <a href="demo2.jsp">Join a Selected Meeting</a> | <a href="demo3.jsp">Create Your Own Meeting and Invite Others</a> | <a href="/">Home</a>
<hr />
<h2>Demo #1: Join the Demo Meeting.</h2>
<hr />
<FORM NAME="form1" METHOD="GET">
@ -55,7 +54,7 @@ if (request.getParameterMap().isEmpty()) {
<tr>
<td width="50%">
<p />Join <strong>Demo Meeting</strong>
<p />Join a Course.
</td>
<td width="50%">Enter your name: <input type="text"
name="username" /> <br />
@ -75,23 +74,27 @@ if (request.getParameterMap().isEmpty()) {
// Got an action=create
//
String username = URLEncoder.encode(request.getParameter("username"),"UTF-8");
String meetingID = URLEncoder.encode("Demo Meeting","UTF-8");
String joinURL = getJoinURL(username, meetingID);
//
// Request a URL to join a meeting called "Demo Meeting"
// Pass null for welcome message to use the default message (see defaultWelcomeMessage in bigbluebutton.properties)
//
String joinURL = getJoinURL(request.getParameter("username"), "Demo Meeting", null );
if ("".equals(joinURL)) {
%>
Error: getJoinURL() returned an empty URL
<%
} else {
if (joinURL.startsWith("http://")) {
%>
<script language="javascript" type="text/javascript">
window.location.href="<%=joinURL%>";
</script>
<%
} else {
%>
Error: getJoinURL() failed
<p/>
<%=joinURL %>
<%
}
}

View File

@ -26,13 +26,11 @@ Author: Fred Dixon <ffdixon@bigbluebutton.org>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>BigBlueButton API Demos</title>
<title>Join a Selected Course</title>
</head>
<body>
<%@ include file="bbb_api.jsp"%>
<%@ include file="demo_header.jsp"%>
<br>
@ -42,10 +40,16 @@ if (request.getParameterMap().isEmpty()) {
// Assume we want to create a meeting
//
%>
<a href="demo1.jsp">Join a Course</a>
|
<a href="demo2.jsp">Join a Selected Course</a>
|
<a href="demo3.jsp">Create Your Own Meeting</a>
|
<a href="/">Home</a>
<h2>Demo #2: Join a Selected Course</h2>
<hr />
<h2>Demo #2: Join a Selected Meeting.</h2>
<hr />
<FORM NAME="form1" METHOD="GET">
@ -54,24 +58,22 @@ if (request.getParameterMap().isEmpty()) {
border=3>
<tbody>
<tr>
<td width="50%">Join a selected meeting.
</td>
<td width="50%">Join a Selected Course.</td>
<td width="50%">
<p/>Enter your name: <input
type="text" name="username" /> <br />
<p />Enter your name: <input type="text" name="username" /> <br />
<INPUT TYPE=hidden NAME=action VALUE="create">
<p />Meeting:&nbsp;<select name="meetingID">
<p />Course:&nbsp;<select name="meetingID">
<option value="English 232">English 232</option>
<option value="English 300">English 300</option>
<option value="English 402">English 402</option>
<option value="Demo Meeting">Demo Meeting</option>
</select>
<p/>
<br />
<input type="submit" value="Join" /></td>
<p /><br />
<input type="submit" value="Join" />
</td>
</tr>
</tbody>
</table>
@ -84,27 +86,27 @@ if (request.getParameterMap().isEmpty()) {
// Got an action=create
//
String username = URLEncoder.encode(request.getParameter("username"),"UTF-8");
String meetingID = URLEncoder.encode(request.getParameter("meetingID"),"UTF-8");
String username = request.getParameter("username");
String meetingID = request.getParameter("meetingID");
String joinURL = getJoinURL(username, meetingID);
String joinURL = getJoinURL(username, meetingID, "Welcome %%CONFNAME%%." );
if ("".equals(joinURL)) {
%>
Error: getJoinURL() returned an empty URL
<%
} else {
if (joinURL.startsWith("http://")) {
%>
<script language="javascript" type="text/javascript">
window.location.href="<%=joinURL%>";
</script>
<% }
} %>
<%@ include file="demo_footer.jsp"%>
<%
} else {
%>
Error: getJoinURL() failed
<p /><%=joinURL%> <%
}
}
%> <%@ include file="demo_footer.jsp"%>
</body>
</html>

View File

@ -26,7 +26,7 @@ Author: Fred Dixon <ffdixon@bigbluebutton.org>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>API Demo - 3</title>
<title>Create Your Own Meeting</title>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
@ -38,8 +38,6 @@ Author: Fred Dixon <ffdixon@bigbluebutton.org>
<%@ include file="bbb_api.jsp"%>
<%@ include file="demo_header.jsp"%>
<%@ page import="java.util.regex.*"%>
<br>
@ -50,10 +48,15 @@ if (request.getParameterMap().isEmpty()) {
// Assume we want to create a meeting
//
%>
<a href="demo1.jsp">Join a Course</a>
|
<a href="demo2.jsp">Join a Selected Course</a>
|
<a href="demo3.jsp">Create Your Own Meeting</a>
|
<a href="/">Home</a>
<hr />
<h2>Demo #3: Create a You Own Meeting.</h2>
<hr />
<h2>Demo #3: Create Your Own Meeting</h2>
<p />
<FORM NAME="form1" METHOD="GET">
@ -77,6 +80,10 @@ if (request.getParameterMap().isEmpty()) {
</FORM>
<script>
//
// We could have asked the user for both their name and a meeting title, but we'll just use their name to create a title
// We'll use JQuery to dynamically update the button
//
$(document).ready(function(){
$("input[name='username1']").keyup(function() {
if ($("input[name='username1']").val() == "") {
@ -95,27 +102,33 @@ $(document).ready(function(){
//
String username = request.getParameter("username1");
String meetingID = URLEncoder.encode(username+"'s meeting","UTF-8");
String meetingID = username + "'s meeting";
String meetingToken = "";
String joinURL = getJoinURL(URLEncoder.encode(username,"UTF-8"), meetingID);
//
// This is the URL for to join the meeting as moderator
//
String joinURL = getJoinURL(username, meetingID, "Welcome to "
+ meetingID);
//
// We're going to extract the meetingToken to enable others to join as viewers
//
String p = "meetingToken=[^&]*";
Pattern pattern =
Pattern.compile( p );
Matcher matcher =
pattern.matcher( joinURL );
Pattern pattern = Pattern.compile(p);
Matcher matcher = pattern.matcher(joinURL);
if (matcher.find()) {
meetingToken = joinURL.substring(matcher.start(), matcher.end());
meetingToken = joinURL.substring(matcher.start(), matcher
.end());
} else {
out.print("Error: Did not find meeting token.");
}
//out.print ("Match : " + meetingToken );
String inviteURL = BigBlueButtonURL+"demo/demo3.jsp?action=invite&meetingID="+meetingID+"&"+meetingToken;
String inviteURL = BigBlueButtonURL
+ "demo/demo3.jsp?action=invite&meetingID=" + URLEncoder.encode(meetingID, "UTF-8")
+ "&" + meetingToken;
%>
<hr />
@ -136,14 +149,13 @@ $(document).ready(function(){
<td width="50%">
<p>&nbsp;</p>
Step 2. Invite others using the following <a
href="<%=inviteURL%>">link</a>:
Step 2. Invite others using the following <a href="<%=inviteURL%>">link</a>:
<form name="form2" method="POST"><textarea cols="60" rows="5"
name="myname" style="overflow: hidden">
<%=inviteURL%>
</textarea></form>
<p>&nbsp;<p />
Step 3. Click the following link to start your meeting:
<p>&nbsp;
<p />Step 3. Click the following link to start your meeting:
<p>&nbsp;</p>
<center><a href="<%=joinURL%>">Start Meeting</a></center>
<p>&nbsp;</p>
@ -160,7 +172,6 @@ $(document).ready(function(){
<%
} else if (request.getParameter("action").equals("enter")) {
//
// The user is now attempting to joing the meeting
@ -169,10 +180,13 @@ $(document).ready(function(){
String username = request.getParameter("username");
String meetingToken = request.getParameter("meetingToken");
String enterURL = BigBlueButtonURL+"demo/demo3.jsp?action=join&username="+URLEncoder.encode(username,"UTF-8")+"&meetingID="+URLEncoder.encode(meetingID,"UTF-8");
String enterURL = BigBlueButtonURL
+ "demo/demo3.jsp?action=join&username="
+ URLEncoder.encode(username, "UTF-8") + "&meetingID="
+ URLEncoder.encode(meetingID, "UTF-8");
if ( isMeetingRunning( meetingToken, URLEncoder.encode(meetingID,"UTF-8")).equals("true") ) {
if (isMeetingRunning(meetingToken,
URLEncoder.encode(meetingID, "UTF-8")).equals("true")) {
//
// The meeting has started -- bring the user into the meeting.
//
@ -185,8 +199,8 @@ $(document).ready(function(){
//
// The meeting has not yet started, so check until we get back the status that the meeting is running
//
String checkMeetingStatus = getURLisMeetingRunning(meetingToken, URLEncoder.encode(meetingID,"UTF-8") );
String checkMeetingStatus = getURLisMeetingRunning(
meetingToken, URLEncoder.encode(meetingID, "UTF-8"));
%>
<script type="text/javascript">
@ -225,7 +239,8 @@ function mycallback() {
<p>Hi <%=username%>,</p>
<p>Now waiting for the moderator to start <strong><%=meetingID%></strong>.</p>
<br />
<p>(Your browser will automatically refresh and join the meeting when it starts.)</p>
<p>(Your browser will automatically refresh and join the meeting
when it starts.)</p>
</td>
<td width="50%"><img src="polling.gif"></img></td>
</tr>
@ -242,8 +257,6 @@ function mycallback() {
//
String meetingID = request.getParameter("meetingID");
String meetingToken = request.getParameter("meetingToken");
%>
<hr />
@ -259,7 +272,8 @@ function mycallback() {
<tr>
<td width="50%">
<p />You have been invited to join<br/><strong><%=meetingID %></strong>.
<p />You have been invited to join<br />
<strong><%=meetingID%></strong>.
</td>
<td width="50%">Enter your name: <input type="text"
@ -282,16 +296,28 @@ function mycallback() {
//
// We have an invite request to join an existing meeting and the meeting is running
//
String username = URLEncoder.encode(request.getParameter("username"),"UTF-8");
String meetingID = URLEncoder.encode(request.getParameter("meetingID"),"UTF-8");
String joinURL = getJoinURL(username, meetingID);
// We don't need to pass a meeting descritpion as it's already been set by the first time
// the meeting was created.
String joinURL = getJoinURL(request.getParameter("username"), request.getParameter("meetingID"), null);
if (joinURL.startsWith("http://")) {
%>
<script language="javascript" type="text/javascript">
window.location.href="<%=joinURL%>";
</script>
<% } %>
<%
} else {
%>
Error: getJoinURL() failed
<p /><%=joinURL%>
<%
}
}
%>
<%@ include file="demo_footer.jsp"%>

View File

@ -1,13 +1,14 @@
<%@ page isErrorPage="true" %>
<%@ page language="java" %>
<%@ page import="java.util.*,java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%
Object statusCode = request.getAttribute("javax.servlet.error.status_code");
Object exceptionType = request.getAttribute("javax.servlet.error.exception_type");
Object message = request.getAttribute("javax.servlet.error.message");
%>
<html>
<head>
<title>Error Page</title>