Skip to content
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

stop*Track を非推奨にして remove*Track を用意する #491

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

## develop

- [CHANGE] stopAudioTrack と stopVideoTrack を非推奨にする
- 代わりに名前を変えただけの removeAudioTrack と removeVideoTrack を用意する
- @voluntas
- [CHANGE] examples を Vite を利用して動かすように変更する
- serve を削除
- Vite を追加
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ https://github.com/shiguredo/sora-js-sdk-samples

```
# .env.local を作成して適切な値を設定してください
$ cp sample.env .env.local
$ cp .env.template .env.local
$ pnpm install
$ pnpm run dev
```
Expand All @@ -47,7 +47,7 @@ $ pnpm run dev

```
# .env.local を作成して適切な値を設定してください
$ cp sample.env .env.local
$ cp .env.template .env.local
$ pnpm install
$ pnpm exec playwright install --with-deps
$ pnpm run e2e-test
Expand Down
65 changes: 60 additions & 5 deletions packages/sdk/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ export default class ConnectionBase {
}

/**
* audio track を停止するメソッド
* audio track を削除するメソッド
*
* @deprecated この関数は非推奨です。代わりに removeAudioTrack を使用してください
*
* @example
* ```
Expand All @@ -345,11 +347,38 @@ export default class ConnectionBase {
* @remarks
* stream の audio track を停止後、PeerConnection の senders から対象の sender を削除します
*
* @param stream - audio track を停止する MediaStream
* @param stream - audio track を削除する MediaStream
*
* @public
*/
stopAudioTrack(stream: MediaStream): Promise<void> {
console.warn(
// @deprecated message
'@deprecated stopAudioTrack will be removed in a future version. Use removeAudioTrack instead.',
)
return this.removeAudioTrack(stream)
}

/**
* audio track を削除するメソッド
*
* @example
* ```
* const sendrecv = connection.sendrecv("sora");
* const mediaStream = await navigator.mediaDevices.getUserMedia({audio: true, video: true});
* await sendrecv.connect(mediaStream);
*
* sendrecv.removeAudioTrack(mediaStream);
* ```
*
* @remarks
* stream の audio track を停止後、PeerConnection の senders から対象の sender を削除します
*
* @param stream - audio track を削除する MediaStream
*
* @public
*/
removeAudioTrack(stream: MediaStream): Promise<void> {
for (const track of stream.getAudioTracks()) {
track.enabled = false
}
Expand All @@ -374,8 +403,11 @@ export default class ConnectionBase {
}, 100)
})
}

/**
* video track を停止するメソッド
* video track を削除するメソッド
*
* @deprecated この関数は非推奨です。代わりに removeVideoTrack を使用してください
*
* @example
* ```
Expand All @@ -394,6 +426,29 @@ export default class ConnectionBase {
* @public
*/
stopVideoTrack(stream: MediaStream): Promise<void> {
return this.removeVideoTrack(stream)
Hexa marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* video track を削除するメソッド
*
* @example
* ```
* const sendrecv = connection.sendrecv("sora");
* const mediaStream = await navigator.mediaDevices.getUserMedia({audio: true, video: true});
* await sendrecv.connect(mediaStream);
*
* sendrecv.removeVideoTrack(mediaStream);
* ```
*
* @remarks
* stream の video track を停止後、PeerConnection の senders から対象の sender を削除します
*
* @param stream - video track を削除する MediaStream
*
* @public
*/
removeVideoTrack(stream: MediaStream): Promise<void> {
for (const track of stream.getVideoTracks()) {
track.enabled = false
}
Expand Down Expand Up @@ -442,7 +497,7 @@ export default class ConnectionBase {
* @public
*/
async replaceAudioTrack(stream: MediaStream, audioTrack: MediaStreamTrack): Promise<void> {
await this.stopAudioTrack(stream)
await this.removeAudioTrack(stream)
const transceiver = this.getAudioTransceiver()
if (transceiver === null) {
throw new Error('Unable to set an audio track. Audio track sender is undefined')
Expand Down Expand Up @@ -474,7 +529,7 @@ export default class ConnectionBase {
* @public
*/
async replaceVideoTrack(stream: MediaStream, videoTrack: MediaStreamTrack): Promise<void> {
await this.stopVideoTrack(stream)
await this.removeVideoTrack(stream)
const transceiver = this.getVideoTransceiver()
if (transceiver === null) {
throw new Error('Unable to set video track. Video track sender is undefined')
Expand Down
Loading