mirror of
https://github.com/pion/webrtc.git
synced 2025-09-27 03:25:58 +08:00
Don't cache SessionDescription during unmarshal
A user could use these across multiple interactions with the API. This
is confusing behavior because all their subsequent calls will be
ignored.
This reverts 3412dc6d95
This commit is contained in:
@@ -261,6 +261,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
|
|||||||
* [Dean Eigenmann](https://github.com/decanus)
|
* [Dean Eigenmann](https://github.com/decanus)
|
||||||
* [Cameron Elliott](https://github.com/cameronelliott)
|
* [Cameron Elliott](https://github.com/cameronelliott)
|
||||||
* [Pascal Benoit](https://github.com/pascal-ace)
|
* [Pascal Benoit](https://github.com/pascal-ace)
|
||||||
|
* [Mats](https://github.com/Mindgamesnl)
|
||||||
|
|
||||||
### License
|
### License
|
||||||
MIT License - see [LICENSE](LICENSE) for full text
|
MIT License - see [LICENSE](LICENSE) for full text
|
||||||
|
@@ -13,12 +13,8 @@ type SessionDescription struct {
|
|||||||
parsed *sdp.SessionDescription
|
parsed *sdp.SessionDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal is a helper to deserialize the sdp, and re-use it internally
|
// Unmarshal is a helper to deserialize the sdp
|
||||||
// if required
|
|
||||||
func (sd *SessionDescription) Unmarshal() (*sdp.SessionDescription, error) {
|
func (sd *SessionDescription) Unmarshal() (*sdp.SessionDescription, error) {
|
||||||
if sd.parsed != nil {
|
|
||||||
return sd.parsed, nil
|
|
||||||
}
|
|
||||||
sd.parsed = &sdp.SessionDescription{}
|
sd.parsed = &sdp.SessionDescription{}
|
||||||
err := sd.parsed.Unmarshal([]byte(sd.SDP))
|
err := sd.parsed.Unmarshal([]byte(sd.SDP))
|
||||||
return sd.parsed, err
|
return sd.parsed, err
|
||||||
|
@@ -2,6 +2,7 @@ package webrtc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -68,12 +69,15 @@ func TestSessionDescription_Unmarshal(t *testing.T) {
|
|||||||
SDP: offer.SDP,
|
SDP: offer.SDP,
|
||||||
}
|
}
|
||||||
assert.Nil(t, desc.parsed)
|
assert.Nil(t, desc.parsed)
|
||||||
parsed, err := desc.Unmarshal()
|
parsed1, err := desc.Unmarshal()
|
||||||
assert.NotNil(t, parsed)
|
assert.NotNil(t, parsed1)
|
||||||
assert.NotNil(t, desc.parsed)
|
assert.NotNil(t, desc.parsed)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
parsed, err = desc.Unmarshal()
|
parsed2, err2 := desc.Unmarshal()
|
||||||
assert.NotNil(t, parsed)
|
assert.NotNil(t, parsed2)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err2)
|
||||||
assert.NoError(t, pc.Close())
|
assert.NoError(t, pc.Close())
|
||||||
|
|
||||||
|
// check if the two parsed results _really_ match, could be affected by internal caching
|
||||||
|
assert.True(t, reflect.DeepEqual(parsed1, parsed2))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user