[IMP] mail: automatically ask for media access when relevant

Ask for camera/microphone access when landing on the WelcomeView of a
channel created via the "Start a meeting" feature.

Part of task 2651831.

closes odoo/odoo#77011

X-original-commit: ef92577ae2ef602c279b47c5c0b1235334d5984c
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Louis Wicket (wil)
2021-09-23 10:00:16 +00:00
parent 9efd9463eb
commit 4e45ce9d06
4 changed files with 50 additions and 10 deletions
@@ -164,12 +164,22 @@ function factory(dependencies) {
audioStream: attr({
default: null,
}),
/**
* States whether the browser has the required APIs for
* microphone/camera recording.
*/
doesBrowserSupportMediaDevices: attr({
compute: '_computeDoesBrowserSupportMediaDevices',
}),
/**
* States if the user's microphone is currently recording.
*/
isMicrophoneEnabled: attr({
compute: '_computeIsMicrophoneEnabled',
}),
/**
* States if the user's camera is currently recording.
*/
isVideoEnabled: attr({
compute: '_computeIsVideoEnabled',
}),
@@ -78,7 +78,7 @@ function factory(dependencies) {
if (this.messaging.currentGuest) {
await this.messaging.models['mail.welcome_view'].updateGuestNameServerSide(this.pendingGuestName.trim());
}
browser.location.href = `/discuss/channel/${this.channelId}`;
browser.location.href = `/discuss/channel/${this.channel.id}`;
}
//----------------------------------------------------------------------
@@ -119,27 +119,52 @@ function factory(dependencies) {
}
WelcomeView.fields = {
channelId: attr({
/**
* The channel to redirect to once the user clicks on the 'joinButton'.
*/
channel: one2one('mail.thread', {
required: true,
}),
/**
* Used as value for `id`, `for`, and `name` attributes of the guest
* Used as a value for `id`, `for`, and `name` attributes of the guest
* name input and its label. Necessary to ensure the uniqueness.
*/
guestNameInputUniqueId: attr({
default: `o_WelcomeView_guestNameInput_${getNextGuestNameInputId()}`,
}),
/**
* Ref the to input element containing the 'pendingGuestName'.
*/
guestNameInputRef: attr(),
/**
* Determines whether the 'guestNameInput' should be focused the next
* time the component is updated.
*/
isDoFocusGuestNameInput: attr(),
/**
* Determines whether the 'joinButton' is disabled.
*
* Shall be disabled when 'pendingGuestName' is an empty string or when
* the current user is not a guest.
*/
isJoinButtonDisabled: attr({
compute: '_computeIsJoinButtonDisabled'
}),
/**
* The MediaPreview linked to the current WelcomeView.
*/
mediaPreview: one2one('mail.media_preview', {
default: create(),
isCausal: true,
readonly: true,
required: true,
}),
/**
* The value of the 'guestNameInput'.
*
* Will be used to update the current guest's name when joining the
* channel by clicking on the 'joinButton'.
*/
pendingGuestName: attr(),
};
@@ -1,6 +1,6 @@
/** @odoo-module **/
import { insert } from '@mail/model/model_field_command';
import { insert, link } from '@mail/model/model_field_command';
import { MessagingService } from '@mail/services/messaging/messaging';
import { getMessagingComponent } from '@mail/utils/messaging_component';
@@ -85,11 +85,14 @@ export async function boot() {
}
}
async function createWelcomeView(channelId) {
async function createWelcomeView(channelData) {
const messaging = await owl.Component.env.services.messaging.get();
const channel = messaging.models['mail.thread'].insert(
messaging.models['mail.thread'].convertData(channelData)
);
const WelcomeView = getMessagingComponent('WelcomeView');
const welcomeView = messaging.models['mail.welcome_view'].create({
channelId,
channel: link(channel),
isDoFocusGuestNameInput: true,
pendingGuestName: messaging.currentGuest && messaging.currentGuest.name,
});
@@ -97,6 +100,10 @@ export async function boot() {
localId: welcomeView.localId,
});
await welcomeViewComponent.mount(document.body);
if (welcomeView.channel.defaultDisplayMode === 'video_full_screen') {
welcomeView.mediaPreview.enableMicrophone();
welcomeView.mediaPreview.enableVideo();
}
}
return { createThreadViewFromChannelData, createWelcomeView };
@@ -41,8 +41,7 @@
odoo.define('mail.discuss_public_boot_channel', async function(require) {
const { boot } = require('@mail/public/discuss_public_boot');
const { createThreadViewFromChannelData } = await boot();
const channelData = <t t-out="json.dumps(channel_sudo.channel_info()[0])"/>;
createThreadViewFromChannelData(channelData);
createThreadViewFromChannelData(<t t-out="json.dumps(channel_sudo.channel_info()[0])"/>);
});
</script>
</t>
@@ -56,8 +55,7 @@
odoo.define('mail.discuss_public_boot_welcome_view', async function(require) {
const { boot } = require('@mail/public/discuss_public_boot');
const { createWelcomeView } = await boot();
const channelId = <t t-out="channel_sudo.id"/>;
createWelcomeView(channelId);
createWelcomeView(<t t-out="json.dumps(channel_sudo.channel_info()[0])"/>);
});
</script>
</t>