Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webrtc): restored with iridium #4188

Merged
merged 44 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
16ace82
chore(call): create call
AlexZakablukov Jul 8, 2022
5340957
chore(call): call permisions
AlexZakablukov Jul 13, 2022
cdfebdc
chore(calls): create iridium webrtc manager
AlexZakablukov Jul 14, 2022
83c153c
chore(calls): subscribe to channel
AlexZakablukov Jul 15, 2022
eeb63f9
chore(calls): change recepient
AlexZakablukov Jul 18, 2022
4113614
chore(calls): trasfer logic from webrtc/actions
AlexZakablukov Jul 19, 2022
98eea3a
chore(webrtc): setup listeners
molimauro Jul 19, 2022
ff7a10c
chore(calls): setup listeners, call logic
AlexZakablukov Jul 19, 2022
e8e9578
chore(calls): subscribeToAnnounce
AlexZakablukov Jul 20, 2022
ee3131a
chore(calls): getFriends and updateDetails
AlexZakablukov Jul 20, 2022
76d4e50
chore(calls): change updateDetails to updateFriend, show user status …
AlexZakablukov Jul 20, 2022
4bd40c9
chore(calls): user statuses
AlexZakablukov Jul 21, 2022
ca399be
chore(calls): createConversation participants
AlexZakablukov Jul 21, 2022
ecc5bb1
chore(calls): init webRTC manager
AlexZakablukov Jul 21, 2022
be8cfbd
chore(calls): incoming call
AlexZakablukov Jul 22, 2022
f52aae6
chore(calls): call.ts subscribe to channel
AlexZakablukov Jul 22, 2022
93dd9d2
chore: random users
molimauro Jul 22, 2022
9e2b41e
chore(calls): webrtc subscribe to broadcast
AlexZakablukov Jul 22, 2022
53db4d8
chore(call): accept, deny, hangUp call logic to webrtc manager
AlexZakablukov Jul 22, 2022
a73e906
chore(call): active call
AlexZakablukov Jul 22, 2022
8bdfdbf
fix: hangup for other user
molimauro Jul 22, 2022
c23bca0
chore(calls): mute/unmute calls
AlexZakablukov Jul 25, 2022
9f25ab7
chore(calls): change saveConversation to updateConversation
AlexZakablukov Jul 25, 2022
4acdf4c
chore(calls): rebased, add sound on accept/deny/hangup/call
AlexZakablukov Jul 26, 2022
387c8f5
chore(calls): create local_track_unmute event
AlexZakablukov Jul 26, 2022
97105e2
fix: set isCallee
molimauro Jul 26, 2022
bf2dc6f
fix(calls): call on permissions denied
AlexZakablukov Jul 27, 2022
d4cff75
chore(calls): webrtc state
AlexZakablukov Jul 28, 2022
1b787a4
chore(calls): remove store/webrtc
AlexZakablukov Jul 29, 2022
9a99c9a
chore(conversations): remove store/conversations
AlexZakablukov Jul 29, 2022
38d2fb4
chore(calls): webrtc toggleMute
AlexZakablukov Jul 29, 2022
ca08e43
fix(calls): remove peer:destroy
AlexZakablukov Aug 1, 2022
98bd3f1
fix(calls): add peer:typing
AlexZakablukov Aug 1, 2022
af4b701
fix(calls): add audio stream to bg call
AlexZakablukov Aug 1, 2022
1d17169
fix(calls): online/offline status
AlexZakablukov Aug 1, 2022
6c63b3e
feat(calls): add border on talking
AlexZakablukov Aug 2, 2022
66bacf6
fix(calls): detect who talking
AlexZakablukov Aug 3, 2022
54b3830
feat(pip): first draft
molimauro Aug 3, 2022
d4988dc
feat(calls): call preview
AlexZakablukov Aug 3, 2022
29b5af2
fix(calls): fix call preview
AlexZakablukov Aug 3, 2022
521c37c
fix(calls): ui for pending call
AlexZakablukov Aug 4, 2022
39fde9c
chore(merge): iridium-dev merged
molimauro Aug 8, 2022
25931bd
chore(webrtc): new iridium logic
molimauro Aug 10, 2022
4c59e93
chore: merge
molimauro Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions components/ui/BackgroundCall/BackgroundCall.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
{{$t('ui.background_call')}} 
<span v-if="caller" class="background-call-name">{{caller.name}}</span>&nbsp;
<span v-if="elapsedTime">- {{elapsedTime}}</span>
<div v-if="!audio.deafened && audioStream" class="audio-stream-container">
<audio
:id="`audio-stream-${audioStream.id}`"
:src-object.prop="audioStream"
autoplay
/>
</div>
</div>
105 changes: 91 additions & 14 deletions components/ui/BackgroundCall/BackgroundCall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,88 @@
<script lang="ts">
import Vue from 'vue'
import { mapState } from 'vuex'
import { Friend } from '~/types/ui/friends'
import dayjs from 'dayjs'
import { RootState } from '~/types/store/store'
import iridium from '~/libraries/Iridium/IridiumManager'
import { Call, CallPeerStreams } from '~/libraries/WebRTC/Call'
import { $WebRTC } from '~/libraries/WebRTC/WebRTC'

export default Vue.extend({
data() {
return {
caller: null,
webrtc: iridium.webRTC.state,
interval: null,
elapsedTime: '',
}
},
computed: {
...mapState({
friends: (state) => (state as RootState).friends.all,
elapsedTime: (state) => (state as RootState).webrtc.elapsedTime,
activeCall: (state) => (state as RootState).webrtc.activeCall,
audio: (state) => (state as RootState).audio,
}),
caller(): Friend | undefined {
return this.friends.find(
(f: Friend) => f.peerId === this.activeCall?.peerId,
activeCall() {
return this.webrtc.activeCall
},
createdAt() {
return this.webrtc.createdAt
},
audioMuted() {
return (
(iridium.connector?.id &&
this.webrtc.streamMuted[iridium.connector?.id]?.audio) ??
false
)
},
call() {
return (
iridium.connector?.id &&
this.webrtc.activeCall?.callId &&
$WebRTC.getCall(this.webrtc.activeCall.callId)
)
},
streams() {
return (
this.call &&
iridium.connector?.id &&
(this.call as Call).streams[iridium.connector?.id]
)
},
audioStream() {
return (
this.call &&
!this.audioMuted &&
(this.streams as CallPeerStreams)?.audio
)
},
},
watch: {
createdAt() {
this.startInterval()
},
},
beforeDestroy() {
if (this.interval) {
clearInterval(this.interval)
}
},
mounted() {
this.startInterval()

const id = this.activeCall?.callId

if (!id || !iridium.chat?.hasConversation(id)) {
return
}

const conversation = iridium.chat?.getConversation(id)

this.caller = conversation?.participants.find((participant) => {
return participant.did !== iridium.connector?.id
})
},
methods: {
navigateToActiveConversation() {
async navigateToActiveConversation() {
if (!this.caller) {
return
}
Expand All @@ -30,14 +94,27 @@ export default Vue.extend({
this.$store.commit('ui/showSidebar', false)
}

this.$store.dispatch('conversation/setConversation', {
id: this.caller.peerId,
type: 'friend',
participants: [this.caller],
calling: false,
})
const id = await iridium.chat?.directConversationIdFromDid(
this.caller.did,
)

if (!id || !(await iridium.chat?.hasConversation(id))) {
return
}

this.$router.push(`/chat/direct/${this.caller.address}`)
this.$router.push(`/chat/${id}`)
},
startInterval() {
if (!this.interval && this.createdAt && this.activeCall) {
this.interval = setInterval(this.updateElapsedTime, 1000)
}
},
updateElapsedTime() {
const duration = dayjs.duration(Date.now() - this.createdAt)
const hours = duration.hours()
this.elapsedTime = `${hours > 0 ? hours + ':' : ''}${duration.format(
'mm:ss',
)}`
},
},
})
Expand Down
21 changes: 18 additions & 3 deletions components/ui/Chat/TypingIndicator/TypingIndicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@

<script lang="ts">
import Vue from 'vue'
import { mapGetters } from 'vuex'
import { ConversationParticipant } from '~/store/conversation/types'
import { ConversationParticipant } from '~/libraries/Iridium/chat/types'
import iridium from '~/libraries/Iridium/IridiumManager'

export default Vue.extend({
data() {
return {
chat: iridium.chat,
}
},
computed: {
...mapGetters('conversation', ['typingParticipants']),
typingParticipants() {
const conversationId = this.$route.params.id
if (!conversationId) {
return
}
return this.chat.getTypingParticipants(conversationId)
},
text(): string {
if (!this.typingParticipants.length) {
return ''
}
return this.$tc('messaging.typing', this.typingParticipants.length, {
user: this.typingParticipants
.map((p: ConversationParticipant) => p.name)
Expand Down
5 changes: 4 additions & 1 deletion components/ui/Global/Global.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
:set-close-timeout="5000"
/>
</UiModal> -->
<UiModal v-if="webrtc.incomingCall">
<UiModal v-if="incomingCall">
<MediaIncomingCall :accept-call="acceptCall" :deny-call="denyCall" />
</UiModal>
<UiModal
Expand Down Expand Up @@ -82,4 +82,7 @@
<InteractablesQuickProfile v-if="ui.quickProfile" :user="ui.quickProfile" />
</transition>
<UiBackgroundCall v-if="showBackgroundCall" />
<UiPip v-if="showBackgroundCall" v-slot="{ dragging }">
<PreviewCall :dragging="dragging" />
</UiPip>
</div>
64 changes: 30 additions & 34 deletions components/ui/Global/Global.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<template src="./Global.html"></template>
<script lang="ts">
import Vue from 'vue'
import { mapGetters, mapState } from 'vuex'
import { mapState } from 'vuex'
import { TrackKind } from '~/libraries/WebRTC/types'
import { ModalWindows } from '~/store/ui/types'
import { $WebRTC } from '~/libraries/WebRTC/WebRTC'
import { Friend } from '~/types/ui/friends'
import iridium from '~/libraries/Iridium/IridiumManager'
import PreviewCall from '~/components/views/media/previewCall/PreviewCall.vue'

declare module 'vue/types/vue' {
interface Vue {
Expand All @@ -16,15 +15,28 @@ declare module 'vue/types/vue' {

export default Vue.extend({
name: 'Global',
components: {
PreviewCall,
},
data() {
return {
webrtc: iridium.webRTC,
}
},
computed: {
...mapState(['ui', 'media', 'webrtc', 'conversation', 'files']),
...mapGetters('webrtc', ['isBackgroundCall', 'isActiveCall']),
...mapState(['ui', 'media', 'conversation', 'files']),
ModalWindows: () => ModalWindows,
incomingCall() {
return this.webrtc.state.incomingCall
},
showBackgroundCall(): boolean {
if (!this.$device.isMobile) {
return this.isBackgroundCall
return this.webrtc.isBackgroundCall
}
return this.isBackgroundCall || (this.isActiveCall && this.ui.showSidebar)
return (
this.webrtc.isBackgroundCall ||
(this.webrtc.isActiveCall && this.ui.showSidebar)
)
},
},
mounted() {
Expand Down Expand Up @@ -76,37 +88,22 @@ export default Vue.extend({
* @example
*/
async acceptCall(kinds: TrackKind[]) {
this.$store.commit('webrtc/setStreamMuted', {
did: iridium.connector?.peerId,
audio: true,
video: true,
screen: true,
})
const { callId, peerId } = this.webrtc.incomingCall
const call = $WebRTC.getCall(callId)
if (!call) {
return
}

const redirectId =
this.webrtc.incomingCall.type === 'group'
? `groups/${callId}`
: `direct/${
this.$store.state.friends.all.find(
(f: Friend) => f.peerId === peerId,
)?.address || 'error'
}`

try {
await call.createLocalTracks(kinds)
await call.answer(peerId)
await this.webrtc.acceptCall(kinds)
} catch (error) {
if (error instanceof Error) {
this.$toast.error(this.$t(error.message) as string)
}
}

const callingPath = `/chat/${redirectId}`
const callId = this.webrtc.state.activeCall?.callId

if (!callId) {
return
}

const callingPath = `/chat/${callId}`

if (this.$route.path !== callingPath) {
this.$router.push(callingPath)
}
Expand All @@ -118,17 +115,16 @@ export default Vue.extend({
*/
denyCall() {
this.$store.commit('ui/fullscreen', false)
this.$store.dispatch('webrtc/denyCall')
this.webrtc.denyCall()
},
/**
* @method hangUp
* @description Hangs up active call
* @example
*/
hangUp() {
this.$store.commit('webrtc/setIncomingCall', undefined, { root: true })
this.$store.commit('ui/fullscreen', false)
this.$store.dispatch('webrtc/hangUp')
this.webrtc.hangUp()
},
},
})
Expand Down
56 changes: 56 additions & 0 deletions components/ui/Loaders/ScaleLoader/ScaleLoader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<div class="scale-loader">
<span />
<span />
<span />
<span />
<span />
</div>
</template>

<script lang="ts">
import Vue from 'vue'

export default Vue.extend({
name: 'ScaleLoader',
})
</script>

<style scoped lang="less">
.scale-loader {
display: flex;
span {
background-color: @white;
width: 4px;
height: 20px;
margin: 2px;
border-radius: 2px;
display: inline-block;
animation: 1s cubic-bezier(0.2, 0.68, 0.18, 1.08) 0.1s infinite normal both
running scale-loader;
&:nth-child(2) {
animation-delay: 0.2s;
}
&:nth-child(3) {
animation-delay: 0.3s;
}
&:nth-child(4) {
animation-delay: 0.4s;
}
&:nth-child(5) {
animation-delay: 0.5s;
}
}
}
@keyframes scale-loader {
0% {
transform: scaleY(1);
}
50% {
transform: scaleY(0.4);
}
100% {
transform: scaleY(1);
}
}
</style>
Loading