Repository: pion/webrtc
Pull request #1627 (2021-01-05 13:02:53)

enhancement/new-sdp-type-public
#### Description

Makes the `NewSDPType` function public.


codecov[bot]: # [Codecov](https://codecov.io/gh/pion/webrtc/pull/1627?src=pr&el=h1) Report
> Merging [#1627](https://codecov.io/gh/pion/webrtc/pull/1627?src=pr&el=desc) (12b8bd8) into [master](https://codecov.io/gh/pion/webrtc/commit/6ef4c1bba82a1b4d8a6bfc14c605909d7d1daf51?el=desc) (6ef4c1b) will **decrease** coverage by `5.03%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/pion/webrtc/pull/1627/graphs/tree.svg?width=650&height=150&src=pr&token=XOOuQo07I2)](https://codecov.io/gh/pion/webrtc/pull/1627?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1627      +/-   ##
==========================================
- Coverage   74.96%   69.93%   -5.04%     
==========================================
  Files          78       57      -21     
  Lines        5661     2145    -3516     
==========================================
- Hits         4244     1500    -2744     
+ Misses       1041      542     -499     
+ Partials      376      103     -273     
```

| Flag | Coverage Δ | |
|---|---|---|
| go | `?` | |
| wasm | `69.93% <100.00%> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/pion/webrtc/pull/1627?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [sdptype.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-c2RwdHlwZS5nbw==) | `94.73% <ø> (ø)` | |
| [peerconnection\_js.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-cGVlcmNvbm5lY3Rpb25fanMuZ28=) | `67.00% <100.00%> (ø)` | |
| [icetcp.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-aWNldGNwLmdv) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [rtpcodec.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-cnRwY29kZWMuZ28=) | `0.00% <0.00%> (-89.48%)` | :arrow_down: |
| [icecandidatepair.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-aWNlY2FuZGlkYXRlcGFpci5nbw==) | `0.00% <0.00%> (-85.72%)` | :arrow_down: |
| [track\_local.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-dHJhY2tfbG9jYWwuZ28=) | `0.00% <0.00%> (-80.00%)` | :arrow_down: |
| [stats.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-c3RhdHMuZ28=) | `0.00% <0.00%> (-67.86%)` | :arrow_down: |
| [gathering\_complete\_promise.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-Z2F0aGVyaW5nX2NvbXBsZXRlX3Byb21pc2UuZ28=) | `60.00% <0.00%> (-40.00%)` | :arrow_down: |
| [sdpsemantics.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-c2Rwc2VtYW50aWNzLmdv) | `0.00% <0.00%> (-37.50%)` | :arrow_down: |
| [dtlsrole.go](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree#diff-ZHRsc3JvbGUuZ28=) | `68.96% <0.00%> (-31.04%)` | :arrow_down: |
| ... and [27 more](https://codecov.io/gh/pion/webrtc/pull/1627/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pion/webrtc/pull/1627?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pion/webrtc/pull/1627?src=pr&el=footer). Last update [6ef4c1b...12b8bd8](https://codecov.io/gh/pion/webrtc/pull/1627?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Sean-Der: Nice! This PR looks great.

It is failing some of the linters it looks like, mind running [these](https://github.com/pion/webrtc/wiki/Contributing#run-all-automated-tests-and-checks-before-submitting) and force pushing this branch again. Thanks @decanus :) 
decanus: @Sean-Der will do.

Patch:
diff --git a/README.md b/README.md
index 728765ab..8aafa709 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/peerconnection.go b/peerconnection.go
index 30264cd9..f8c0d153 100644
--- a/peerconnection.go
+++ b/peerconnection.go
@@ -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)}
 	}
 
diff --git a/peerconnection_js.go b/peerconnection_js.go
index 21ebfbc2..c2931940 100644
--- a/peerconnection_js.go
+++ b/peerconnection_js.go
@@ -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(),
 	}
 }
diff --git a/sdptype.go b/sdptype.go
index 432a7261..bd49b6d1 100644
--- a/sdptype.go
+++ b/sdptype.go
@@ -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


Test patch:
diff --git a/sdptype_test.go b/sdptype_test.go
index 854c30b0..e325c222 100644
--- a/sdptype_test.go
+++ b/sdptype_test.go
@@ -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,
 		)
 	}