Skip to content

Commit

Permalink
feat: configurable media input (#96)
Browse files Browse the repository at this point in the history
* feat: add webcam and screen configuration

* refactor: config type reference from config module

* refactor: remove unneeded type

* refactor: create peer doesn't need config anymore

* refactor: create peer doesn't need config anymore

* feat: configurable media input setting through peer

* refactor: update media config properties

* refactor: add supportsSetCodecPreferences variable

* refactor: remove unused properties for now

* refactor: change video codec order

* refactor: ensure the default codecs are ordered

* fix: screen share default codec is vp8

* fix: use deep partial to make all properties optional

* fix: simulcast for webcam set to true

* fix: support for array type checking

* fix: webcam is auto svc and screen is not

* fix: merge config and replace arrays value

* refactor: simplify webcam and screen setting by config

* refactor: update variables

* fix: add more config checking

* refactor: change function name

* fix: reorder codecs instead of use only prefered ones

* refactor: bitrates config are not exposed to users for now

* feat: add inlive hub supported codecs

* refactor: remove isArray lodash and update the original config

* refactor: make descriptive variable name

* fix default config publishing media tracks

* fix: svc and simulcast can be enabled separately

* feat: set scalability mode on simulcast when svc is enabled

* fix: send encodings with rid when simulcast enabled

* refactor: remove unused comment

---------

Co-authored-by: Yohan Totting <[email protected]>
  • Loading branch information
faiq-naufal and tyohan authored Mar 4, 2024
1 parent 7cf7490 commit e4a1876
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 245 deletions.
4 changes: 4 additions & 0 deletions packages/internal/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ export declare namespace SharedType {
type ObjectLiteral = {
[key: string]: any
}

type DeepPartial<Thing> = Thing extends any[]
? Thing
: { [Key in keyof Thing]?: DeepPartial<Thing[Key]> }
}
2 changes: 1 addition & 1 deletion packages/room/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ await room.endRoom(roomData.data.roomId);

A method to delete a specific room metadata based on metadata `key` provided. It expects the `roomId` and `key` as parameters. This method will return a promise.

- `room.createPeer(roomId: string, clientId: string, config?: object)`
- `room.createPeer(roomId: string, clientId: string)`

A method to create a peer that manages the WebRTC peer to peer connection. It requires `roomId` and `clientId` parameters to be set. This method will return a promise.

Expand Down
28 changes: 15 additions & 13 deletions packages/room/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ export const webrtc = {
}

export const media = {
video: {
width: 1280,
height: 720,
frameRate: 24,
facingMode: 'user',
aspectRatio: 1.777_777_777_8,
maxBitrate: 1_200_000,
codec: 'VP9',
webcam: {
maxFramerate: 30,
videoCodecs: ['video/VP9', 'video/H264', 'video/VP8'],
simulcast: false,
svc: true,
scalabilityMode: 'L3T1',
},
audio: {
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true,
red: true,
screen: {
maxFramerate: 30,
videoCodecs: ['video/VP8', 'video/H264', 'video/VP9'],
simulcast: false,
svc: true,
scalabilityMode: 'L1T2',
},
microphone: {
audioCodecs: ['audio/red', 'audio/opus'],
},
}
23 changes: 9 additions & 14 deletions packages/room/facade/facade.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import merge from 'lodash-es/merge.js'
import mergeWith from 'lodash-es/mergeWith.js'
import { createFetcher } from '../api/fetcher.js'
import { createApi } from '../api/api.js'
import { createEvent } from '../event/event.js'
import { createStreams } from '../stream/streams.js'
import { createStream } from '../stream/stream.js'
import { createPeer } from '../peer/peer.js'
import { createChannel } from '../channel/channel.js'
import * as defaultConfig from '../config/config.js'

const config = {
api: defaultConfig.api,
webrtc: defaultConfig.webrtc,
media: defaultConfig.media,
}
import * as config from '../config/config.js'

/** @param {import('./facade-types.js').RoomFacadeType.FacadeDependencies} facadeDependencies Dependencies for facade module */
export const createFacade = ({
Expand All @@ -28,7 +22,9 @@ export const createFacade = ({
* @param {import('../room-types.js').RoomType.UserConfig} userConfig
*/
createInstance: (userConfig) => {
merge(config, userConfig)
mergeWith(config, userConfig, (_, userValue) => {
return Array.isArray(userValue) ? userValue : undefined
})

const baseUrl = `${config.api.baseUrl}/${config.api.version}`
const apiKey = config.api.apiKey
Expand All @@ -40,7 +36,7 @@ export const createFacade = ({
const streams = createStreams().createInstance()
const peer = createPeer({
api,
config,
config: config,
createStream,
event,
streams,
Expand All @@ -65,10 +61,9 @@ export const createFacade = ({
/**
* @param {string} roomId
* @param {string} clientId
* @param {import('../peer/peer-types.js').RoomPeerType.PeerConfig} [config]
*/
async (roomId, clientId, config) => {
await peer.connect(roomId, clientId, config)
async (roomId, clientId) => {
await peer.connect(roomId, clientId)
return peer
},
createDataChannel: api.createDataChannel,
Expand All @@ -81,7 +76,7 @@ export const createFacade = ({
}

export const facade = createFacade({
config,
config: config,
api: { createFetcher, createApi },
event: { createEvent },
stream: { createStream, createStreams },
Expand Down
13 changes: 0 additions & 13 deletions packages/room/peer/peer-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ export declare namespace RoomPeerType {
config: RoomType.Config
}

type BitrateConfig = {
lowBitrate?: number
midBitrate?: number
highBitrate?: number
}

type PeerConfig = {
codecs?: string[]
bitrate?: BitrateConfig
scalabilityMode?: string
maxFramerate?: number
}

type RTCRtpSVCEncodingParameters = RTCRtpEncodingParameters & {
scalabilityMode?: string
}
Expand Down
Loading

0 comments on commit e4a1876

Please sign in to comment.