# Improper\_meeting\_state

**URL:** <https://devforum.zoom.us/t/improper-meeting-state/108720>\
**Category:** Web\
**Tags:** video-sdk\
**Created:** [April 26, 2024, 11:30am UTC](https://devforum.zoom.us/t/improper-meeting-state/108720 "2024-04-26T11:30:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gokul1342441](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gokul1342441/32/59097_2.png) [@gokul1342441](https://devforum.zoom.us/u/gokul1342441)\
**Post date:** [April 26, 2024, 11:30am UTC](https://devforum.zoom.us/t/improper-meeting-state/108720/1 "2024-04-26T11:30:31Z")

</div>

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.

```auto
{
     "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:

```auto
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 …

```auto
  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.

```auto
    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);
            }
        });
    }   

```

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [April 28, 2024, 3:09am UTC](https://devforum.zoom.us/t/improper-meeting-state/108720/2 "2024-04-28T03:09:12Z")

</div>

Hey @gokul1342441

Thank you for your feedback and sharing the code snippet.

From what I understand, you want to preview your video before joining the session using the `startLocalStream` method, right?

In your code, both `startVideo` and `attachVideo` are methods that can only be called within a session. If you need to preview, you can use the `localVideoTrack` feature. Here’s a simple example:

```javascript
const localVideo = ZoomVideo.createLocalVideoTrack();
await localVideo.start(videoElement);

```

> **[LocalVideoTrack | Zoom Video SDK for Web - 1.11.0](https://marketplacefront.zoom.us/sdk/custom/web/interfaces/LocalVideoTrack.html#start)**
>
> Documentation for Zoom Video SDK for Web - 1.11.0

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [May 28, 2024, 1:09pm UTC](https://devforum.zoom.us/t/improper-meeting-state/108720/3 "2024-05-28T13:09:31Z")

</div>

Closed on May 28, 2024, 1:09pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
