Skip to content

Instantly share code, notes, and snippets.

@petedoyle
Created December 30, 2010 23:57
Show Gist options
  • Save petedoyle/760505 to your computer and use it in GitHub Desktop.
Save petedoyle/760505 to your computer and use it in GitHub Desktop.
BBB url creation
// CONFIG:
def apiBaseUrl = "http://conf.cotni.org/bigbluebutton/api" // no trailing '/' please
def salt = "26f31c52-6d4f-4562-b3c7-fd7857d191ac"
def phoneNumber = "360-536-4392" // the number to join the conference via phone
def meetingParams = [
name: 71000,
meetingID: 71000,
attendeePW: 7777,
moderatorPW: 8888,
voiceBridge: 71000,
dialNumber: phoneNumber,
welcome: "Welcome to the conference! To access this conference via phone, please call $phoneNumber."
]
def moderators = [ "Les" ]
def attendees = [ "Pete", "Bob", "Larry" ]
// Initialize ApiService, so we can use it to create signed links
def apiService = new ApiService( baseUrl: apiBaseUrl, salt: salt )
// Create URLs
def createMeetingUrl = apiService.getSignedApiUrl( "create", meetingParams ) // meeting creation url
def isMeetingRunningUrl = apiService.getSignedApiUrl( "isMeetingRunning", [meetingID: meetingParams.meetingID] ) // Is meeting running url
def meetingInfoUrl = apiService.getSignedApiUrl( "getMeetingInfo", [meetingID: meetingParams.meetingID, password: meetingParams.moderatorPW] ) // getMeetingInfo url
def meetingsUrl = apiService.getSignedApiUrl( "getMeetings", [random: "dummytext"] ) // getMeetings url
def endMeetingUrl = apiService.getSignedApiUrl( "end", [meetingID: meetingParams.meetingID, password: meetingParams.moderatorPW] ) // end meeting url
// Print Meeting Info & Control URLs
println """
Meeting Params:
$meetingParams
Meeting Control URLs:
Is running?: $isMeetingRunningUrl
Create meeting: $createMeetingUrl
Meeting info: $meetingInfoUrl
List Meetings: $meetingsUrl
End meeting: $endMeetingUrl
"""
// Generate and Print JOIN URLs for Moderators
println "Join Meeting URLs:"
println " Moderators:"
moderators.each {
def url = apiService.getSignedApiUrl( "join", [fullName: it, meetingID: meetingParams.meetingID, password: meetingParams.moderatorPW] )
printf( "%16s: %s %n", it, url )
}
// Generate and Print JOIN URLs for Attendees
println "\n Attendees:"
attendees.each {
def url = apiService.getSignedApiUrl( "join", [fullName: it, meetingID: meetingParams.meetingID, password: meetingParams.attendeePW] )
printf( "%16s: %s %n", it, url )
}
// ApiService class used to build API URLs with checksums
import java.security.MessageDigest;
class ApiService {
static transactional = true
private static final String DEFAULT_BASE_URL = "http://example.com/bigbluebutton/api"
private static final String DEFAULT_SALT = "<DEFAULT_SALT>"
private String salt = DEFAULT_SALT
private String baseUrl = DEFAULT_BASE_URL
def messageDigest = MessageDigest.getInstance( "SHA1" )
def getSignedApiUrl(String command, Map params) {
baseUrl + "/" + command + buildQueryString( command, params ) + "&checksum=" + calculateChecksumValue( command, params )
}
/**
* Returns the query string without the &checksum= parameter
*/
private String buildQueryString(String command, Map params) {
"?" + params.collect { it.key + "=" + URLEncoder.encode( "${it.value}", "UTF-8" )}.join("&")
}
/**
* Returns the checksum value for a given API call
*/
private String calculateChecksumValue(String command, Map params) {
String checksumString = buildChecksumString( command, params )
BigInteger sha1 = new BigInteger( 1, messageDigest.digest( checksumString.getBytes() ) )
sha1.toString(16).padLeft(40, '0')
}
/**
* Builds the checksum string in the form of {command}+{query string}+{salt}.
* example: joinfullName=Les&meetingID=71000&password=888826f31c52-6d4f-4562-b3c7-fd7857d191ac
*/
private String buildChecksumString(String command, Map params) {
command + params.collect { it.key + "=" + URLEncoder.encode( "${it.value}", "UTF-8" ) }.join( "&" ) + salt
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment