Skip to content

Commit

Permalink
Update media allowed values from Authorization (#589)
Browse files Browse the repository at this point in the history
* update joinAudience params name

* update Authorization type with new media_allowed, audio_allowed and video_allowed

* changset

* update sessionSlice specs
  • Loading branch information
edolix authored Jul 14, 2022
1 parent 8ec914b commit fa62d67
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changeset/gorgeous-timers-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@signalwire/core': patch
'@signalwire/js': patch
---

[internal] Update media_allowed, video_allowed and audio_allowed values for joinAudience method.
5 changes: 3 additions & 2 deletions packages/core/src/redux/features/session/sessionSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe('SessionState Tests', () => {
iceServers: rpcConnectResultVRT.ice_servers,
authStatus: 'authorized',
authState: {
audio_allowed: true,
media_allowed: 'all',
audio_allowed: 'both',
project: '8f0a119a-cda7-4497-a47d-c81493b824d4',
resource: '9c80f1e8-9430-4070-a043-937eb3a96b38',
room: {
Expand All @@ -31,7 +32,7 @@ describe('SessionState Tests', () => {
'SGZtkRD9fvuBAOUp1UF56zESxdEvGT6qSGZtkRD9fvuBAOUp1UF56zESxdEvGT6q',
type: 'video',
user_name: 'Joe',
video_allowed: true,
video_allowed: 'both',
},
authError: undefined,
authCount: 1,
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const createMockedLogger = (): InternalSDKLogger => ({
*
* @returns Redux Store
*/
export const configureJestStore = (options?: Partial<ConfigureStoreOptions>) => {
export const configureJestStore = (
options?: Partial<ConfigureStoreOptions>
) => {
return configureStore({
userOptions: {
project: PROJECT_ID,
Expand Down Expand Up @@ -60,8 +62,9 @@ export const rpcConnectResultVRT: RPCConnectResult = {
},
signature:
'SGZtkRD9fvuBAOUp1UF56zESxdEvGT6qSGZtkRD9fvuBAOUp1UF56zESxdEvGT6q',
audio_allowed: true,
video_allowed: true,
media_allowed: 'all',
audio_allowed: 'both',
video_allowed: 'both',
},
protocol:
'signalwire_SGZtkRD9fvuBAOUp1UF56zESxdEvGT6qSGZtkRD9fvuBAOUp1UF56zESxdEvGT6q_03e8c927-8ea3-4661-86d5-778c3e03296a_8f0a119a-cda7-4497-a47d-c81493b824d4',
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ export interface SessionRequestObject {
reject: (value: unknown) => void
}

export type MediaAllowed = 'all' | 'audio-only' | 'video-only'
export type MediaDirectionAllowed = 'none' | 'receive' | 'both'
export type AudioAllowed = MediaDirectionAllowed
export type VideoAllowed = MediaDirectionAllowed

export interface Authorization {
type: 'video'
project: string
Expand All @@ -171,8 +176,9 @@ export interface Authorization {
}
signature: string
expires_at?: number
audio_allowed?: boolean
video_allowed?: boolean
media_allowed: MediaAllowed
audio_allowed: AudioAllowed
video_allowed: VideoAllowed
}

export interface RPCConnectResult {
Expand Down
3 changes: 2 additions & 1 deletion packages/js/src/BaseRoomSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
RoomMethods,
StartScreenShareOptions,
RoomSessionConnectionContract,
RoomSessionJoinAudienceParams,
} from './utils/interfaces'
import {
ROOM_COMPONENT_LISTENERS,
Expand Down Expand Up @@ -56,7 +57,7 @@ export interface BaseRoomSession<T>
*/
join(): Promise<T>
/** @internal */
joinAudience(options?: { audio?: boolean; video?: boolean }): Promise<T>
joinAudience(options?: RoomSessionJoinAudienceParams): Promise<T>
/**
* Leaves the room. This detaches all the locally originating streams from the
* room.
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ export interface RoomScreenShareMethods
extends RoomMemberSelfMethodsInterface {}

export interface RoomSessionJoinAudienceParams {
audio?: boolean
video?: boolean
receiveAudio?: boolean
receiveVideo?: boolean
}

export type PagingCursor =
Expand Down
19 changes: 10 additions & 9 deletions packages/js/src/utils/roomSession.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getLogger } from '@signalwire/core'
import type { Authorization } from '@signalwire/core'
import type { Authorization, MediaDirectionAllowed } from '@signalwire/core'
import type { RoomSessionJoinAudienceParams } from './interfaces'

// `joinAudience` utils
const getJoinAudienceMediaParams = ({
authState,
audio = true,
video = true,
receiveAudio = true,
receiveVideo = true,
}: RoomSessionJoinAudienceParams & {
authState: Authorization
}) => {
Expand All @@ -15,30 +15,31 @@ const getJoinAudienceMediaParams = ({
local,
kind,
}: {
remote?: boolean
local?: boolean
remote: MediaDirectionAllowed
local: boolean
kind: 'audio' | 'video'
}) => {
if (!remote && local) {
const remoteAllowed = remote !== 'none'
if (!remoteAllowed && local) {
getLogger().warn(
`[joinAudience] ${kind} is currently not allowed on this room.`
)
}

return !!(remote && local)
return !!(remoteAllowed && local)
}

return {
audio: false,
video: false,
negotiateAudio: getMediaValue({
remote: authState.audio_allowed,
local: audio,
local: receiveAudio,
kind: 'audio',
}),
negotiateVideo: getMediaValue({
remote: authState.video_allowed,
local: video,
local: receiveVideo,
kind: 'video',
}),
}
Expand Down

0 comments on commit fa62d67

Please sign in to comment.