diff options
author | Joas Schilling <coding@schilljs.com> | 2020-06-24 14:19:00 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-07-01 10:00:24 +0200 |
commit | 389d7b6bfc16a29ced52cb41b0e7fbb5facbb4c9 (patch) | |
tree | 1a6ba1d542926329f0957bd76d9a9fea59a55a36 /src/mixins/isInCall.js | |
parent | 5f83e2385c924b0612522a80ae312cdf87042751 (diff) |
Trigger a vue event when SessionStorage "joined_conversation" changes
Otherwise there is no update of the computed and the call screen will not show up.
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'src/mixins/isInCall.js')
-rw-r--r-- | src/mixins/isInCall.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/mixins/isInCall.js b/src/mixins/isInCall.js new file mode 100644 index 000000000..d2165bb48 --- /dev/null +++ b/src/mixins/isInCall.js @@ -0,0 +1,59 @@ +/** + * + * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +import { PARTICIPANT } from '../constants' +import SessionStorage from '../services/SessionStorage' +import { EventBus } from '../services/EventBus' + +/** + * A mixin to check whether the current session of a user is in a call or not. + * + * Components using this mixin require a "token" property and a "participant" property with, at least, the "inCall" property. + */ +export default { + + data() { + return { + sessionStorageJoinedConversation: null, + } + }, + + computed: { + isInCall() { + return this.sessionStorageJoinedConversation === this.token + && this.participant.inCall !== PARTICIPANT.CALL_FLAG.DISCONNECTED + }, + }, + + beforeDestroy() { + EventBus.$off('joinedConversation', this.readSessionStorageJoinedConversation) + }, + + beforeMount() { + EventBus.$on('joinedConversation', this.readSessionStorageJoinedConversation) + }, + + methods: { + readSessionStorageJoinedConversation() { + this.sessionStorageJoinedConversation = SessionStorage.getItem('joined_conversation') + }, + }, +} |