Skip to content

Commit

Permalink
feat(call): increase peer announce frequency for active conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Ewing committed May 11, 2022
1 parent 6c02539 commit 4f69ba9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions store/accounts/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ export default {
const { initialized: textileInitialized } = rootState.textile
const { initialized: webrtcInitialized } = rootState.webrtc

dispatch('conversation/initialize', {}, { root: true })
commit('accounts/setUserPeerId', $Peer2Peer.id, { root: true })

await db.initializeSearchIndexes()
Expand All @@ -342,7 +343,6 @@ export default {
payerPublicKey: payerAccount?.publicKey.toBase58(),
})
await dispatch('friends/initialize', {}, { root: true })
await dispatch('conversation/initialize', {}, { root: true })

if ($SolanaManager.payerAccount?.secretKey) {
await dispatch(
Expand Down Expand Up @@ -383,7 +383,7 @@ export default {
)
}

dispatch('groups/initialize', {}, { root: true })
await dispatch('groups/initialize', {}, { root: true })
commit('textile/textileInitialized', true, { root: true })
},
}
Expand Down
1 change: 0 additions & 1 deletion store/conversation/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createFromPubKey } from 'peer-id'
import { keys } from 'libp2p-crypto'
import { ConversationParticipant, ConversationState } from './types'
import { ActionsArguments } from '~/types/store/store'
import { Peer2Peer } from '~/libraries/WebRTC/Libp2p'

const actions = {
/**
Expand Down
2 changes: 1 addition & 1 deletion store/conversation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export enum ConversationActivity {
export type ConversationParticipant = {
peerId?: string
address: string
name: string
textilePubkey?: string
state?: ConversationConnection
activity?: ConversationActivity
name?: string
profilePicture?: string
updatedAt?: number
}
Expand Down
10 changes: 6 additions & 4 deletions store/groups/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ const getUserAccount = () => {
}

export default {
initialize({ dispatch }: ActionsArguments<GroupsState>) {
dispatch('fetchGroups')
dispatch('subscribeToGroupInvites')
dispatch('subscribeToGroupsUpdate')
async initialize({ dispatch }: ActionsArguments<GroupsState>) {
await Promise.all([
dispatch('fetchGroups'),
dispatch('subscribeToGroupInvites'),
dispatch('subscribeToGroupsUpdate'),
])
},

/**
Expand Down
15 changes: 4 additions & 11 deletions store/webrtc/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from 'vue'
import type { SignalData } from 'simple-peer'
import { ConversationParticipant } from '../conversation/types'
import { WebRTCError, WebRTCState } from './types'
import { WebRTCState } from './types'

import { ActionsArguments } from '~/types/store/store'
import { $WebRTC } from '~/libraries/WebRTC/WebRTC'
Expand All @@ -10,10 +10,10 @@ import { TrackKind } from '~/libraries/WebRTC/types'
import { Config } from '~/config'
import { PropCommonEnum } from '~/libraries/Enums/enums'
import { Peer2Peer, PrivateKeyInfo } from '~/libraries/WebRTC/Libp2p'
import { Call, CallPeerDescriptor } from '~/libraries/WebRTC/Call'
import { CallPeerDescriptor } from '~/libraries/WebRTC/Call'
import { Friend } from '~/types/ui/friends'

const announceFrequency = 10 * 1000
const announceFrequency = 5000
const webRTCActions = {
/**
* @method initialized
Expand Down Expand Up @@ -217,13 +217,6 @@ const webRTCActions = {
setInterval(() => {
if (rootState.conversation) {
rootState.conversation.participants
.filter(
(p) =>
!rootState.friends.all.some(
(friend) =>
friend.peerId === p.peerId || friend.address === p.address,
),
)
.filter((p) => p.peerId !== $Peer2Peer.id)
.forEach((p) => {
$Peer2Peer.sendMessage(
Expand All @@ -241,7 +234,7 @@ const webRTCActions = {
})
}
rootState.friends.all
.filter((friend) => !!friend.peerId)
.filter((friend) => !!friend.peerId && friend.state !== 'online')
.forEach((friend) => {
$Peer2Peer.sendMessage(
{
Expand Down
2 changes: 2 additions & 0 deletions types/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { WebRTCState } from '~/store/webrtc/types'
import { GroupsState } from '~/store/groups/types'
import { SettingsState } from '~/store/settings/types'
import { ConversationState } from '~/store/conversation/types'
import { AudioState } from '~/store/audio/types'

export interface RootState {
accounts: AccountsState
audio: AudioState
dataState: DataState
friends: FriendsState
textile: TextileState
Expand Down

0 comments on commit 4f69ba9

Please sign in to comment.