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)
* [pascal-ace](https://github.com/pascal-ace)
* [Threadnaught](https://github.com/Threadnaught)
* [Dean Eigenmann](https://github.com/decanus)
### License
MIT License - see [LICENSE](LICENSE) for full text

View File

@@ -809,7 +809,7 @@ func (pc *PeerConnection) setDescription(sd *SessionDescription, op stateChangeO
switch {
case pc.isClosed.get():
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)}
}

View File

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

View File

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

View File

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