Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Free media devices before switch in Jason (#160, #27)
Browse files Browse the repository at this point in the history
- add 'rollback_on_fail' flag to the Room.set_local_media_settings() method
- add 'stop_first' flag to the Room.set_local_media_settings() method
  • Loading branch information
evdokimovs authored Dec 18, 2020
1 parent 49914b1 commit ced3ef4
Show file tree
Hide file tree
Showing 15 changed files with 1,218 additions and 388 deletions.
196 changes: 99 additions & 97 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion jason/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ All user visible changes to this project will be documented in this file. This p
- `Jason.init_room()` ([#46]);
- `Room.join()` ([#46]);
- `Jason.close_room()` ([#147]).
- Ability to configure local media stream used by `Room` via `Room.set_local_media_settings()` ([#54], [#97], [#145]);
- Ability to configure local media stream used by `Room` via `Room.set_local_media_settings()` ([#54], [#97], [#145], [#160]):
- `Room.set_local_media_settings()` can be configured to stop used tracks before trying to acquire new tracks ([#160]);
- `Room.set_local_media_settings()` can be configured to rollback to previous settings if fail to set new settings ([#160]).
- `Room.on_failed_local_media` callback ([#54], [#143]);
- `Room.on_close` callback for WebSocket close initiated by server ([#55]);
- `RemoteMediaTrack.on_enabled` and `RemoteMediaTrack.on_disabled` callbacks being called when `RemoteMediaTrack` is enabled or disabled ([#123], [#143], [#156]);
Expand Down Expand Up @@ -132,6 +134,7 @@ All user visible changes to this project will be documented in this file. This p
[#155]: /../../pull/155
[#156]: /../../pull/156
[#158]: /../../pull/158
[#160]: /../../pull/160



Expand Down
1 change: 1 addition & 0 deletions jason/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ default = ["console_error_panic_hook", "wee_alloc"]
mockable = ["downcast", "fragile", "mockall", "predicates-tree"]

[dependencies]
async-recursion = "0.3"
async-trait = "0.1"
bitflags = "1.2"
console_error_panic_hook = { version = "0.1", optional = true }
Expand Down
33 changes: 22 additions & 11 deletions jason/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
.media_manager()
.init_local_tracks(constraints);
await updateLocalVideo(localTracks);
await room.set_local_media_settings(constraints);
await room.set_local_media_settings(constraints, false, false);
}

async function isVideoEnabledListener(e) {
Expand All @@ -398,7 +398,7 @@
.media_manager()
.init_local_tracks(constraints);
await updateLocalVideo(localTracks);
await room.set_local_media_settings(constraints);
await room.set_local_media_settings(constraints, false, false);
}

function bindJoinButtons(roomId) {
Expand Down Expand Up @@ -509,10 +509,7 @@
track.free();
}
}
if (isAudioSendEnabled) {
constraints = await initLocalStream();
}
await room.set_local_media_settings(constraints);
await room.set_local_media_settings(constraints, false, true);
});

let videoSwitch = async () => {
Expand All @@ -522,10 +519,24 @@
track.free();
}
}
if (isVideoSendEnabled) {
constraints = await initLocalStream();
try {
if (!isCallStarted) {
await initLocalStream();
}
await room.set_local_media_settings(constraints, true, true);
} catch (e) {
let name = e.name();
if (name === 'RecoveredException') {
alert('MediaStreamSettings set failed and current MediaStreamSettings was successfully recovered.');
} else if (name === 'RecoverFailedException') {
alert('MediaStreamSettings set failed and MediaStreamSettings recovery failed.');
for (const err of e.recover_fail_reasons()) {
console.error('Name: "' + err.name() + '";\nMessage: "' + err.message() + '";');
}
} else if (name === 'ErroredException') {
alert('Fatal error occured while MediaStreamSettings update.');
}
}
await room.set_local_media_settings(constraints);
};
videoSelect.addEventListener('change', videoSwitch);
screenshareSwitchEl.addEventListener('change', videoSwitch);
Expand Down Expand Up @@ -762,7 +773,7 @@

const constraints = await initLocalStream();
await fillMediaDevicesInputs(audioSelect, videoSelect);
await room.set_local_media_settings(constraints);
await room.set_local_media_settings(constraints, false, false);
} else {
chooseRoomButton.onclick = async function () {
let roomId = roomIdInput.value;
Expand All @@ -772,7 +783,7 @@

const constraints = await initLocalStream();
await fillMediaDevicesInputs(audioSelect, videoSelect);
await room.set_local_media_settings(constraints);
await room.set_local_media_settings(constraints, false, false);

chooseRoomDiv.style.display = 'none';
videoCallDiv.style.display = '';
Expand Down
25 changes: 20 additions & 5 deletions jason/e2e-demo/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ window.onload = async function() {
try {
const constraints = await initLocalStream();
await fillMediaDevicesInputs(audioSelect, videoSelect, null);
await room.set_local_media_settings(constraints);
await room.set_local_media_settings(constraints, false, false);
} catch (e) {
console.error('Init local video failed: ' + e);
}
Expand Down Expand Up @@ -747,7 +747,7 @@ window.onload = async function() {
if (!isAudioSendEnabled) {
constraints = await initLocalStream();
}
await room.set_local_media_settings(constraints);
await room.set_local_media_settings(constraints, false, true);
} catch (e) {
console.error('Changing audio source failed: ' + e);
}
Expand All @@ -761,10 +761,25 @@ window.onload = async function() {
track.free();
}
}
if (isVideoSendEnabled) {
constraints = await initLocalStream();
try {
if (!isCallStarted) {
await initLocalStream();
}
await room.set_local_media_settings(constraints, true, true);
} catch (e) {
let name = e.name();
if (name === 'RecoveredException') {
alert('MediaStreamSettings set failed and current MediaStreamSettings was successfully recovered.');
} else if (name === 'RecoverFailedException') {
alert('MediaStreamSettings set failed and MediaStreamSettings recovery failed.');
for (const err of e.recover_fail_reasons()) {
console.error('Name: "' + err.name() + '";\nMessage: "' + err.message() + '";');
}
} else if (name === 'ErroredException') {
alert('Fatal error occured while MediaStreamSettings update.');
}
console.error("Changing video source failed: " + name);
}
await room.set_local_media_settings(constraints);
} catch (e) {
console.error('Changing video source failed: ' + e.message());
}
Expand Down
5 changes: 4 additions & 1 deletion jason/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ use crate::{
#[doc(inline)]
pub use self::{
connection::{Connection, ConnectionHandle, Connections},
room::{Room, RoomCloseReason, RoomError, RoomHandle, WeakRoom},
room::{
ConstraintsUpdateException, Room, RoomCloseReason, RoomError,
RoomHandle, WeakRoom,
},
};

/// General library interface.
Expand Down
Loading

0 comments on commit ced3ef4

Please sign in to comment.