Expose NewSDPType

Allows a user to easily marshal a string to SDPType
This commit is contained in:
decanus
2021-01-05 14:01:08 +01:00
committed by Sean DuBois
parent 6ef4c1bba8
commit e3ec4024ba
5 changed files with 6 additions and 4 deletions

View File

@@ -258,6 +258,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
* [baiyufei](https://github.com/baiyufei) * [baiyufei](https://github.com/baiyufei)
* [pascal-ace](https://github.com/pascal-ace) * [pascal-ace](https://github.com/pascal-ace)
* [Threadnaught](https://github.com/Threadnaught) * [Threadnaught](https://github.com/Threadnaught)
* [Dean Eigenmann](https://github.com/decanus)
### License ### License
MIT License - see [LICENSE](LICENSE) for full text MIT License - see [LICENSE](LICENSE) for full text

View File

@@ -809,7 +809,7 @@ func (pc *PeerConnection) setDescription(sd *SessionDescription, op stateChangeO
switch { switch {
case pc.isClosed.get(): case pc.isClosed.get():
return &rtcerr.InvalidStateError{Err: ErrConnectionClosed} return &rtcerr.InvalidStateError{Err: ErrConnectionClosed}
case newSDPType(sd.Type.String()) == SDPType(Unknown): case NewSDPType(sd.Type.String()) == SDPType(Unknown):
return &rtcerr.TypeError{Err: fmt.Errorf("%w: '%d' is not a valid enum value of type SDPType", errPeerConnSDPTypeInvalidValue, sd.Type)} return &rtcerr.TypeError{Err: fmt.Errorf("%w: '%d' is not a valid enum value of type SDPType", errPeerConnSDPTypeInvalidValue, sd.Type)}
} }

View File

@@ -623,7 +623,7 @@ func valueToSessionDescription(descValue js.Value) *SessionDescription {
return nil return nil
} }
return &SessionDescription{ return &SessionDescription{
Type: newSDPType(descValue.Get("type").String()), Type: NewSDPType(descValue.Get("type").String()),
SDP: descValue.Get("sdp").String(), SDP: descValue.Get("sdp").String(),
} }
} }

View File

@@ -41,7 +41,8 @@ const (
sdpTypeRollbackStr = "rollback" sdpTypeRollbackStr = "rollback"
) )
func newSDPType(raw string) SDPType { // NewSDPType creates an SDPType from a string
func NewSDPType(raw string) SDPType {
switch raw { switch raw {
case sdpTypeOfferStr: case sdpTypeOfferStr:
return SDPTypeOffer return SDPTypeOffer

View File

@@ -21,7 +21,7 @@ func TestNewSDPType(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
assert.Equal(t, assert.Equal(t,
testCase.expectedSDPType, testCase.expectedSDPType,
newSDPType(testCase.sdpTypeString), NewSDPType(testCase.sdpTypeString),
"testCase: %d %v", i, testCase, "testCase: %d %v", i, testCase,
) )
} }