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!