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

シングルストリーム接続は multistream: false を必須とする変更 #498

Merged
merged 6 commits into from
Mar 6, 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] シグナリングオプションの `multistream` は false の時のみシングルストリームを使用する
- シングルストリームを使用したい場合は `multistream: false` の指定が必須となる
- @tnamao
- [CHANGE] stopAudioTrack と stopVideoTrack を非推奨にする
- 代わりに名前を変えただけの removeAudioTrack と removeVideoTrack を用意する
- @voluntas
Expand Down
7 changes: 4 additions & 3 deletions packages/sdk/src/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export default class ConnectionPublisher extends ConnectionBase {
* @public
*/
async connect(stream: MediaStream): Promise<MediaStream> {
if (this.options.multistream) {
// options.multistream が明示的に false を指定した時だけシングルストリームにする
if (this.options.multistream === false) {
await Promise.race([
this.multiStream(stream).finally(() => {
this.singleStream(stream).finally(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ legacyStream という名前に統一して貰ってイイですか。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これも修正しつつ、コードのコメントや check.html もシングルをレガシーに修正しました

this.clearConnectionTimeout()
this.clearMonitorSignalingWebSocketEvent()
}),
Expand All @@ -30,7 +31,7 @@ export default class ConnectionPublisher extends ConnectionBase {
])
} else {
await Promise.race([
this.singleStream(stream).finally(() => {
this.multiStream(stream).finally(() => {
this.clearConnectionTimeout()
this.clearMonitorSignalingWebSocketEvent()
}),
Expand Down
4 changes: 1 addition & 3 deletions packages/sdk/src/sora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ class SoraConnection {
metadata: JSONType = null,
options: ConnectionOptions = { audio: true, video: true },
): ConnectionPublisher {
// sendrecv の場合、multistream に初期値を指定する
const sendrecvOptions: ConnectionOptions = Object.assign({ multistream: true }, options)
return new ConnectionPublisher(
this.signalingUrlCandidates,
'sendrecv',
channelId,
metadata,
sendrecvOptions,
options,
this.debug,
)
}
Expand Down
14 changes: 7 additions & 7 deletions packages/sdk/src/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export default class ConnectionSubscriber extends ConnectionBase {
*/
// biome-ignore lint/suspicious/noConfusingVoidType: stream が <MediaStream | void> なのでどうしようもない
async connect(): Promise<MediaStream | void> {
if (this.options.multistream) {
await Promise.race([
this.multiStream().finally(() => {
// options.multistream が明示的に false を指定した時だけシングルストリームにする
if (this.options.multistream === false) {
const stream = await Promise.race([
this.singleStream().finally(() => {
this.clearConnectionTimeout()
this.clearMonitorSignalingWebSocketEvent()
}),
Expand All @@ -28,10 +29,10 @@ export default class ConnectionSubscriber extends ConnectionBase {
])
this.monitorWebSocketEvent()
this.monitorPeerConnectionState()
return
return stream
}
const stream = await Promise.race([
this.singleStream().finally(() => {
await Promise.race([
this.multiStream().finally(() => {
this.clearConnectionTimeout()
this.clearMonitorSignalingWebSocketEvent()
}),
Expand All @@ -40,7 +41,6 @@ export default class ConnectionSubscriber extends ConnectionBase {
])
this.monitorWebSocketEvent()
this.monitorPeerConnectionState()
return stream
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export function createSignalingMessage(
video: true,
}
// role: sendrecv で multistream: false の場合は例外を発生させる
if (role === 'sendrecv' && options.multistream !== true) {
// options.multistream === undefined は multistream として扱う
if (role === 'sendrecv' && options.multistream === false) {
throw new Error(
"Failed to parse options. Options multistream must be true when connecting using 'sendrecv'",
)
Expand Down
23 changes: 20 additions & 3 deletions packages/sdk/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from 'vitest'
import { createSignalingMessage } from '../src/utils'
import { expect, test } from 'vitest'
import { type AudioCodecType, DataChannelDirection, VideoCodecType } from '../src/types'
import { createSignalingMessage } from '../src/utils'

const channelId = '7N3fsMHob'
const metadata = 'PG9A6RXgYqiqWKOVO'
Expand Down Expand Up @@ -47,6 +47,15 @@ test('createSignalingMessage simple sendrecv', () => {
).toEqual(expectedMessage)
})

test('createSignalingMessage sendrecv and undefined multistream', () => {
const expectedMessage = Object.assign({}, baseExpectedMessage, {
role: 'sendrecv',
})
expect(createSignalingMessage(sdp, 'sendrecv', channelId, undefined, {}, false)).toEqual(
expectedMessage,
)
})

test('createSignalingMessage invalid role', () => {
expect(() => {
createSignalingMessage(sdp, 'test', channelId, metadata, {}, false)
Expand All @@ -55,7 +64,7 @@ test('createSignalingMessage invalid role', () => {

test('createSignalingMessage sendrecv and multistream: false', () => {
expect(() => {
createSignalingMessage(sdp, 'sendrecv', channelId, metadata, {}, false)
createSignalingMessage(sdp, 'sendrecv', channelId, metadata, { multistream: false }, false)
}).toThrow(
Error(
"Failed to parse options. Options multistream must be true when connecting using 'sendrecv'",
Expand Down Expand Up @@ -140,6 +149,14 @@ test('createSignalingMessage multistream: true', () => {
)
})

test('createSignalingMessage undefined multistream', () => {
const options = {}
const expectedMessage = Object.assign({}, baseExpectedMessage, {})
expect(createSignalingMessage(sdp, 'sendonly', channelId, undefined, options, false)).toEqual(
expectedMessage,
)
})

test('createSignalingMessage multistream: false', () => {
const options = { multistream: false }
const expectedMessage = Object.assign({}, baseExpectedMessage, {
Expand Down