Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
balazskreith committed Nov 17, 2024
1 parent 5442cf1 commit c27b430
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 76 deletions.
116 changes: 42 additions & 74 deletions media-server/src/services/HamokService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,82 +335,8 @@ export class HamokService extends EventEmitter<HamokServiceEventMap> {
}).catch(err => logger.error('Failed to join dev hamok', err));
}

const subscribe = async (event?: keyof HamokEmitterEventMap) => {
if (!event || event === 'client-sample') {
await this.eventEmitter.subscribe('client-sample', (message) => {
this.emit('client-sample', message);
});
}

if (!event || event === 'create-pipe-transport-request') {
await this.eventEmitter.subscribe('create-pipe-transport-request', (requestId, payload) => {
this.emit('create-pipe-transport-request', payload, createNonVoidResponseCallback(requestId));
});
}

if (!event || event === 'connect-pipe-transport-request') {
await this.eventEmitter.subscribe('connect-pipe-transport-request', (requestId, payload) => {
this.emit('connect-pipe-transport-request', payload, createVoidResponseCallback(requestId));
});
}

if (!event || event === 'pipe-media-producer-to') {
await this.eventEmitter.subscribe('pipe-media-producer-to', (requestId, payload) => {
this.emit('pipe-media-producer-to', payload, createNonVoidResponseCallback(requestId));
});
}

if (!event || event === 'get-client-producers-request') {
await this.eventEmitter.subscribe('get-client-producers-request', (requestId, payload) => {
this.emit('get-client-producers-request', payload, createNonVoidResponseCallback(requestId));
});
}

if (!event || event === 'consume-media-producer') {
await this.eventEmitter.subscribe('consume-media-producer', (payload) => {
this.emit('consume-media-producer', payload);
});
}

if (!event || event === 'piped-media-consumer-closed') {
await this.eventEmitter.subscribe('piped-media-consumer-closed', (payload) => {
this.emit('piped-media-consumer-closed', payload);
});
}

if (!event || event === 'response') {
await this.eventEmitter.subscribe('response', (requestId, response) => {
const pendingRequest = this._pendingRequests.get(requestId);

if (!pendingRequest) return;

clearTimeout(pendingRequest.timer);
if (response.error) {
pendingRequest.reject(response.error);
} else {
pendingRequest.resolve(response.payload);
}
});
}
}

this.eventEmitter.subscriptions.on('removed', (event, peerId) => {
if (peerId !== this.hamok.localPeerId) return;

const forcedSubscribe = () => {
subscribe(event).catch(err => {
logger.error('Failed to subscribe to %s: %o', event, err);
forcedSubscribe();
})
}

forcedSubscribe();
})

this.hamok.on('joined', async () => {
logger.info('Hamok joined %s', this.eventEmitter.hasSubscribers('create-pipe-transport-request', true));

await subscribe();
});

await this.hamok.join({
Expand All @@ -428,6 +354,48 @@ export class HamokService extends EventEmitter<HamokServiceEventMap> {
;


await this.eventEmitter.subscribe('client-sample', (message) => {
this.emit('client-sample', message);
});

await this.eventEmitter.subscribe('create-pipe-transport-request', (requestId, payload) => {
this.emit('create-pipe-transport-request', payload, createNonVoidResponseCallback(requestId));
});

await this.eventEmitter.subscribe('connect-pipe-transport-request', (requestId, payload) => {
this.emit('connect-pipe-transport-request', payload, createVoidResponseCallback(requestId));
});

await this.eventEmitter.subscribe('pipe-media-producer-to', (requestId, payload) => {
this.emit('pipe-media-producer-to', payload, createNonVoidResponseCallback(requestId));
});

await this.eventEmitter.subscribe('consume-media-producer', (payload) => {
this.emit('consume-media-producer', payload);
});

await this.eventEmitter.subscribe('piped-media-consumer-closed', (payload) => {
this.emit('piped-media-consumer-closed', payload);
});

await this.eventEmitter.subscribe('get-client-producers-request', (requestId, payload) => {
this.emit('get-client-producers-request', payload, createNonVoidResponseCallback(requestId));
});

await this.eventEmitter.subscribe('response', (requestId, response) => {
const pendingRequest = this._pendingRequests.get(requestId);

if (!pendingRequest) return;

clearTimeout(pendingRequest.timer);
if (response.error) {
pendingRequest.reject(response.error);
} else {
pendingRequest.resolve(response.payload);
}
});


const createNonVoidResponseCallback = <T extends object>(requestId: string): HamokServiceResponseField<T> => ((payload?: T, error?: string) => {
this.eventEmitter.notify('response', requestId, {
error,
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/stores/callConfigStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ConnectionConfig } from '../utils/Connection';
import { v4 as uuid } from 'uuid';

const DEFAULT_PORT = (new URL(window.location.href)).searchParams.get('port') ?? '9080';
const SERVER = undefined;
// const SERVER = 'wss://media.webrtc-observer.org:443';
// const SERVER = undefined;
const SERVER = 'wss://media.webrtc-observer.org:443';

const forceRelay = window.location.search.includes('forceRelay') ? true : undefined;
// const forcedRelay = false;
Expand Down

0 comments on commit c27b430

Please sign in to comment.