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

Fix Media Server Recording & Server Peer Action Routing #8029

Merged
merged 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ export const initializeNetwork = (hostId: UserId, topic: Topic) => {
)

const transport = {
get peers() {
return network.primus ? [network.hostPeerID] : []
},

messageToPeer: (peerId: PeerID, data: any) => {
network.primus?.write(data)
},
Expand Down
3 changes: 0 additions & 3 deletions packages/engine/src/networking/classes/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ export const createNetwork = <Ext>(hostId: UserId, topic: Topic, extension: Ext
* @todo non null this
*/
transport: {
get peers() {
return []
},
messageToPeer: (peerId: PeerID, data: any) => {},
messageToAll: (data: any) => {},
bufferToPeer: (dataChannelType: DataChannelType, peerId: PeerID, data: any) => {},
Expand Down
13 changes: 7 additions & 6 deletions packages/engine/src/networking/systems/OutgoingActionSystem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PeersUpdateType } from '@etherealengine/common/src/interfaces/PeerID'
import { PeerID, PeersUpdateType } from '@etherealengine/common/src/interfaces/PeerID'
import { Action, clearOutgoingActions, getState } from '@etherealengine/hyperflux'

import { Engine } from '../../ecs/classes/Engine'
Expand All @@ -20,15 +20,15 @@ export const updatePeers = (network: Network) => {
name: userNames[peer.userId]
}
}) as Array<PeersUpdateType>
for (const peerID of network.transport.peers)
network.transport.messageToPeer(peerID, { type: MessageTypes.UpdatePeers.toString(), data: peers })
for (const peer of peers)
network.transport.messageToPeer(peer.peerID, { type: MessageTypes.UpdatePeers.toString(), data: peers })
}

export const sendActionsAsPeer = (network: Network) => {
if (!network.ready) return
const actions = [...Engine.instance.store.actions.outgoing[network.topic].queue]
if (!actions.length) return
// for (const peerID of network.transport.peers) {
// for (const peerID of network.peers) {
network.transport.messageToPeer(network.hostPeerID, {
type: MessageTypes.ActionData.toString(),
/*encode(*/ data: actions
Expand All @@ -45,12 +45,12 @@ export const sendActionsAsHost = (network: Network) => {

const outgoing = Engine.instance.store.actions.outgoing

for (const peerID of network.transport.peers) {
for (const peerID of Array.from(network.peers.keys()) as PeerID[]) {
const arr: Action[] = []
for (const a of [...actions]) {
const action = { ...a }
if (outgoing[network.topic].historyUUIDs.has(action.$uuid)) {
const idx = outgoing[network.topic].queue.indexOf(action)
const idx = outgoing[network.topic].queue.findIndex((a) => a.$uuid === action.$uuid)
outgoing[network.topic].queue.splice(idx, 1)
}
if (!action.$to) continue
Expand All @@ -59,6 +59,7 @@ export const sendActionsAsHost = (network: Network) => {
arr.push(action)
}
}
console.log('SENDING ACTIONS TO PEER', arr, peerID)
if (arr.length)
network.transport.messageToPeer(peerID, { type: MessageTypes.ActionData.toString(), /*encode(*/ data: arr }) //)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/instanceserver/src/MediaRecordingFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const createTransport = async (router: Router, port: number, rtcpPort: nu
// FFmpeg don't support RTP/RTCP multiplexing ("a=rtcp-mux" in SDP)
rtcpMux: false,

...localConfig.mediasoup.plainTransport
listenIp: localConfig.mediasoup.plainTransport.listenIp
})

await transport.connect({
Expand Down
11 changes: 9 additions & 2 deletions packages/instanceserver/src/NetworkFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,24 @@ export const setupSubdomain = async () => {
}

// Set up our instanceserver according to our current environment
const localIp = await getLocalServerIp(instanceServerState.isMediaInstance.value)
const announcedIp = config.kubernetes.enabled
? instanceServerState.instanceServer.value.status.address
: localIp.ipAddress
: (await getLocalServerIp(instanceServerState.isMediaInstance.value)).ipAddress

// @todo put this in hyperflux state
localConfig.mediasoup.webRtcTransport.listenIps = [
{
ip: '0.0.0.0',
announcedIp
}
]

localConfig.mediasoup.plainTransport.listenIp = {
ip: '0.0.0.0',
announcedIp
}

localConfig.mediasoup.recording.ip = announcedIp
}

export async function getFreeSubdomain(isIdentifier: string, subdomainNumber: number): Promise<string> {
Expand Down
8 changes: 2 additions & 6 deletions packages/instanceserver/src/SocketWebRTCServerFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@ export const initializeNetwork = async (app: Application, hostId: UserId, topic:
logger.info('Server transport initialized.')

const transport = {
get peers() {
return Object.keys(app.primus.connections) as PeerID[]
},

messageToPeer: (peerId: PeerID, data: any) => {
const spark = app.primus.connections[peerId]
const spark = network.peers.get(peerId)?.spark
if (spark) spark.write(data)
},

messageToAll: (data: any) => {
for (const spark of Object.values(app.primus.connections)) spark.write(data)
for (const peer of Array.from(network.peers.values())) peer.spark?.write(data)
},

bufferToPeer: (dataChannelType: DataChannelType, peerID: PeerID, data: any) => {
Expand Down
13 changes: 7 additions & 6 deletions packages/server-core/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { PlainTransportOptions } from 'mediasoup/node/lib/PlainTransport'
import type { TransportListenIp } from 'mediasoup/node/lib/Transport'
import type { WebRtcTransportOptions } from 'mediasoup/node/lib/WebRtcTransport'

import configFile from './appconfig'
import { SctpParameters } from './types/SctpParameters'
Expand Down Expand Up @@ -122,18 +123,18 @@ export const localConfig = {
// to set these appropriately for your network for the demo to
// run anywhere but on 127.0.0.1
webRtcTransport: {
listenIps: [{ ip: configFile.instanceserver.domain, announcedIp: null! as string }],
listenIps: [{ ip: null! as string, announcedIp: null! as string }],
initialAvailableOutgoingBitrate: 1000 * 1000 * 1000, //1gbps
maxIncomingBitrate: 30 * 1000 * 1000 // 30mbps - this should be set to something; leaving it uncapped causes stuttering
},

plainTransport: {
listenIp: { ip: configFile.instanceserver.domain }
} as PlainTransportOptions,
listenIp: { ip: null! as string, announcedIp: null! as string }
},

recording: {
ip: configFile.instanceserver.domain,

// the internal IP of the local machine, not the public one - overridden upon instance server startup
ip: null! as string,
// FFmpeg's sdpdemux only supports RTCP = RTP + 1
audioPort: 5004,
audioPortRtcp: 5005,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/pages/Capture/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ const CaptureDashboard = () => {
style={{ objectFit: 'contain', top: '0px' }}
>
<div className="grid w-screen h-screen place-items-center">
<h1>{mediaConnection?.connected?.value ? 'Enable Camera' : 'Loading...'}</h1>
<h1>{mediaConnection?.connected?.value ? 'Enable Camera' : 'Connecting...'}</h1>
</div>
</button>
) : null}
Expand Down
Loading