-
Notifications
You must be signed in to change notification settings - Fork 271
Data track schema metadata #1994
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
base: main
Are you sure you want to change the base?
Changes from all commits
999be68
09a1473
868b284
04eaa80
6bfa1d9
ddc00b9
8c5df6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,22 @@ | ||
| import type LocalDataTrack from '../LocalDataTrack'; | ||
| import { type DataTrackHandle } from '../handle'; | ||
| import { type DataTrackInfo, type DataTrackSid } from '../types'; | ||
| import { | ||
| type DataTrackFrameEncoding, | ||
| type DataTrackInfo, | ||
| type DataTrackSchemaId, | ||
| type DataTrackSid, | ||
| } from '../types'; | ||
| import { type DataTrackPublishError, type DataTrackPublishErrorReason } from './errors'; | ||
|
|
||
| /** Options for publishing a data track. */ | ||
| export type DataTrackOptions = { | ||
| name: string; | ||
|
|
||
| /** Schema describing frames sent on the track. */ | ||
| schema?: DataTrackSchemaId; | ||
|
|
||
| /** Encoding of frames sent on the track. */ | ||
| frameEncoding?: DataTrackFrameEncoding; | ||
| }; | ||
|
Comment on lines
11
to
20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: To confirm - is there a relationship between schema encoding and frame encoding? Or can a user specify any type of frame encoding for any time of schema encoding? If there is a relationship and there are some combinations that aren't allowed, I think it would be good at least in the public type (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great callout! Yes, the valid combinations are documented in the doc comments for the enum, however, I would like to have some validation of this. I'm not sure if it is feasible to make this validated at the type level (at least not in all client SDKs), but we could at least validate at publish time. Another option is to implement this on the SFU side and have it return an error during track publication if an invalid combination is used (possible advantage: no need to update this logic in every client if new schema/frame encoding cases are added in the future). What are your thoughts here?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's probably not something that would need to be done in all client sdks, but if this isn't something that is likely to change and in the future new relationships will be purely additive (ie, Definitely though implement this as a "denylist" and not an "allowlist" so that future newly introduced combos will work in old sdks.
IMO it's worth doing this in both places, just like you'd have both client side and server side form validation. |
||
|
|
||
| /** Encodes whether a data track publish request to the SFU has been successful or not. */ | ||
|
|
@@ -26,6 +37,8 @@ export type EventSfuPublishRequest = { | |
| handle: DataTrackHandle; | ||
| name: string; | ||
| usesE2ee: boolean; | ||
| schema?: DataTrackSchemaId; | ||
| frameEncoding?: DataTrackFrameEncoding; | ||
| }; | ||
|
|
||
| /** Request sent to the SFU to unpublish a track. */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { | ||
| DataTrackFrameEncoding as ProtocolDataTrackFrameEncoding, | ||
| DataTrackSchemaEncoding as ProtocolDataTrackSchemaEncoding, | ||
| DataTrackSchemaId as ProtocolDataTrackSchemaId, | ||
| DataTrackFrameEncoding_WellKnownFrameEncoding as ProtocolWellKnownFrameEncoding, | ||
| DataTrackSchemaEncoding_WellKnownSchemaEncoding as ProtocolWellKnownSchemaEncoding, | ||
| } from '@livekit/protocol'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { DataTrackFrameEncoding, DataTrackSchemaEncoding, DataTrackSchemaId } from './schema'; | ||
|
|
||
| describe('DataTrackSchemaEncoding', () => { | ||
| const wellKnown: Array<DataTrackSchemaEncoding> = [ | ||
| 'protobuf', | ||
| 'flatbuffer', | ||
| 'ros1Msg', | ||
| 'ros2Msg', | ||
| 'ros2Idl', | ||
| 'omgIdl', | ||
| 'jsonSchema', | ||
| ]; | ||
|
|
||
| it.each(wellKnown)('round-trips well-known encoding %s', (encoding) => { | ||
| const protobuf = DataTrackSchemaEncoding.toProtobuf(encoding); | ||
| expect(protobuf.value.case).toStrictEqual('wellKnown'); | ||
| expect(DataTrackSchemaEncoding.from(protobuf)).toStrictEqual(encoding); | ||
| }); | ||
|
|
||
| it('round-trips a custom encoding', () => { | ||
| const encoding: DataTrackSchemaEncoding = { custom: 'my_encoding' }; | ||
| const protobuf = DataTrackSchemaEncoding.toProtobuf(encoding); | ||
| expect(protobuf.value).toStrictEqual({ case: 'custom', value: 'my_encoding' }); | ||
| expect(DataTrackSchemaEncoding.from(protobuf)).toStrictEqual(encoding); | ||
| }); | ||
|
|
||
| it('maps an unspecified well-known value to "other"', () => { | ||
| const protobuf = new ProtocolDataTrackSchemaEncoding({ | ||
| value: { case: 'wellKnown', value: ProtocolWellKnownSchemaEncoding.UNSPECIFIED }, | ||
| }); | ||
| expect(DataTrackSchemaEncoding.from(protobuf)).toStrictEqual('other'); | ||
| }); | ||
|
|
||
| it('maps a well-known value introduced after this version to "other"', () => { | ||
| const protobuf = new ProtocolDataTrackSchemaEncoding({ | ||
| value: { case: 'wellKnown', value: 999 as ProtocolWellKnownSchemaEncoding }, | ||
| }); | ||
| expect(DataTrackSchemaEncoding.from(protobuf)).toStrictEqual('other'); | ||
| }); | ||
|
|
||
| it('maps an absent oneof to "other"', () => { | ||
| expect(DataTrackSchemaEncoding.from(new ProtocolDataTrackSchemaEncoding())).toStrictEqual( | ||
| 'other', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('DataTrackFrameEncoding', () => { | ||
| const wellKnown: Array<DataTrackFrameEncoding> = [ | ||
| 'ros1', | ||
| 'cdr', | ||
| 'protobuf', | ||
| 'flatbuffer', | ||
| 'cbor', | ||
| 'msgpack', | ||
| 'json', | ||
| ]; | ||
|
|
||
| it.each(wellKnown)('round-trips well-known encoding %s', (encoding) => { | ||
| const protobuf = DataTrackFrameEncoding.toProtobuf(encoding); | ||
| expect(protobuf.value.case).toStrictEqual('wellKnown'); | ||
| expect(DataTrackFrameEncoding.from(protobuf)).toStrictEqual(encoding); | ||
| }); | ||
|
|
||
| it('round-trips a custom encoding', () => { | ||
| const encoding: DataTrackFrameEncoding = { custom: 'my_encoding' }; | ||
| const protobuf = DataTrackFrameEncoding.toProtobuf(encoding); | ||
| expect(protobuf.value).toStrictEqual({ case: 'custom', value: 'my_encoding' }); | ||
| expect(DataTrackFrameEncoding.from(protobuf)).toStrictEqual(encoding); | ||
| }); | ||
|
|
||
| it('maps an unspecified well-known value to "other"', () => { | ||
| const protobuf = new ProtocolDataTrackFrameEncoding({ | ||
| value: { case: 'wellKnown', value: ProtocolWellKnownFrameEncoding.UNSPECIFIED }, | ||
| }); | ||
| expect(DataTrackFrameEncoding.from(protobuf)).toStrictEqual('other'); | ||
| }); | ||
|
|
||
| it('maps a well-known value introduced after this version to "other"', () => { | ||
| const protobuf = new ProtocolDataTrackFrameEncoding({ | ||
| value: { case: 'wellKnown', value: 999 as ProtocolWellKnownFrameEncoding }, | ||
| }); | ||
| expect(DataTrackFrameEncoding.from(protobuf)).toStrictEqual('other'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('DataTrackSchemaId', () => { | ||
| it('round-trips name and encoding', () => { | ||
| const schemaId: DataTrackSchemaId = { name: 'rgb', encoding: 'protobuf' }; | ||
| const protobuf = DataTrackSchemaId.toProtobuf(schemaId); | ||
| expect(protobuf).toBeInstanceOf(ProtocolDataTrackSchemaId); | ||
| expect(protobuf.name).toStrictEqual('rgb'); | ||
| expect(DataTrackSchemaId.from(protobuf)).toStrictEqual(schemaId); | ||
| }); | ||
|
|
||
| it('defaults encoding to "other" when the protobuf encoding is absent', () => { | ||
| const protobuf = new ProtocolDataTrackSchemaId({ name: 'rgb' }); | ||
| expect(DataTrackSchemaId.from(protobuf)).toStrictEqual({ name: 'rgb', encoding: 'other' }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.