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(delegates): config fixes & custom delegates included #4634

Merged
merged 10 commits into from
Sep 8, 2022
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
# in case you want to run Cypress locally
ENVIRONMENT=dev

NUXT_ENV_IRIDIUM_SYNC_NODES= '/ip4/138.197.229.159/tcp/4003/ws,/ip4/138.197.229.159/tcp/4002'
# NUXT_ENV_IRIDIUM_SYNC_NODES= '/ip4/138.197.229.159/tcp/4003/ws,/ip4/138.197.229.159/tcp/4002'
NUXT_ENV_IRIDIUM_SYNC_NODES= '/ip4/127.0.0.1/tcp/4003/ws,/ip4/127.0.0.1/tcp/4005/ws'
# '/dns4/localhost/tcp/443/wss/p2p/12D3KooWRgdhiJam4naWGYtgLXtc17ty89MMPvig41p9BhKG7FRW'
6 changes: 3 additions & 3 deletions components/views/media/heading/Heading.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="media-heading">
<TypographyTag v-if="callTime" data-cy="elapsed-time">
{{$t('ui.live', { time: formatDuration(callTime / 1000) })}}
<div class="heading">
<TypographyTag v-if="callTimeString" data-cy="elapsed-time">
{{$t('ui.live', { time: callTimeString })}}
</TypographyTag>
</div>
16 changes: 8 additions & 8 deletions components/views/media/heading/Heading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export default Vue.extend({
},
data() {
return {
callTime: 0,
formatDuration,
webrtc: iridium.webRTC.state,
callTimeString: '',
}
},
mounted() {
setInterval(this.updateCallTime, 1000)
},
methods: {
updateCallTime() {
this.callTime = iridium.webRTC.callTime
watch: {
webrtc: {
handler() {
this.callTimeString = this.$dayjs(this.webrtc.callStartedAt).toNow(true)
},
deep: true,
},
},
})
Expand Down
23 changes: 11 additions & 12 deletions config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// eslint-disable-next-line import/named
import { Commitment } from '@solana/web3.js'
import type { IridiumConfig } from '@satellite-im/iridium'

const syncNodes = process.env.NUXT_ENV_IRIDIUM_SYNC_NODES?.split(',') || [
const nodes = process.env.NUXT_ENV_IRIDIUM_SYNC_NODES?.split(',') || [
'/ip4/localhost/tcp/443/wss/p2p/12D3KooWRgdhiJam4naWGYtgLXtc17ty89MMPvig41p9BhKG7FRW',
]
console.log('debug: | syncNodes', syncNodes)

const gateways = process.env.NUXT_ENV_IRIDIUM_GATEWAYS?.split(',') || [
'https://satellite.infura-ipfs.io',
]
export const Config = {
debug: true,
iridium: {
syncNodes,
nodes,
gateways,
ipfs: {
config: {
Addresses: {
Swarm: syncNodes,
Delegate: syncNodes,
},
Bootstrap: syncNodes,
Bootstrap: nodes,
},
},
},
} as Partial<IridiumConfig>,
ipfs: {
gateway: 'https://satellite.infura-ipfs.io/ipfs/',
},
Expand Down Expand Up @@ -206,13 +205,13 @@ export const Config = {
},
seedPhraseCharsCount: 12,
pip: {
/* Grid config, image splitting the screen in `rows x columns`
/* Grid config, image splitting the screen in `rows x columns`
_____ _____
|_____|_____|
|_____|_____|
|_____|_____|
|_____|_____|

Depending on the center of the Pip, it will land on a specific slot
*/
rows: [0, 1, 2, 3] as const,
Expand Down
115 changes: 72 additions & 43 deletions libraries/Iridium/IridiumManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class IridiumManager extends Emitter {
webRTC: WebRTCManager
settings: SettingsManager
users: UsersManager
syncTimeout?: NodeJS.Timeout

constructor() {
super()
Expand Down Expand Up @@ -74,8 +75,8 @@ export class IridiumManager extends Emitter {
async initFromEntropy(entropy: Uint8Array) {
logger.info('iridium/manager', 'initFromEntropy()')
this.connector = await createIridiumIPFS(entropy, {
...Config.iridium,
logger,
nodes: Config.iridium.syncNodes,
})

logger.info('iridium/manager', 'connector initialized', {
Expand Down Expand Up @@ -116,29 +117,27 @@ export class IridiumManager extends Emitter {

logger.info('iridium/manager', 'initializing profile')
await this.profile.init()
await new Promise((resolve) =>
setTimeout(() => this.sendSyncInit().then(() => resolve(true)), 3000),
)
await this.connector?.waitForSyncNode(5000)
await this.sendSyncInit()
}

async onProfileChange() {
logger.debug('iridium/manager', 'profile changed', {
primaryNodeID: this.connector?.p2p.primaryNodeID,
p2pReady: this.connector?.p2p.ready,
did: this.profile.state?.did,
nodeReady: this.connector?.p2p.nodeReady,
})
if (!this.connector?.p2p.ready) {
if (!this.connector?.p2p.primaryNodeID || !this.connector?.p2p.nodeReady) {
return
}
if (this.profile.state?.did) {
await this.sendSyncInit()
}
await this.sendSyncInit()
}

async onP2pReady() {
if (
!this.profile.state?.did ||
!this.connector?.p2p.primaryNodeID ||
!this.connector?.p2p.hasNode ||
!this.connector?.p2p.nodeReady ||
!this.connector.p2p.ready
) {
logger.debug(
Expand All @@ -147,6 +146,8 @@ export class IridiumManager extends Emitter {
{
primaryNodeID: this.connector?.p2p.primaryNodeID,
p2pReady: this.connector?.p2p.ready,
nodeReady: this.connector?.p2p.nodeReady,
hasNode: this.connector?.p2p.hasNode,
did: this.profile.state?.did,
},
)
Expand All @@ -156,20 +157,38 @@ export class IridiumManager extends Emitter {
this.ready = true
logger.info('iridium/manager', 'initializing users')
await this.users.init()
logger.info('iridium/manager', 'initializing groups')
await this.groups.init()
logger.info('iridium/manager', 'initializing files')
await this.files.init()
logger.info('iridium/manager', 'initializing webRTC')
await this.webRTC.init()
logger.info('iridium/manager', 'initializing settings')
await this.settings.init()
logger.info('iridium/manager', 'notification settings')
await this.notifications.init()
logger.info('iridium/friends', 'initializing friends')
await this.friends.init()
logger.info('iridium/manager', 'initializing chat')
await this.chat.init()
await Promise.all(
[
async () => {
logger.info('iridium/manager', 'initializing groups')
await this.groups.init()
},
async () => {
logger.info('iridium/manager', 'initializing files')
await this.files.init()
},
async () => {
logger.info('iridium/manager', 'initializing webRTC')
await this.webRTC.init()
},
async () => {
logger.info('iridium/manager', 'initializing settings')
await this.settings.init()
},
async () => {
logger.info('iridium/manager', 'notification settings')
await this.notifications.init()
},
async () => {
logger.info('iridium/friends', 'initializing friends')
await this.friends.init()
},
async () => {
logger.info('iridium/manager', 'initializing chat')
await this.chat.init()
},
].map((f) => f()),
)
logger.info('iridium/manager', 'ready')

logger.info(
Expand All @@ -185,26 +204,36 @@ export class IridiumManager extends Emitter {
}

async sendSyncInit() {
const connector = this.connector
if (!connector?.p2p.primaryNodeID) {
logger.warn('iridium/manager', 'no primary node, cannot send sync init', {
primaryNodeID: connector?.p2p.primaryNodeID,
ready: connector?.p2p.ready,
})
return
}
const profile = this.profile.state
logger.info('iridium/manager', 'sending sync init', { profile })
const payload = {
type: 'sync/init',
at: Date.now(),
name: profile?.name || this.id,
avatar: profile?.photoHash || '',
status: profile?.status || '',
photoHash: profile?.photoHash || '',
}
clearTimeout(this.syncTimeout)
this.syncTimeout = setTimeout(() => {
const connector = this.connector
if (!connector?.p2p.primaryNodeID) {
logger.warn(
'iridium/manager',
'no primary node, cannot send sync init',
{
primaryNodeID: connector?.p2p.primaryNodeID,
ready: connector?.p2p.ready,
},
)
return
}
const profile = this.profile.state
if (!profile?.did) {
return
}
logger.info('iridium/manager', 'sending sync init', { profile })
const payload = {
type: 'sync/init',
at: Date.now(),
name: profile?.name || this.id,
avatar: profile?.photoHash || '',
status: profile?.status || '',
photoHash: profile?.photoHash || '',
}

await connector.send(connector.p2p.primaryNodeID, payload)
connector.send(connector.p2p.primaryNodeID, payload)
}, 3000)
}
}

Expand Down
8 changes: 6 additions & 2 deletions libraries/Iridium/users/UsersManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default class UsersManager extends Emitter<IridiumUserPubsub> {
await iridium.connector.subscribe<IridiumUserPubsub>('/users/announce', {
handler: this.onUsersAnnounce.bind(this),
sync: true,
decode: false,
})
logger.log(this.loggerTag, 'listening for user activity', this.state)

Expand Down Expand Up @@ -248,7 +249,10 @@ export default class UsersManager extends Emitter<IridiumUserPubsub> {

return new Promise<User[]>((resolve) => {
const id = v4()
if (!iridium.connector?.p2p.primaryNodeID || !iridium.ready) {
if (
!iridium.connector?.p2p.primaryNodeID ||
!iridium.connector?.p2p.nodeReady
) {
logger.warn('iridium/usermanager', 'no primary node, cannot search', {
primaryNodeID: iridium?.connector?.p2p.primaryNodeID,
p2pReady: iridium?.connector?.p2p.ready,
Expand All @@ -260,7 +264,7 @@ export default class UsersManager extends Emitter<IridiumUserPubsub> {
const timeout = setTimeout(() => {
logger.warn(this.loggerTag, 'peer search timeout', { query })
resolve([])
}, 30000)
}, 5000)

this.once(`searchResults/${id}`, (results: User[]) => {
logger.debug(this.loggerTag, 'search results received', results)
Expand Down
4 changes: 2 additions & 2 deletions libraries/Iridium/webrtc/WebRTCManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const initialState: WebRTCState = {
incomingCall: null,
activeCall: null,
streamMuted: {},
callTime: 0,
callStartedAt: 0,
streamConstraints: {
audio: true,
Expand All @@ -47,7 +48,6 @@ type WebRTCTypingMessage = {
export default class WebRTCManager extends Emitter {
public state: WebRTCState
private loggerTag = 'iridium/webRTC'
public callTime: number = 0
public timers: { [key: string]: any } = {}

constructor() {
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class WebRTCManager extends Emitter {

setInterval(() => {
if (this.state.activeCall) {
this.callTime = Date.now() - this.state.callStartedAt
this.state.callTime = Date.now() - this.state.callStartedAt
}
}, 1000)
}
Expand Down
1 change: 1 addition & 0 deletions libraries/Iridium/webrtc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface WebRTCState {
streamMuted: StreamMutedState
activeCall: WebRTCActiveCall | null
incomingCall: WebRTCIncomingCall | null
callTime: number
callStartedAt: number
streamConstraints: WebRTCStreamConstraints
}
Expand Down
2 changes: 1 addition & 1 deletion locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
fullscreen: 'Fullscreen',
exit_fullscreen: 'Exit fullscreen',
more: 'More',
live: 'Live {time}',
live: 'Live for {time}',
edited: 'edited',
online: 'All users are offline | {name} is online | {name} are online',
offline: '{name} is not connected',
Expand Down
1 change: 1 addition & 0 deletions store/accounts/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export default {
commit('setRegistrationStatus', RegistrationStatus.REGISTERED)
commit('setActiveAccount', iridium.id)
commit('setUserDetails', profile)
await iridium.sendSyncInit()
return dispatch('startup', walletAccount)
},

Expand Down