Hi, I just got this working then I was called off to do something else so the code may be a little sloppy but here are rough steps to get a token, then create, start and join a meeting. This is in ASP.NET MVC with C# and jQuery.
First, generate a token
static readonly char padding = { ‘=’ };
public static string GenerateToken(string apiKey, string apiSecret, string meetingNumber, string ts, string role)
{
string message = String.Format("{0}{1}{2}{3}", apiKey, meetingNumber, ts, role);
apiSecret = apiSecret ?? “”;
var encoding = new System.Text.ASCIIEncoding();
byte keyByte = encoding.GetBytes(apiSecret);
byte messageBytesTest = encoding.GetBytes(message);
string msgHashPreHmac = System.Convert.ToBase64String(messageBytesTest);
byte messageBytes = encoding.GetBytes(msgHashPreHmac);
using (var hmacsha256 = new HMACSHA256(keyByte))
{
byte hashmessage = hmacsha256.ComputeHash(messageBytes);
string msgHash = System.Convert.ToBase64String(hashmessage);
string token = String.Format("{0}.{1}.{2}.{3}.{4}", apiKey, meetingNumber, ts, role, msgHash);
var tokenBytes = System.Text.Encoding.UTF8.GetBytes(token);
return System.Convert.ToBase64String(tokenBytes).TrimEnd(padding);
}
}
Next, create a meeting. This is fetched in a .js file. The token passed in is the token created above. From the json, you can parse out the Meeting ID (id) and Meeting Password (password) for the new meeting and store it in the fields MeetingNumber and Password on the page.
public async Task CreateMeetingAsync(string token)
{
var stringContent = “{“topic”: “Test Meeting”,“type”: “1”,“timezone”: “America/Chicago”,“password”: “password”,“agenda”: “Test Agenda”,” +
““settings”: {“host_video”: “true”,“participant_video”: “false”,“cn_meeting”: “false”,“in_meeting”: “false”,“join_before_host”: “false”,” +
““mute_upon_entry”: “false”,“watermark”: “false”,“use_pmi”: “false”,“approval_type”: “0”,“registration_type”: “1”,“audio”: “both”,“auto_recording”: “none”}}”;
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(“https://api.zoom.us/v2/users/yourZoom@emailAddress.com/meetings”);
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue(“application/json”));//ACCEPT header
client.DefaultRequestHeaders.Add(“Authorization”, "Bearer " + token);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, “meetings”);
request.Content = new StringContent(stringContent,
Encoding.UTF8,
“application/json”);//CONTENT-TYPE header
HttpResponseMessage response = new HttpResponseMessage();
await client.SendAsync(request)
.ContinueWith(responseTask =>
{
Console.WriteLine(“Response: {0}”, responseTask.Result);
response = responseTask.Result;
});
var json = response.Content.ReadAsStringAsync();
return Json(json);
}
Then you will need to generate an access token for the meeting id you just received. Again, this is fetched in the .js file. I store this in a field called MeetingToken on the page.
public ActionResult GetMeetingAccessToken(string meetingNumber)
{
String ts = (ToTimestamp(DateTime.UtcNow.ToUniversalTime()) - 30000).ToString();
string role = “1”;
var result = GenerateToken(apiKey, apiSecret, meetingNumber, ts, role);
return Json(result);
}
Now you should have all the info you need to join the meeting via ZoomMtg. Below is a snippet of code from the .js file, $(‘#Role’) is 1
function joinMeeting() {
meetConfig.apiKey = API_KEY;
meetConfig.signature = $(’#MeetingToken’).val();
meetConfig.userName = $(’#Name’).val();
meetConfig.passWord = $(’#Password’).val();
meetConfig.role = $(’#Role’).val();
meetConfig.meetingNumber = $(’#MeetingNumber’).val();
ZoomMtg.init({
leaveUrl: meetConfig.leaveUrl,
isSupportAV: true,
debug: true,
success: function (res) {
ZoomMtg.join({
signature: meetConfig.signature,
apiKey: meetConfig.apiKey,
meetingNumber: meetConfig.meetingNumber,
userEmail: meetConfig.userEmail,
userName: meetConfig.userName,
passWord: meetConfig.passWord,
success: function (res) {
console.log(‘success’);
},
error: function (res) {
console.log(‘error’);
console.log(res);
},
})
},
error: function (error) {
console.log(‘error’);
}
});
ZoomMtg.inMeetingServiceListener(‘onUserJoin’, function (data) {
console.log(‘inMeetingServiceListener onUserJoin’, data);
});
ZoomMtg.inMeetingServiceListener(‘onUserLeave’, function (data) {
console.log(‘inMeetingServiceListener onUserLeave’, data);
});
ZoomMtg.inMeetingServiceListener(‘onUserIsInWaitingRoom’, function (data) {
console.log(‘inMeetingServiceListener onUserIsInWaitingRoom’, data);
});
ZoomMtg.inMeetingServiceListener(‘onMeetingStatus’, function (data) {
// {status: 1(connecting), 2(connected), 3(disconnected), 4(reconnecting)}
console.log(‘inMeetingServiceListener onMeetingStatus’, data);
});
}
Hope this helps!