mirror of
				https://github.com/pion/webrtc.git
				synced 2025-10-31 18:52:55 +08:00 
			
		
		
		
	Expose NewSDPType
Allows a user to easily marshal a string to SDPType
This commit is contained in:
		| @@ -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 | ||||||
|   | |||||||
| @@ -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)} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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(), | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
| @@ -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, | ||||||
| 		) | 		) | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 decanus
					decanus