-
Notifications
You must be signed in to change notification settings - Fork 14
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
Playback APIs #297
Merged
Merged
Playback APIs #297
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f2d9127
first step in playback apis for core
edolix b78bbaa
add room methods and implement RoomSessionPlayback object
edolix 827340d
expose getPlaybacks/startPlayback for JS package
edolix 1cf144d
fix core tests
edolix 08e6624
update heroku example
edolix de257d8
uses toLocalEvent for playback.start method
edolix 614dcb0
rename startPlayback to just play
edolix ffc0a8b
implement playback apis for realtime-api
edolix edc6379
add missing exported member
danieleds b95fb8d
add docs
danieleds 629d31a
clarify return value from getPlaybacks (and getRecordings for consist…
danieleds 4003e61
rewording
danieleds 07d4918
add explicit parameters in RoomSessionDocs.play
danieleds 488d4c4
add describe block for playback apis
edolix 7206ea7
Merge branch 'main' into eg/playback-apis
edolix 58a6b2f
remove conflict stuff
edolix 4c4534f
add protocol information for now
danieleds df4c721
allow playback events on RT RoomSession
edolix 4f218a2
transform playbacks and recording with toExternalJSON
edolix a75138b
update rt example
edolix d4d8f26
apply toExternalJSON on JS RoomSession
edolix e3c710e
add changeset
edolix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@signalwire/core': minor | ||
'@signalwire/js': minor | ||
'@signalwire/realtime-api': minor | ||
--- | ||
|
||
Add support for the Playback APIs: `roomSession.play()` and the `RoomSessionPlayback` object to control it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { configureJestStore } from '../testUtils' | ||
import { EventEmitter } from '../utils/EventEmitter' | ||
import { | ||
createRoomSessionPlaybackObject, | ||
RoomSessionPlayback, | ||
RoomSessionPlaybackEventsHandlerMapping, | ||
} from './RoomSessionPlayback' | ||
|
||
describe('RoomSessionPlayback', () => { | ||
describe('createRoomSessionPlaybackObject', () => { | ||
let instance: RoomSessionPlayback | ||
beforeEach(() => { | ||
instance = createRoomSessionPlaybackObject({ | ||
store: configureJestStore(), | ||
emitter: new EventEmitter<RoomSessionPlaybackEventsHandlerMapping>(), | ||
}) | ||
// @ts-expect-error | ||
instance.execute = jest.fn() | ||
}) | ||
|
||
it('should control an active playback', async () => { | ||
// Mock properties | ||
instance.id = 'c22d7223-5a01-49fe-8da0-46bec8e75e32' | ||
instance.roomSessionId = 'room-session-id' | ||
|
||
const baseExecuteParams = { | ||
method: '', | ||
params: { | ||
room_session_id: 'room-session-id', | ||
playback_id: 'c22d7223-5a01-49fe-8da0-46bec8e75e32', | ||
}, | ||
} | ||
await instance.pause() | ||
// @ts-expect-error | ||
expect(instance.execute).toHaveBeenLastCalledWith({ | ||
...baseExecuteParams, | ||
method: 'video.playback.pause', | ||
}) | ||
await instance.resume() | ||
// @ts-expect-error | ||
expect(instance.execute).toHaveBeenLastCalledWith({ | ||
...baseExecuteParams, | ||
method: 'video.playback.resume', | ||
}) | ||
await instance.stop() | ||
// @ts-expect-error | ||
expect(instance.execute).toHaveBeenLastCalledWith({ | ||
...baseExecuteParams, | ||
method: 'video.playback.stop', | ||
}) | ||
await instance.setVolume(30) | ||
// @ts-expect-error | ||
expect(instance.execute).toHaveBeenLastCalledWith({ | ||
method: 'video.playback.set_volume', | ||
params: { | ||
room_session_id: 'room-session-id', | ||
playback_id: 'c22d7223-5a01-49fe-8da0-46bec8e75e32', | ||
volume: 30, | ||
}, | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { connect } from '../redux' | ||
import { BaseComponent } from '../BaseComponent' | ||
import { BaseComponentOptions } from '../utils/interfaces' | ||
import type { | ||
VideoPlaybackContract, | ||
VideoPlaybackMethods, | ||
VideoPlaybackEventNames, | ||
} from '../types/videoPlayback' | ||
|
||
/** | ||
* Instances of this class allow you to control (e.g., pause, resume, stop) the | ||
* playback inside a room session. You can obtain instances of this class by | ||
* starting a playback from the desired {@link RoomSession} (see | ||
* {@link RoomSession.play}) | ||
*/ | ||
export interface RoomSessionPlayback extends VideoPlaybackContract {} | ||
|
||
export type RoomSessionPlaybackEventsHandlerMapping = Record< | ||
VideoPlaybackEventNames, | ||
(playback: RoomSessionPlayback) => void | ||
> | ||
|
||
export class RoomSessionPlaybackAPI | ||
extends BaseComponent<RoomSessionPlaybackEventsHandlerMapping> | ||
implements VideoPlaybackMethods | ||
{ | ||
async pause() { | ||
await this.execute({ | ||
method: 'video.playback.pause', | ||
params: { | ||
room_session_id: this.getStateProperty('roomSessionId'), | ||
playback_id: this.getStateProperty('id'), | ||
}, | ||
}) | ||
} | ||
|
||
async resume() { | ||
await this.execute({ | ||
method: 'video.playback.resume', | ||
params: { | ||
room_session_id: this.getStateProperty('roomSessionId'), | ||
playback_id: this.getStateProperty('id'), | ||
}, | ||
}) | ||
} | ||
|
||
async stop() { | ||
await this.execute({ | ||
method: 'video.playback.stop', | ||
params: { | ||
room_session_id: this.getStateProperty('roomSessionId'), | ||
playback_id: this.getStateProperty('id'), | ||
}, | ||
}) | ||
} | ||
|
||
async setVolume(volume: number) { | ||
await this.execute({ | ||
method: 'video.playback.set_volume', | ||
params: { | ||
room_session_id: this.getStateProperty('roomSessionId'), | ||
playback_id: this.getStateProperty('id'), | ||
volume, | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
export const createRoomSessionPlaybackObject = ( | ||
params: BaseComponentOptions<RoomSessionPlaybackEventsHandlerMapping> | ||
): RoomSessionPlayback => { | ||
const playback = connect< | ||
RoomSessionPlaybackEventsHandlerMapping, | ||
RoomSessionPlaybackAPI, | ||
RoomSessionPlayback | ||
>({ | ||
store: params.store, | ||
Component: RoomSessionPlaybackAPI, | ||
componentListeners: { | ||
errors: 'onError', | ||
responses: 'onSuccess', | ||
}, | ||
})(params) | ||
|
||
return playback | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for @danieleds - we are transforming the properties from snake_case to camelCase here (and same for
playbacks
on L171 below)