It seems like you’re encountering an error with your Zoom SDK integration in an Angular application. The error you provided indicates an “IMPROPER_MEETING_STATE” with the reason being “closed”. This typically suggests that there’s an issue with the meeting state being improperly handled or closed unexpectedly.
{
"type" : "IMPROPER_MEETING_STATE",
"reason" : "closed"
}
Looking at your code, it appears you’re trying to initialize and join a Zoom meeting using the Zoom Video SDK within your Angular application. Here are a few things to consider:
import ZoomVideo from '@zoom/videosdk';
async startLocalStream(localVideoElement: HTMLElement): Promise<any> {
const zoomClient = ZoomVideo.createClient();
console.log("🚀 ~ TestService ~ startLocalStream ~ zoomClient:", zoomClient)
this.zoomSession = zoomClient.getMediaStream();
console.log("🚀 ~ TestService ~ startLocalStream ~ zoomSession:", this.zoomSession)
await this.zoomSession.startVideo();
const userVideo = await this.zoomSession.attachVideo(zoomClient.getCurrentUserInfo().userId, "720p");
console.log("🚀 ~ TestService ~ startLocalStream ~ userVideo:", userVideo)
localVideoElement.appendChild(userVideo);
return this.zoomSession;
}
async connectToRoom(token: string, roomName: string, userName: string): Promise<any> {
const zoomClient = ZoomVideo.createClient();
console.log("🚀 ~ TestService ~ connectToRoom ~ zoomClient:", zoomClient);
try {
await zoomClient.init('en-US', 'Global', { patchJsMedia: true });
await zoomClient.join(roomName, token, userName);
this.zoomSession = zoomClient.getMediaStream();
console.log("🚀 ~ TestService ~ returnzoomClient.join ~ this.zoomSession:", this.zoomSession);
} catch (error) {
console.error("Error during Zoom meeting initialization or join:", error);
}
}
this is my Angular Service file …
public async zoomsdk() {
return new Promise(async (resolved, rejected) => {
this.testService.getzoomsdkToken().subscribe(async (response: any) => {
console.log("🚀 ~ this.testService.getZoomsdkToken ~ response:", response)
if (this.dual_proctoring_test) {
const localVideoElement = this.localVideo.nativeElement;
console.log("🚀 ~ returnnewPromise ~ localVideoElement:", localVideoElement)
await this.testService.startLocalStream(localVideoElement);
const token = response.VIDEO_SDK_JWT; // Assume the token is now coming from the response
console.log("🚀 ~ this.testService.getzoomsdkToken ~ token:", token)
const sessionName = response.sessionName; // Define your session name
console.log("🚀 ~ this.testService.getzoomsdkToken ~ sessionName:", sessionName)
const userName = response.userName;
await this.testService.connectToRoom(token, sessionName, userName);
} else {
resolved(true);
}
});
});
}
Token Generation: Verify that your JWT token generation is correct. The token needs to be generated with the correct parameters including user_id
, userName
, roomName
, and sessionPasscode
. Make sure these parameters are properly set before generating the JWT token.
public static generateJWTZoom(user_id: string, userName: string, roomName: string, sessionPasscode: string) {
return new Promise(async (resolve, reject) => {
try {
const sdkKey = Utils.zoom_sdk_key;
const sdkSecret = Utils.zoom_sdk_secret;
const iat = Math.round(new Date().getTime() / 1000) - 30;
const exp = iat + 60 * 60 * 2;
const oHeader = { alg: 'HS256', typ: 'JWT' };
const oPayload = {
app_key: sdkKey,
tpc: roomName,
role_type: 1, // Assuming role 1 is for attendee, adjust as needed
session_key: '', // You may need to adjust this depending on your Zoom setup
user_identity: user_id,
version: 1,
iat: iat,
exp: exp,
user_name: userName, // Add userName to payload
session_passcode: sessionPasscode, // Add sessionPasscode to payload
geo_regions: "US,AU,CA,IN,CN,BR,MX,HK,SG,JP,DE,NL" // Add geo_regions to payload
};
const sHeader = JSON.stringify(oHeader);
const sPayload = JSON.stringify(oPayload);
// Ensure sdkSecret is provided to the JWT signing function
const sdkJWT = KJUR.jws.JWS.sign('HS256', sHeader, sPayload, sdkSecret);
resolve(sdkJWT);
} catch (error) {
console.error('Error generating Zoom JWT:', error);
reject(error);
}
});
}