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?";
Random random = new Random();
Integer voiceBridge = 70000 + random.nextInt(79999);
String welcome_param = "";
String checksum = "";
String create_parameters = "name=" + username + "&meetingID=" + meetingID
+ "&attendeePW=ap&moderatorPW=mp&voiceBridge="+voiceBridge;
Random random = new Random();
Integer voiceBridge = 70000 + random.nextInt(9999);
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);
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>
@ -39,12 +39,11 @@ 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,24 +74,28 @@ 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)) {
if (joinURL.startsWith("http://")) {
%>
Error: getJoinURL() returned an empty URL
<script language="javascript" type="text/javascript">
window.location.href="<%=joinURL%>";
</script>
<%
} else {
%>
<script language="javascript" type="text/javascript">
window.location.href="<%=joinURL%>";
</script>
Error: getJoinURL() failed
<p/>
<%=joinURL %>
<%
<%
}
}
%>

View File

@ -26,26 +26,30 @@ 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>
<%
if (request.getParameterMap().isEmpty()) {
//
// Assume we want to create a meeting
//
%>
<%
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>
@ -79,32 +81,32 @@ if (request.getParameterMap().isEmpty()) {
</FORM>
<%
} else if (request.getParameter("action").equals("create")) {
//
// Got an action=create
//
String username = URLEncoder.encode(request.getParameter("username"),"UTF-8");
String meetingID = URLEncoder.encode(request.getParameter("meetingID"),"UTF-8");
String joinURL = getJoinURL(username, meetingID);
} else if (request.getParameter("action").equals("create")) {
//
// Got an action=create
//
if ("".equals(joinURL)) {
%>
Error: getJoinURL() returned an empty URL
<%
} else {
String username = request.getParameter("username");
String meetingID = request.getParameter("meetingID");
String joinURL = getJoinURL(username, meetingID, "Welcome %%CONFNAME%%." );
if (joinURL.startsWith("http://")) {
%>
<script language="javascript" type="text/javascript">
window.location.href="<%=joinURL%>";
window.location.href="<%=joinURL%>";
</script>
<% }
} %>
<%@ include file="demo_footer.jsp"%>
<%
} else {
%>
Error: getJoinURL() failed
<p /><%=joinURL%> <%
}
}
%> <%@ include file="demo_footer.jsp"%>
</body>
</html>
</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,22 +38,25 @@ Author: Fred Dixon <ffdixon@bigbluebutton.org>
<%@ include file="bbb_api.jsp"%>
<%@ include file="demo_header.jsp"%>
<%@ page import="java.util.regex.*"%>
<br>
<%
if (request.getParameterMap().isEmpty()) {
//
// Assume we want to create a meeting
//
%>
<%
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() == "") {
@ -89,34 +96,40 @@ $(document).ready(function(){
</script>
<%
} else if (request.getParameter("action").equals("create")) {
//
// User has requested to create a meeting
//
String username = request.getParameter("username1");
String meetingID = URLEncoder.encode(username+"'s meeting","UTF-8");
} else if (request.getParameter("action").equals("create")) {
//
// User has requested to create a meeting
//
String meetingToken = "";
String joinURL = getJoinURL(URLEncoder.encode(username,"UTF-8"), meetingID);
String username = request.getParameter("username1");
String meetingID = username + "'s meeting";
String p = "meetingToken=[^&]*";
Pattern pattern =
Pattern.compile( p );
String meetingToken = "";
Matcher matcher =
pattern.matcher( joinURL );
if (matcher.find()) {
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;
%>
//
// 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);
if (matcher.find()) {
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=" + URLEncoder.encode(meetingID, "UTF-8")
+ "&" + meetingToken;
%>
<hr />
<h2>Meeting Created</h2>
@ -129,21 +142,20 @@ $(document).ready(function(){
<tbody>
<tr>
<td width="50%">
<center><strong> <%=username %>'s meeting</strong> has been
<center><strong> <%=username%>'s meeting</strong> has been
created.</center>
</td>
<td width="50%">
<p>&nbsp;</p>
Step 2. Invite others using the following <a
href="<%=inviteURL%>">link</a>:
<p>&nbsp;</p>
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,34 +172,36 @@ $(document).ready(function(){
<%
} else if (request.getParameter("action").equals("enter")) {
//
// The user is now attempting to joing the meeting
//
String meetingID = request.getParameter("meetingID");
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");
if ( isMeetingRunning( meetingToken, URLEncoder.encode(meetingID,"UTF-8")).equals("true") ) {
} else if (request.getParameter("action").equals("enter")) {
//
// The meeting has started -- bring the user into the meeting.
// The user is now attempting to joing the meeting
//
%>
String meetingID = request.getParameter("meetingID");
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");
if (isMeetingRunning(meetingToken,
URLEncoder.encode(meetingID, "UTF-8")).equals("true")) {
//
// The meeting has started -- bring the user into the meeting.
//
%>
<script type="text/javascript">
window.location = "<%=enterURL %>";
window.location = "<%=enterURL%>";
</script>
<%
<%
} else {
//
// 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") );
%>
//
// 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"));
%>
<script type="text/javascript">
$(document).ready(function(){
@ -204,14 +218,14 @@ function mycallback() {
// Not elegant, but works around a bug in IE8
var isMeetingRunning = ($("#HeartBeatDIV").text().search("true") > 0 );
if ( isMeetingRunning ) {
window.location = "<%=enterURL %>";
if ( isMeetingRunning) {
window.location = "<%=enterURL%>";
}
}
</script>
<hr />
<h2><strong><%=meetingID %></strong> has not yet started.</h2>
<h2><strong><%=meetingID%></strong> has not yet started.</h2>
<hr />
@ -222,10 +236,11 @@ function mycallback() {
<tr>
<td width="50%">
<p>Hi <%=username %>,</p>
<p>Now waiting for the moderator to start <strong><%=meetingID %></strong>.</p>
<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>
@ -235,16 +250,14 @@ function mycallback() {
<%
}
} else if (request.getParameter("action").equals("invite")) {
//
// We have an invite to an active meeting. Ask the person for their name
// so they can join.
//
String meetingID = request.getParameter("meetingID");
String meetingToken = request.getParameter("meetingToken");
%>
} else if (request.getParameter("action").equals("invite")) {
//
// We have an invite to an active meeting. Ask the person for their name
// so they can join.
//
String meetingID = request.getParameter("meetingID");
String meetingToken = request.getParameter("meetingToken");
%>
<hr />
<h2>Invite</h2>
@ -259,13 +272,14 @@ 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"
name="username" /> <br />
<INPUT TYPE=hidden NAME=meetingID VALUE="<%=meetingID %>"> <INPUT
TYPE=hidden NAME=meetingToken VALUE="<%=meetingToken %>"> <INPUT
<INPUT TYPE=hidden NAME=meetingID VALUE="<%=meetingID%>"> <INPUT
TYPE=hidden NAME=meetingToken VALUE="<%=meetingToken%>"> <INPUT
TYPE=hidden NAME=action VALUE="enter"> <br />
<input type="submit" value="Join" /></td>
</tr>
@ -278,20 +292,32 @@ function mycallback() {
<%
} else if (request.getParameter("action").equals("join")) {
//
// 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);
%>
} else if (request.getParameter("action").equals("join")) {
//
// We have an invite request to join an existing meeting and the meeting is running
//
// 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%>";
window.location.href="<%=joinURL%>";
</script>
<% } %>
<%
} else {
%>
Error: getJoinURL() failed
<p /><%=joinURL%>
<%
}
}
%>
<%@ include file="demo_footer.jsp"%>

View File

@ -1,120 +1,121 @@
<%@ page isErrorPage="true" %>
<%@ page language="java" %>
<%@ page import="java.util.*,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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<P><A href="<%=response.encodeURL(request.getContextPath()) %>">Home</A></P>
<hr>
<H2>An Error has occured:</H2>
<TABLE CELLPADDING="2" CELLSPACING="2" BORDER="1" WIDTH="100%">
<TR>
<TD WIDTH="20%"><B>Status Code</B></TD>
<TD WIDTH="80%"><%= statusCode %></TD>
</TR>
<TR>
<TD WIDTH="20%"><B>Exception Type</B></TD>
<TD WIDTH="80%"><%= exceptionType %></TD>
</TR>
<TR>
<TD WIDTH="20%"><B>Message</B></TD>
<TD WIDTH="80%"><%= message %></TD>
</TR>
<TR>
<TD WIDTH="20%"><B>Exception</B></TD>
<TD WIDTH="80%">
<%
if( exception != null )
{
out.print("<PRE>");
exception.printStackTrace(new PrintWriter(out));
out.print("</PRE>");
}
%>
</TD>
</TR>
<TR>
<TD WIDTH="20%"><B>Root Cause</B></TD>
<TD>
<%
if( (exception != null) && (exception instanceof ServletException) )
{
Throwable cause = ((ServletException)exception).getRootCause();
if( cause != null )
{
out.print("<PRE>");
cause.printStackTrace(new PrintWriter(out));
out.print("</PRE>");
}
}
%>
</TD>
</TR>
</TABLE>
<hr>
Header List
<table border=3>
<tr>
<td>Name</td>
<td>Value</td>
</tr>
<%
String name = "";
String value = "";
java.util.Enumeration headers = request.getHeaderNames();
while(headers.hasMoreElements())
{
name = (String) headers.nextElement();
value = request.getHeader(name);
%>
<tr>
<td><%=name%></td>
<td><%=value%></td>
</tr>
<%
}
%>
</table>
Attribute List
<!-- "javax.servlet.jsp.jspException" for getting an Exception -->
<table border=3>
<%
java.util.Enumeration attributes = request.getAttributeNames();
while(attributes.hasMoreElements())
{
name = (String) attributes.nextElement();
if (request.getAttribute(name) == null)
{
value = "null";
}
else
{
value = request.getAttribute(name).toString();
}
%>
<tr>
<td><%=name%></td>
<td><%=value%></td>
</tr>
<%
}
%>
</table>
</body>
</html>
<%@ page isErrorPage="true" %>
<%@ page language="java" %>
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<P><A href="<%=response.encodeURL(request.getContextPath()) %>">Home</A></P>
<hr>
<H2>An Error has occured:</H2>
<TABLE CELLPADDING="2" CELLSPACING="2" BORDER="1" WIDTH="100%">
<TR>
<TD WIDTH="20%"><B>Status Code</B></TD>
<TD WIDTH="80%"><%= statusCode %></TD>
</TR>
<TR>
<TD WIDTH="20%"><B>Exception Type</B></TD>
<TD WIDTH="80%"><%= exceptionType %></TD>
</TR>
<TR>
<TD WIDTH="20%"><B>Message</B></TD>
<TD WIDTH="80%"><%= message %></TD>
</TR>
<TR>
<TD WIDTH="20%"><B>Exception</B></TD>
<TD WIDTH="80%">
<%
if( exception != null )
{
out.print("<PRE>");
exception.printStackTrace(new PrintWriter(out));
out.print("</PRE>");
}
%>
</TD>
</TR>
<TR>
<TD WIDTH="20%"><B>Root Cause</B></TD>
<TD>
<%
if( (exception != null) && (exception instanceof ServletException) )
{
Throwable cause = ((ServletException)exception).getRootCause();
if( cause != null )
{
out.print("<PRE>");
cause.printStackTrace(new PrintWriter(out));
out.print("</PRE>");
}
}
%>
</TD>
</TR>
</TABLE>
<hr>
Header List
<table border=3>
<tr>
<td>Name</td>
<td>Value</td>
</tr>
<%
String name = "";
String value = "";
java.util.Enumeration headers = request.getHeaderNames();
while(headers.hasMoreElements())
{
name = (String) headers.nextElement();
value = request.getHeader(name);
%>
<tr>
<td><%=name%></td>
<td><%=value%></td>
</tr>
<%
}
%>
</table>
Attribute List
<!-- "javax.servlet.jsp.jspException" for getting an Exception -->
<table border=3>
<%
java.util.Enumeration attributes = request.getAttributeNames();
while(attributes.hasMoreElements())
{
name = (String) attributes.nextElement();
if (request.getAttribute(name) == null)
{
value = "null";
}
else
{
value = request.getAttribute(name).toString();
}
%>
<tr>
<td><%=name%></td>
<td><%=value%></td>
</tr>
<%
}
%>
</table>
</body>
</html>