Skip to content

Commit

Permalink
Standardize method names (#302)
Browse files Browse the repository at this point in the history
* rename microphone/speaker methods for RoomSessionMember

* rename speaker/microphone for RoomSession

* type Room test instace

* rename methods for Room obj

* change method names for RoomDevice

* add missing method to RoomDevice

* add changeset

* doc fixes

Co-authored-by: Daniele Di Sarli <danieleds0@gmail.com>
  • Loading branch information
framini and danieleds authored Sep 22, 2021
1 parent b60e9fc commit 2ac7f6d
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 67 deletions.
7 changes: 7 additions & 0 deletions .changeset/polite-plums-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@signalwire/core': patch
'@signalwire/js': patch
'@signalwire/realtime-api': patch
---

Added setInputVolume/setOutputVolume and marked setMicrophoneVolume/setSpeakerVolume as deprecated.
77 changes: 46 additions & 31 deletions packages/core/src/types/videoMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
ToInternalVideoEvent,
OnlyStateProperties,
OnlyFunctionProperties,
AssertSameType
AssertSameType,
} from './utils'
import * as Rooms from '../rooms'

Expand Down Expand Up @@ -42,26 +42,29 @@ type VideoMemberUpdatablePropsMain = {
[K in keyof InternalVideoMemberUpdatableProps as SnakeToCamelCase<K>]: InternalVideoMemberUpdatableProps[K]
}

type VideoMemberUpdatableProps = AssertSameType<VideoMemberUpdatablePropsMain, {
/** Whether the outbound audio is muted (e.g., from the microphone) */
audioMuted: boolean,
/** Whether the outbound video is muted */
videoMuted: boolean,
/** Whether the inbound audio is muted */
deaf: boolean,
/** Whether the member is on hold */
onHold: boolean,
/** Whether the member is visible */
visible: boolean,
/** Input volume (e.g., of the microphone). Values range from -50 to 50, with a default of 0. */
inputVolume: number,
/** Output volume (e.g., of the speaker). Values range from -50 to 50, with a default of 0. */
outputVolume: number,
/** Input level at which the participant is identified as currently speaking.
* The default value is 30 and the scale goes from 0 (lowest sensitivity,
* essentially muted) to 100 (highest sensitivity). */
inputSensitivity: number
}>
type VideoMemberUpdatableProps = AssertSameType<
VideoMemberUpdatablePropsMain,
{
/** Whether the outbound audio is muted (e.g., from the microphone) */
audioMuted: boolean
/** Whether the outbound video is muted */
videoMuted: boolean
/** Whether the inbound audio is muted */
deaf: boolean
/** Whether the member is on hold */
onHold: boolean
/** Whether the member is visible */
visible: boolean
/** Input volume (e.g., of the microphone). Values range from -50 to 50, with a default of 0. */
inputVolume: number
/** Output volume (e.g., of the speaker). Values range from -50 to 50, with a default of 0. */
outputVolume: number
/** Input level at which the participant is identified as currently speaking.
* The default value is 30 and the scale goes from 0 (lowest sensitivity,
* essentially muted) to 100 (highest sensitivity). */
inputSensitivity: number
}
>

// @ts-expect-error
export const MEMBER_UPDATABLE_PROPS: VideoMemberUpdatableProps = toExternalJSON(
Expand Down Expand Up @@ -209,37 +212,49 @@ export interface VideoMemberContract extends VideoMemberUpdatableProps {
setDeaf(value: boolean): Rooms.SetDeaf

/**
* Sets the microphone input level for the member.
* @deprecated Use {@link setInputVolume} instead.
* `setMicrophoneVolume` will be removed in v4.0.0
*/
setMicrophoneVolume(params: { volume: number }): Rooms.SetInputVolumeMember

/**
* Sets the input volume for the member (e.g., the microphone input level).
*
* @param params
* @param params
* @param params.volume desired volume. Values range from -50 to 50, with a
* default of 0.
*
* @example
* ```typescript
* await member.setMicrophoneVolume({volume: -10})
* await member.setInputVolume({volume: -10})
* ```
*/
setMicrophoneVolume(params: { volume: number }): Rooms.SetInputVolumeMember
setInputVolume(params: { volume: number }): Rooms.SetInputVolumeMember
/**
* @deprecated Use {@link setOutputVolume} instead.
* `setSpeakerVolume` will be removed in v4.0.0
*/

setSpeakerVolume(params: { volume: number }): Rooms.SetOutputVolumeMember

/**
* Sets the speaker output level.
* Sets the output volume for the member (e.g., the speaker output level).
*
* @param params
* @param params
* @param params.volume desired volume. Values range from -50 to 50, with a
* default of 0.
*
* @example
* ```typescript
* await member.setSpeakerVolume({volume: -10})
* await member.setOutputVolume({volume: -10})
* ```
*/
setSpeakerVolume(params: { volume: number }): Rooms.SetOutputVolumeMember
setOutputVolume(params: { volume: number }): Rooms.SetOutputVolumeMember

/**
* Sets the input level at which the participant is identified as currently
* speaking.
*
*
* @param params
* @param params.value desired sensitivity. The default value is 30 and the
* scale goes from 0 (lowest sensitivity, essentially muted) to 100 (highest
Expand All @@ -256,7 +271,7 @@ export interface VideoMemberContract extends VideoMemberUpdatableProps {

/**
* Removes this member from the room.
*
*
* @example
* ```typescript
* await member.remove()
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/types/videoRoomSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export interface VideoRoomSessionContract {
setMicrophoneVolume(
params: MemberCommandWithVolumeParams
): Rooms.SetInputVolumeMember
setInputVolume(
params: MemberCommandWithVolumeParams
): Rooms.SetInputVolumeMember
setInputSensitivity(
params: MemberCommandWithValueParams
): Rooms.SetInputSensitivityMember
Expand All @@ -73,6 +76,9 @@ export interface VideoRoomSessionContract {
setSpeakerVolume(
params: MemberCommandWithVolumeParams
): Rooms.SetOutputVolumeMember
setOutputVolume(
params: MemberCommandWithVolumeParams
): Rooms.SetOutputVolumeMember
removeMember(params: Required<MemberCommandParams>): Rooms.RemoveMember
setHideVideoMuted(value: boolean): Rooms.SetHideVideoMuted
getLayouts(): Rooms.GetLayouts
Expand Down
21 changes: 20 additions & 1 deletion packages/js/src/Room.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { EventEmitter, actions } from '@signalwire/core'
import { createRoomSessionObject } from './Room'
import type { Room } from './Room'
import { configureJestStore, configureFullStack } from './testUtils'

describe('Room Object', () => {
let store: any
let room: any
let room: Room

beforeEach(() => {
store = configureJestStore()
room = createRoomSessionObject({
store,
emitter: new EventEmitter(),
})
// @ts-expect-error
room.execute = jest.fn()
// mock a room.subscribed event
// @ts-expect-error
room.onRoomSubscribed({
nodeId: 'node-id',
roomId: 'room-id',
Expand All @@ -29,6 +32,8 @@ describe('Room Object', () => {
expect(room.videoUnmute).toBeDefined()
expect(room.deaf).toBeDefined()
expect(room.undeaf).toBeDefined()
expect(room.setInputVolume).toBeDefined()
expect(room.setOutputVolume).toBeDefined()
expect(room.setMicrophoneVolume).toBeDefined()
expect(room.setSpeakerVolume).toBeDefined()
expect(room.setInputSensitivity).toBeDefined()
Expand Down Expand Up @@ -59,6 +64,7 @@ describe('Room Object', () => {
emitter,
})
// mock a room.subscribed event
// @ts-expect-error
room.onRoomSubscribed({
nodeId: 'node-id',
roomId: '6e83849b-5cc2-4fc6-80ed-448113c8a426',
Expand All @@ -75,13 +81,15 @@ describe('Room Object', () => {

describe('startRecording', () => {
it('should return an interactive object', async () => {
// @ts-expect-error
;(room.execute as jest.Mock).mockResolvedValueOnce({
code: '200',
message: 'Recording started',
recording_id: 'c22d7223-5a01-49fe-8da0-46bec8e75e32',
})

const recording = await room.startRecording()
// @ts-expect-error
recording.execute = jest.fn()
expect(recording.id).toEqual('c22d7223-5a01-49fe-8da0-46bec8e75e32')
expect(recording.roomSessionId).toEqual('room-session-id')
Expand All @@ -97,42 +105,50 @@ describe('Room Object', () => {
},
}
await recording.pause()
// @ts-expect-error
expect(recording.execute).toHaveBeenLastCalledWith({
...baseExecuteParams,
method: 'video.recording.pause',
})
await recording.resume()
// @ts-expect-error
expect(recording.execute).toHaveBeenLastCalledWith({
...baseExecuteParams,
method: 'video.recording.resume',
})
await recording.stop()
// @ts-expect-error
expect(recording.execute).toHaveBeenLastCalledWith({
...baseExecuteParams,
method: 'video.recording.stop',
})
})

it('should work with simulataneous recordings', async () => {
// @ts-expect-error
;(room.execute as jest.Mock).mockResolvedValueOnce({
code: '200',
message: 'Recording started',
recording_id: 'first-recording',
})
// @ts-expect-error
;(room.execute as jest.Mock).mockResolvedValueOnce({
code: '200',
message: 'Recording started',
recording_id: 'second-recording',
})

const firstRecording = await room.startRecording()
// @ts-expect-error
firstRecording.execute = jest.fn()
const secondRecording = await room.startRecording()
// @ts-expect-error
secondRecording.execute = jest.fn()

expect(firstRecording.id).toEqual('first-recording')
expect(firstRecording.roomSessionId).toEqual('room-session-id')
await firstRecording.stop()
// @ts-expect-error
expect(firstRecording.execute).toHaveBeenLastCalledWith({
method: 'video.recording.stop',
params: {
Expand All @@ -144,6 +160,7 @@ describe('Room Object', () => {
expect(secondRecording.id).toEqual('second-recording')
expect(secondRecording.roomSessionId).toEqual('room-session-id')
await secondRecording.stop()
// @ts-expect-error
expect(secondRecording.execute).toHaveBeenLastCalledWith({
method: 'video.recording.stop',
params: {
Expand All @@ -162,8 +179,10 @@ describe('Room Object', () => {
// @ts-expect-error
emitter,
})
// @ts-expect-error
room.execute = jest.fn()
// mock a room.subscribed event
// @ts-expect-error
room.onRoomSubscribed({
nodeId: 'node-id',
roomId: '6e83849b-5cc2-4fc6-80ed-448113c8a426',
Expand Down
2 changes: 2 additions & 0 deletions packages/js/src/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ export const RoomAPI = extendComponent<RoomConnection, RoomMethods>(
videoUnmute: Rooms.videoUnmuteMember,
deaf: Rooms.deafMember,
undeaf: Rooms.undeafMember,
setInputVolume: Rooms.setInputVolumeMember,
setOutputVolume: Rooms.setOutputVolumeMember,
setMicrophoneVolume: Rooms.setInputVolumeMember,
setSpeakerVolume: Rooms.setOutputVolumeMember,
setInputSensitivity: Rooms.setInputSensitivityMember,
Expand Down
7 changes: 5 additions & 2 deletions packages/js/src/RoomDevice.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { RoomDeviceAPI } from './RoomDevice'
import type { RoomDevice } from './RoomDevice'
import { configureJestStore } from './testUtils'

describe('RoomDevice Object', () => {
let roomDevice: any
let roomDevice: RoomDevice

beforeEach(() => {
roomDevice = new RoomDeviceAPI({
store: configureJestStore(),
emitter: jest.fn() as any,
})
}) as any as RoomDevice
// @ts-expect-error
roomDevice.execute = jest.fn()
})

Expand All @@ -18,6 +20,7 @@ describe('RoomDevice Object', () => {
expect(roomDevice.videoMute).toBeDefined()
expect(roomDevice.videoUnmute).toBeDefined()
expect(roomDevice.setMicrophoneVolume).toBeDefined()
expect(roomDevice.setInputVolume).toBeDefined()
expect(roomDevice.setInputSensitivity).toBeDefined()
})
})
1 change: 1 addition & 0 deletions packages/js/src/RoomDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const RoomDeviceAPI = extendComponent<
audioUnmute: Rooms.audioUnmuteMember,
videoMute: Rooms.videoMuteMember,
videoUnmute: Rooms.videoUnmuteMember,
setInputVolume: Rooms.setInputVolumeMember,
setMicrophoneVolume: Rooms.setInputVolumeMember,
setInputSensitivity: Rooms.setInputSensitivityMember,
})
7 changes: 5 additions & 2 deletions packages/js/src/RoomScreenShare.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { RoomScreenShareAPI } from './RoomScreenShare'
import type { RoomScreenShare } from './RoomScreenShare'
import { configureJestStore } from './testUtils'

describe('RoomScreenShare Object', () => {
let roomScreenShare: any
let roomScreenShare: RoomScreenShare

beforeEach(() => {
roomScreenShare = new RoomScreenShareAPI({
store: configureJestStore(),
emitter: jest.fn() as any,
})
}) as any as RoomScreenShare
// @ts-expect-error
roomScreenShare.execute = jest.fn()
})

Expand All @@ -18,6 +20,7 @@ describe('RoomScreenShare Object', () => {
expect(roomScreenShare.videoMute).toBeDefined()
expect(roomScreenShare.videoUnmute).toBeDefined()
expect(roomScreenShare.setMicrophoneVolume).toBeDefined()
expect(roomScreenShare.setInputVolume).toBeDefined()
expect(roomScreenShare.setInputSensitivity).toBeDefined()
})
})
1 change: 1 addition & 0 deletions packages/js/src/RoomScreenShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ export const RoomScreenShareAPI = extendComponent<
videoMute: Rooms.videoMuteMember,
videoUnmute: Rooms.videoUnmuteMember,
setMicrophoneVolume: Rooms.setInputVolumeMember,
setInputVolume: Rooms.setInputVolumeMember,
setInputSensitivity: Rooms.setInputSensitivityMember,
})
Loading

0 comments on commit 2ac7f6d

Please sign in to comment.