mirror of
https://github.com/pion/webrtc.git
synced 2024-05-03 11:54:53 +08:00
Replace js.Value comparisons deprecated in Go 1.14
Use IsUndefined() and IsNull() to check for undefined and null js.Value when building with Go 1.14.
This commit is contained in:
parent
0272c250f4
commit
d5998ae2dd
@ -162,7 +162,7 @@ func (d *DataChannel) Label() string {
|
|||||||
// out-of-order delivery is allowed.
|
// out-of-order delivery is allowed.
|
||||||
func (d *DataChannel) Ordered() bool {
|
func (d *DataChannel) Ordered() bool {
|
||||||
ordered := d.underlying.Get("ordered")
|
ordered := d.underlying.Get("ordered")
|
||||||
if ordered == js.Undefined() {
|
if jsValueIsUndefined(ordered) {
|
||||||
return true // default is true
|
return true // default is true
|
||||||
}
|
}
|
||||||
return ordered.Bool()
|
return ordered.Bool()
|
||||||
@ -171,7 +171,7 @@ func (d *DataChannel) Ordered() bool {
|
|||||||
// MaxPacketLifeTime represents the length of the time window (msec) during
|
// MaxPacketLifeTime represents the length of the time window (msec) during
|
||||||
// which transmissions and retransmissions may occur in unreliable mode.
|
// which transmissions and retransmissions may occur in unreliable mode.
|
||||||
func (d *DataChannel) MaxPacketLifeTime() *uint16 {
|
func (d *DataChannel) MaxPacketLifeTime() *uint16 {
|
||||||
if d.underlying.Get("maxPacketLifeTime") != js.Undefined() {
|
if !jsValueIsUndefined(d.underlying.Get("maxPacketLifeTime")) {
|
||||||
return valueToUint16Pointer(d.underlying.Get("maxPacketLifeTime"))
|
return valueToUint16Pointer(d.underlying.Get("maxPacketLifeTime"))
|
||||||
} else {
|
} else {
|
||||||
// See https://bugs.chromium.org/p/chromium/issues/detail?id=696681
|
// See https://bugs.chromium.org/p/chromium/issues/detail?id=696681
|
||||||
|
13
js_compare.go
Normal file
13
js_compare.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// +build js,go1.14
|
||||||
|
|
||||||
|
package webrtc
|
||||||
|
|
||||||
|
import "syscall/js"
|
||||||
|
|
||||||
|
func jsValueIsUndefined(v js.Value) bool {
|
||||||
|
return v.IsUndefined()
|
||||||
|
}
|
||||||
|
|
||||||
|
func jsValueIsNull(v js.Value) bool {
|
||||||
|
return v.IsNull()
|
||||||
|
}
|
13
js_compare_legacy.go
Normal file
13
js_compare_legacy.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// +build js,!go1.14
|
||||||
|
|
||||||
|
package webrtc
|
||||||
|
|
||||||
|
import "syscall/js"
|
||||||
|
|
||||||
|
func jsValueIsUndefined(v js.Value) bool {
|
||||||
|
return v == js.Undefined()
|
||||||
|
}
|
||||||
|
|
||||||
|
func jsValueIsNull(v js.Value) bool {
|
||||||
|
return v == js.Null()
|
||||||
|
}
|
12
js_utils.go
12
js_utils.go
@ -42,7 +42,7 @@ func awaitPromise(promise js.Value) (js.Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func valueToUint16Pointer(val js.Value) *uint16 {
|
func valueToUint16Pointer(val js.Value) *uint16 {
|
||||||
if val == js.Null() || val == js.Undefined() {
|
if jsValueIsNull(val) || jsValueIsUndefined(val) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
convertedVal := uint16(val.Int())
|
convertedVal := uint16(val.Int())
|
||||||
@ -50,7 +50,7 @@ func valueToUint16Pointer(val js.Value) *uint16 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func valueToStringPointer(val js.Value) *string {
|
func valueToStringPointer(val js.Value) *string {
|
||||||
if val == js.Null() || val == js.Undefined() {
|
if jsValueIsNull(val) || jsValueIsUndefined(val) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
stringVal := val.String()
|
stringVal := val.String()
|
||||||
@ -79,28 +79,28 @@ func interfaceToValueOrUndefined(val interface{}) js.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func valueToStringOrZero(val js.Value) string {
|
func valueToStringOrZero(val js.Value) string {
|
||||||
if val == js.Undefined() || val == js.Null() {
|
if jsValueIsUndefined(val) || jsValueIsNull(val) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return val.String()
|
return val.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func valueToUint8OrZero(val js.Value) uint8 {
|
func valueToUint8OrZero(val js.Value) uint8 {
|
||||||
if val == js.Undefined() || val == js.Null() {
|
if jsValueIsUndefined(val) || jsValueIsNull(val) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return uint8(val.Int())
|
return uint8(val.Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func valueToUint16OrZero(val js.Value) uint16 {
|
func valueToUint16OrZero(val js.Value) uint16 {
|
||||||
if val == js.Null() || val == js.Undefined() {
|
if jsValueIsNull(val) || jsValueIsUndefined(val) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return uint16(val.Int())
|
return uint16(val.Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func valueToUint32OrZero(val js.Value) uint32 {
|
func valueToUint32OrZero(val js.Value) uint32 {
|
||||||
if val == js.Null() || val == js.Undefined() {
|
if jsValueIsNull(val) || jsValueIsUndefined(val) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return uint32(val.Int())
|
return uint32(val.Int())
|
||||||
|
@ -486,7 +486,7 @@ func iceServerToValue(server ICEServer) js.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func valueToConfiguration(configValue js.Value) Configuration {
|
func valueToConfiguration(configValue js.Value) Configuration {
|
||||||
if configValue == js.Null() || configValue == js.Undefined() {
|
if jsValueIsNull(configValue) || jsValueIsUndefined(configValue) {
|
||||||
return Configuration{}
|
return Configuration{}
|
||||||
}
|
}
|
||||||
return Configuration{
|
return Configuration{
|
||||||
@ -503,7 +503,7 @@ func valueToConfiguration(configValue js.Value) Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func valueToICEServers(iceServersValue js.Value) []ICEServer {
|
func valueToICEServers(iceServersValue js.Value) []ICEServer {
|
||||||
if iceServersValue == js.Null() || iceServersValue == js.Undefined() {
|
if jsValueIsNull(iceServersValue) || jsValueIsUndefined(iceServersValue) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
iceServers := make([]ICEServer, iceServersValue.Length())
|
iceServers := make([]ICEServer, iceServersValue.Length())
|
||||||
@ -524,7 +524,7 @@ func valueToICEServer(iceServerValue js.Value) ICEServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func valueToICECandidate(val js.Value) *ICECandidate {
|
func valueToICECandidate(val js.Value) *ICECandidate {
|
||||||
if val == js.Null() || val == js.Undefined() {
|
if jsValueIsNull(val) || jsValueIsUndefined(val) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
protocol, _ := NewICEProtocol(val.Get("protocol").String())
|
protocol, _ := NewICEProtocol(val.Get("protocol").String())
|
||||||
@ -564,7 +564,7 @@ func sessionDescriptionToValue(desc *SessionDescription) js.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func valueToSessionDescription(descValue js.Value) *SessionDescription {
|
func valueToSessionDescription(descValue js.Value) *SessionDescription {
|
||||||
if descValue == js.Null() || descValue == js.Undefined() {
|
if jsValueIsNull(descValue) || jsValueIsUndefined(descValue) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &SessionDescription{
|
return &SessionDescription{
|
||||||
|
Loading…
Reference in New Issue
Block a user