# How to know if Recording is running in session or not?

**URL:** <https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444>\
**Category:** How to implement?\
**Tags:** v2\
**Created:** [December 16, 2020, 8:44am UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444 "2020-12-16T08:44:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![saket](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/saket/32/1217_2.png) [@saket](https://openvidu.discourse.group/u/saket)\
**Post date:** [December 16, 2020, 8:44am UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444/1 "2020-12-16T08:44:24Z")

</div>

How to know if Recording is running in session or not ?

One way i can think is get all recording list and then filter out by session id and recording status… but is there any other direct way where i can get this flag by session object or some other way ?

---

<div class="post-metadata">

**Author:** ![Sivuyile\_Magutywa](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/sivuyile_magutywa/32/262_2.png) [@Sivuyile\_Magutywa](https://openvidu.discourse.group/u/Sivuyile_Magutywa)\
**Post date:** [December 16, 2020, 2:52pm UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444/2 "2020-12-16T14:52:39Z")

</div>

This is how I get recordings

const session = openvidu.initSession();

session.on(‘recordingStarted’, (event) =\> {  
// Add Code Here  
});

session.on(‘recordingStopped’, (event) =\> {  
// Add Code Here  
});

---

<div class="post-metadata">

**Author:** ![Sivuyile\_Magutywa](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/sivuyile_magutywa/32/262_2.png) [@Sivuyile\_Magutywa](https://openvidu.discourse.group/u/Sivuyile_Magutywa)\
**Post date:** [December 16, 2020, 2:59pm UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444/3 "2020-12-16T14:59:04Z")

</div>

I use angular, so I have a service for OpenVidu. If you are interested I can show you the full implementation. I use `BehaviorSubject` and full disclaimer I am not an RXJS expert

```
 // Recording
 public recordState = new BehaviorSubject<boolean>(false);

session.on(‘recordingStarted’, (event) => {
       this.recordState.next(true);
});

session.on(‘recordingStopped’, (event) => {
       this.recordState.next(false);
});

```

In my components

```
isRecording: boolean

ngOnInit(): void {
     this.openviduService.recordState.subscribe(
         (recording) => (this.isRecording = recording)
     );
}

```

And also don’t forget to unsubscribe.

---

<div class="post-metadata">

**Author:** ![saket](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/saket/32/1217_2.png) [@saket](https://openvidu.discourse.group/u/saket)\
**Post date:** [December 16, 2020, 3:15pm UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444/4 "2020-12-16T15:15:11Z")

</div>

I am Using Java client with ui made of plain javascript . Where user start recording from browser and suppose he closed or refresh the page without stopping the recording and come back to same session within few time then I need to find out if is there any recoding is already running or not in that session so that on ui I can show start/stop button accordingly.

---

<div class="post-metadata">

**Author:** ![Sivuyile\_Magutywa](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/sivuyile_magutywa/32/262_2.png) [@Sivuyile\_Magutywa](https://openvidu.discourse.group/u/Sivuyile_Magutywa)\
**Post date:** [December 16, 2020, 4:03pm UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444/5 "2020-12-16T16:03:28Z")

</div>

Oh I see, then you just need to get the recording, this for REST API

### `/openvidu/api/recordings/<RECORDING_ID>`

In my case RECORDING\_ID is the SessionID since it’s always unique and never reused

this recturns Recording Object

```auto
{
    "id": "ses_YnDaGYNcd7",
    "object": "recording",
    "name": "MyRecording",
    "outputMode": "COMPOSED",
    "hasAudio": true,
    "hasVideo": true,
    "resolution": "1280x720",
    "recordingLayout": "CUSTOM",
    "customLayout": "",
    "sessionId": "ses_YnDaGYNcd7",
    "createdAt": 1600564785109,
    "size": 303072692,
    "duration": 108000.234,
    "url": "https://my.openvidu.ip/openvidu/recordings/ses_YnDaGYNcd7/MyRecording.mp4",
    "status": "ready"
}

```

Look at the `status`  
`starting`, `started`, `stopped`, `ready`, `failed`

---

<div class="post-metadata">

**Author:** ![Sivuyile\_Magutywa](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/sivuyile_magutywa/32/262_2.png) [@Sivuyile\_Magutywa](https://openvidu.discourse.group/u/Sivuyile_Magutywa)\
**Post date:** [December 16, 2020, 4:18pm UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444/6 "2020-12-16T16:18:12Z")

</div>

For Java

```auto
// Get recording
Recording recordingRetrieved = openvidu.getRecording(recordingId);

```

---

<div class="post-metadata">

**Author:** ![saket](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/saket/32/1217_2.png) [@saket](https://openvidu.discourse.group/u/saket)\
**Post date:** [December 16, 2020, 4:26pm UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444/7 "2020-12-16T16:26:31Z")

</div>

Yes in this way we can get details but in my case there might be multiple recording exist in same session as I do start- stop and again start recording. So either I need keep track of running recording of each session on server OR need to get all recording and then filter by session Id and then get recording of status of started.

---

<div class="post-metadata">

**Author:** ![adad](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@adad](https://openvidu.discourse.group/u/adad)\
**Post date:** [December 16, 2020, 4:33pm UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444/8 "2020-12-16T16:33:55Z")

</div>

Just call the REST API `/openvidu/api/sessions/<SESSION_ID>` to retrieve the session details. There is a property `recording` which is true when a recording is currently active.

---

<div class="post-metadata">

**Author:** ![Sivuyile\_Magutywa](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/sivuyile_magutywa/32/262_2.png) [@Sivuyile\_Magutywa](https://openvidu.discourse.group/u/Sivuyile_Magutywa)\
**Post date:** [December 16, 2020, 4:39pm UTC](https://openvidu.discourse.group/t/how-to-know-if-recording-is-running-in-session-or-not/2444/9 "2020-12-16T16:39:18Z")

</div>

In my case, it’s always the Session ID + some number.

For example, if Session ID is `6MEBpdT0SLa4lIBDizLe` RecordingID will `6MEBpdT0SLa4lIBDizLe-1` or `6MEBpdT0SLa4lIBDizLe-2` and also I keep track of my RecordingID using Browser Local Storage if the user refreshes the Page I then Check for recordings, if one already exists is still running I then Updated my UI, or If fails to retrieve recording the user I notify the user to start a new recording.
