Closing the conference audio recording onClick

Oleksandr1997

New Member
Hello.
I was wondering, which method is required to stop the recording of audio on Web SDK (using conference for multiuser stream)? I looked at this example: https://github.com/flashphoner/flas...mples/demo/streaming/conference/conference.js and I didn't find the method to manually stop the recording. I tried using connection.disconnect() along with room.leave() and stream.stop(), but this didn't stop my tab recording audio even though the room.publish() returned status failed. Which method should I use to stop audio recording?
 

Oleksandr1997

New Member
I did the way u suggested, when I called the find method on my publishing stream, I got the following response:

data :
[
{
appKey: "roomApp",
sessionId:
"/85.222.123.34:63429/5.101.181.48:8443-873bc679-fdcd-420f-a204-316cec62c815",
mediaSessionId: "0f17e5b1-5f9d-11ea-bc70-1d8ac4eaa069",
name: "5e622777a08c790036fa3438-5e622770a271c7f2a2f10561-0f17",
published: true,
hasVideo: false,
hasAudio: true,
status: "PUBLISHING",
sdp:
"v=0\r\no=- 3154491441527085511 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=msid-semantic: WMS YWyE8Wy4p7UhZ0RTi1jjQi3fdeGuPC6PrZHf\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:jFG/\r\na=ice-pwd:wqH7dD34wrXSMghXs5oZpjSb\r\na=ice-options:trickle\r\na=fingerprint:sha-256 FD:E0:7A:01:42:95:D1:8B:DD:FE:1A:B9:92:32:2F:82:78:8A:16:53:E6:1C:6C:18:62:7E:DF:DD:AB:1A:D8:B2\r\na=setup:actpass\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=extmap:5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\r\na=extmap:6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\r\na=sendonly\r\na=msid:YWyE8Wy4p7UhZ0RTi1jjQi3fdeGuPC6PrZHf e1b9609f-4eff-4a61-a5d5-90ef0bc98926\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:112 telephone-event/32000\r\na=rtpmap:113 telephone-event/16000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:3781230850 cname:ZjFBrmo+COqgXqI0\r\na=ssrc:3781230850 msid:YWyE8Wy4p7UhZ0RTi1jjQi3fdeGuPC6PrZHf e1b9609f-4eff-4a61-a5d5-90ef0bc98926\r\na=ssrc:3781230850 mslabel:YWyE8Wy4p7UhZ0RTi1jjQi3fdeGuPC6PrZHf\r\na=ssrc:3781230850 label:e1b9609f-4eff-4a61-a5d5-90ef0bc98926\r\n",
audioCodec: "opus",
record: false,
width: 0,
height: 0,
bitrate: 0,
minBitrate: 0,
maxBitrate: 0,
quality: 0,
timeShift: 2060905,
history: false,
gop: 0,
fps: 0,
audioBitrate: 0,
codecImpl: "",
transport: "TCP",
cvoExtension: false,
createDate: 1583493877466,
mediaProvider: "WebRTC",
custom: { name: "5e622777a08c790036fa3438" },
origin: "http://localhost:8080",
constraints: { audio: true, video: false }
}
];

But then, when I try using this mediaSessionId in the stopRecording method I get the 500 error with the following response:
{
exception: "com.flashphoner.rest.server.exception.InternalErrorException",
path: "/rest-api/stream/stopRecording",
error: "Internal Server Error",
message: "Publish stream fileRecorder == null, id 832b7931-5f9d-11ea-b819-57014cd4c696",
timestamp: 1583494074367,
status: 500
}

What can be the reason for this issue?
 

Max

Administrator
Staff member
Good day.
We checked the log you've sent. It seems like the stream is not recording in mediasession for which you're trying to stop this operation. In this case, /rest-api/stream/stopRecording qurey returns 500 Internal Server Error with the following message (for example)
Code:
{
"exception": "com.flashphoner.rest.server.exception.InternalErrorException",
"path": "/rest-api/stream/stopRecording",
"error": "Internal Server Error",
"message": "Publish stream fileRecorder == null, id a5390d70-61a1-11ea-9841-3be91ab18fa9",
"timestamp": 1583715849803,
"status": 500
}
In latest WCS builds, you can check if stream in media session is recording with the /rest-api/recorder/find_all query. This query returns the mediasessions list with file names which are recording now.
 

Oleksandr1997

New Member
So, I do manage to find the recording stream, than I run the method to stop the recording. It is successful. But the tab still shows that the mic is recording. Do I have to manually close the mic on client? Do you have any advice how to do it?
Thank you very much for your responses and support - it helps a lot!
 

Oleksandr1997

New Member
I tried closing the recorder by both /stream/stopRecording and recorder/terminate. In first case the record stream returns the UNPUBLISHED status in the listener (the API method returns 200). In second case the state returned is FAILED (the API method also returns 200)
 

Max

Administrator
Staff member
Good day.
But the tab still shows that the mic is recording. Do I have to manually close the mic on client? Do you have any advice how to do it?
This shoud be done on client side. You should use Flashphoner.releaseLocalMedia() function. Please see the Media Device example on GitHub:
Code:
function stopTest() {
    releaseResourcesForTesting();
    if (Flashphoner.releaseLocalMedia(localVideo)) {
        $("#testBtn").text("Test").off('click').click(function () {
            $(this).prop('disabled', true);
            startTest();
        }).prop('disabled', false);
    } else {
        $("#testBtn").prop('disabled', false);
    }
}
I tried closing the recorder by both /stream/stopRecording and recorder/terminate. In first case the record stream returns the UNPUBLISHED status in the listener (the API method returns 200). In second case the state returned is FAILED (the API method also returns 200)
When stream recording is already stopped, but media session is still active and stream is still published, any subsequent /stream/stopRecording and /recorder/terminate calls return 200 OK. This is a small issue, and we raised internal ticket WCS-2584 to fix it. As workaround, please use /recorder/find_all query to detect if stream is recording.
 

Oleksandr1997

New Member
Good day.

This shoud be done on client side. You should use Flashphoner.releaseLocalMedia() function. Please see the Media Device example on GitHub:
Code:
function stopTest() {
    releaseResourcesForTesting();
    if (Flashphoner.releaseLocalMedia(localVideo)) {
        $("#testBtn").text("Test").off('click').click(function () {
            $(this).prop('disabled', true);
            startTest();
        }).prop('disabled', false);
    } else {
        $("#testBtn").prop('disabled', false);
    }
}
I tried Flashphoner.releaseLocalMedia() - it didn't stop the local microphone (still shows microphone in tab).
 

Max

Administrator
Staff member
Есть какое-то решение проблемы ?
Please use English in this forum section or ask your question in Russian section.
I tried Flashphoner.releaseLocalMedia() - it didn't stop the local microphone (still shows microphone in tab).
We made the following test in some browsers:
1. Changed video constraints to publish audio only
Code:
    var constraints = {
        audio: true,
        video: false
    };
2. Added releaseLocalMedia() call to OnMediaStopped handler function
Code:
function onMediaStopped(room) {
    var display = document.getElementById("localDisplay");
    Flashphoner.releaseLocalMedia(display);
    ...
}
3. Opened Conference example page and started a conference room by pressing "Join"
4. Pressed "Stop" to stop stream publishing or "Leave" to leave the conference.
5. Checked if the microphone is released in system settings and if microphone icon is still displayed by browser.
We got the following results:
- Chrome 80, Opera 67, MS Chromium Edge 80: the microphone is released, icon is still displayed
- Firefox 74, MS Edge 44.18362.449.0 (EdgeHTML), Safari 13.0.4: the microphone is released, icon is not displayed
So it seems like Chromium issue. Anyway, capture red icon in browser tab header is cleared, user can see that no video or sound is captured now. Perhaps Chromium shows access to microphone is allowed in this case:
upload_2020-3-11_11-34-58.png
 
Last edited:

Oleksandr1997

New Member
Our server url
https://server.witheyezon.com:8444

We have couple of questions:
1. Which user can close the conference (only maker?)
2. How many recordings are created after the conference ended? Is there possibility to make 1 recording with all the participants?
3. And what can be the reason that the methods us suggest - don't allow to close the recording from client? (it's not only the icon in our case - we can actually hear the person after he used releaseLocalMedia()?
 

Max

Administrator
Staff member
Can you show how to do correctly the "stop" stream button as it is done there?
Please review the Conference example source code.
When participant joins the room and publishes a stream, onMediaPublished() function is called by STREAM_STATUS.PUBLISHING handler
Code:
    ...
    }).on(STREAM_STATUS.PUBLISHING, function (stream) {
        setStatus("#localStatus", stream.status());
        onMediaPublished(stream);
    })
    ...
In onMediaPublished() function, handler function for "Stop" button is defined. The handler function calls stream.stop() on button click
Code:
    ...
    $("#localStopBtn").text("Stop").off('click').click(function(){
        $(this).prop('disabled', true);
        stream.stop();
    }).prop('disabled', false);
    ...
Then onMediaStopped() function is called by STREAM_STATUS.UNPUBLISHED handler
Code:
    ...
    }).on(STREAM_STATUS.UNPUBLISHED, function(stream) {
        setStatus("#localStatus", stream.status());
        onMediaStopped(room);
    });
    ...
You should place Flashphoner.releaseLocalMedia() call to onMediaStopped function as we've done while testing
Code:
function onMediaStopped(room) {
//// Add releaseLocalMedia here
//    var display = document.getElementById("localDisplay");
//    Flashphoner.releaseLocalMedia(display);
    $("#localStopBtn").text("Publish").off('click').click(function(){
        $(this).prop('disabled', true);
        publishLocalMedia(room);
    }).prop('disabled', (connection.getRooms().length == 0));
    $("#localAudioToggle").prop("disabled", true);
    $("#localVideoToggle").prop("disabled", true);
}
room.leave() function call also stops local stream publishing, so STREAM_STATUS.UNPUBLISHED will be received and onMediaStopped will be called.
1. Which user can close the conference (only maker?)
2. How many recordings are created after the conference ended? Is there possibility to make 1 recording with all the participants?
3. And what can be the reason that the methods us suggest - don't allow to close the recording from client? (it's not only the icon in our case - we can actually hear the person after he used releaseLocalMedia()?
1. A room will only be destroyed when all the participants will leave it. So, if conference maker leaves last, this will close a conference
2. If you enable sream recording in applicaltion code by addind record: true option here
Code:
    room.publish({
        display: display,
        constraints: constraints,
        record: true,
        receiveVideo: false,
        receiveAudio: false
all the published streams in conference will be recorded each to its own file. To make one recording with all the participant streams you should use stream mixer (note this requires a lot of CPU resources for video mixing) and record mixer output streams.
3. If you can actually hear the person, this means the stream publishing is not stopped. Please check if this can be reproduced in Conference example out-of-the-box (unchanged). If yes, please provide us SSH access to your server, we will check inplace. If no, please provade us your source code with minimal changes to reproduce the issue, we will review it.
-
 

Oleksandr1997

New Member
Please review the Conference example source code.
When participant joins the room and publishes a stream, onMediaPublished() function is called by STREAM_STATUS.PUBLISHING handler
Code:
    ...
    }).on(STREAM_STATUS.PUBLISHING, function (stream) {
        setStatus("#localStatus", stream.status());
        onMediaPublished(stream);
    })
    ...
In onMediaPublished() function, handler function for "Stop" button is defined. The handler function calls stream.stop() on button click
Code:
    ...
    $("#localStopBtn").text("Stop").off('click').click(function(){
        $(this).prop('disabled', true);
        stream.stop();
    }).prop('disabled', false);
    ...
Then onMediaStopped() function is called by STREAM_STATUS.UNPUBLISHED handler
Code:
    ...
    }).on(STREAM_STATUS.UNPUBLISHED, function(stream) {
        setStatus("#localStatus", stream.status());
        onMediaStopped(room);
    });
    ...
You should place Flashphoner.releaseLocalMedia() call to onMediaStopped function as we've done while testing
Code:
function onMediaStopped(room) {
//// Add releaseLocalMedia here
//    var display = document.getElementById("localDisplay");
//    Flashphoner.releaseLocalMedia(display);
    $("#localStopBtn").text("Publish").off('click').click(function(){
        $(this).prop('disabled', true);
        publishLocalMedia(room);
    }).prop('disabled', (connection.getRooms().length == 0));
    $("#localAudioToggle").prop("disabled", true);
    $("#localVideoToggle").prop("disabled", true);
}
room.leave() function call also stops local stream publishing, so STREAM_STATUS.UNPUBLISHED will be received and onMediaStopped will be called.

1. A room will only be destroyed when all the participants will leave it. So, if conference maker leaves last, this will close a conference
2. If you enable sream recording in applicaltion code by addind record: true option here
Code:
    room.publish({
        display: display,
        constraints: constraints,
        record: true,
        receiveVideo: false,
        receiveAudio: false
all the published streams in conference will be recorded each to its own file. To make one recording with all the participant streams you should use stream mixer (note this requires a lot of CPU resources for video mixing) and record mixer output streams.
3. If you can actually hear the person, this means the stream publishing is not stopped. Please check if this can be reproduced in Conference example out-of-the-box (unchanged). If yes, please provide us SSH access to your server, we will check inplace. If no, please provade us your source code with minimal changes to reproduce the issue, we will review it.
-
Thank you. In fact, if I room.leave() or stream.stop() - but don't mute the microphone beforehand - people in the room can still hear me (that was our main found bug). I implemented everything the way you suggested, just using stream.muteAudio before disconnect, allows to reach a temporary solution for us. I will test everything further to see what actually happens.
 

Max

Administrator
Staff member
WCS-2584 issue ( /stream/stopRecording and /recorder/terminate return 200 OK when recording is already stopped but the stream is not yet unpublished) has been fixed in v. 5.2.591.
 
Top