Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async authenticatePeer(peer: SimplePeer.Instance, peerId?: string) {
const peerPublicKey = peerId ? sodium.from_hex(peerId) : undefined
const userPublicKey = await mutualHandshake(peer, localUser().id, peerPublicKey)
if (!userPublicKey) {
const addr = `${(peer as any).remoteAddress}:${(peer as any).remotePort}`
peer.destroy()
throw new NetworkError(
NetworkErrorCode.PeerAuthenticationFailure,
`Failed to authenticate with peer [${addr}]`
)
}
const userId = sodium.to_hex(userPublicKey)
const netId = new NetUniqueId(userPublicKey)
const conn = new RTCPeerConn(netId, peer)
console.debug(`Authenticated peer ${userId}`, conn)
this.emit('connection', conn)
private async createSession() {
let client
try {
client = await this.getClient()
} catch {
throw new NetworkError(NetworkErrorCode.SignalServerConnectionFailure)
}
try {
await client.createRoom({
publicKey: localUser().id.publicKey,
privateKey: localUser().id.privateKey!
})
} catch (e) {
console.error(e)
throw new NetworkError(
NetworkErrorCode.SignalServerConnectionFailure,
'Failed to create room'
)
}
client.on('peer', this.authenticatePeer)
client.on('close', this.serverConnectionClosed)
this.sessionClient = client
this.intervalId = setInterval(this.keepAlive, KEEP_ALIVE_INTERVAL) as any
console.debug('Created signal client session')
private async createSession() {
let client
try {
client = await this.getClient()
} catch {
throw new NetworkError(NetworkErrorCode.SignalServerConnectionFailure)
}
try {
await client.createRoom({
publicKey: localUser().id.publicKey,
privateKey: localUser().id.privateKey!
})
} catch (e) {
console.error(e)
throw new NetworkError(
NetworkErrorCode.SignalServerConnectionFailure,
'Failed to create room'
)
}
client.on('peer', this.authenticatePeer)
client.on('close', this.serverConnectionClosed)
this.sessionClient = client
this.intervalId = setInterval(this.keepAlive, KEEP_ALIVE_INTERVAL) as any
(state: IAppState): IConnectedProps => ({
hasPlaybackPermissions: hasPlaybackPermissions(state, localUser()),
currentMedia: getCurrentMedia(state),
mediaQueue: getMediaQueue(state),
mediaQueueLocked: state.mediaPlayer.queueLocked
})
)(_MediaList)