mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 15:16:52 +08:00

Fixes #515 This includes a few small and closely related changes: 1. All occurrences of the build tag `+build js` have been changed to the more precise `+build js,wasm`. This will exclude the files from being included by third-party compilers like GopherJS, with which they are incompatible. 2. Some files which are incompatible with JavaScript/Wasm now have the correct build tag (`+build -js`) so they will be excluded from Wasm builds. 3. Some configuration options which are incompatible with JavaScript/Wasm (or at least the current bindings) will now no longer appear in Wasm builds. This meant creating new files with new struct definitions and the appropriate build tags.
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
// +build js,wasm
|
|
|
|
package webrtc
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func signalPair(pcOffer *PeerConnection, pcAnswer *PeerConnection) (err error) {
|
|
offerChan := make(chan SessionDescription)
|
|
pcOffer.OnICECandidate(func(candidate *string) {
|
|
if candidate == nil {
|
|
offerChan <- *pcOffer.PendingLocalDescription()
|
|
}
|
|
})
|
|
|
|
// Note(albrow): We need to create a data channel in order to trigger ICE
|
|
// candidate gathering in the background.
|
|
if _, err := pcOffer.CreateDataChannel("initial_data_channel", nil); err != nil {
|
|
return err
|
|
}
|
|
|
|
offer, err := pcOffer.CreateOffer(nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := pcOffer.SetLocalDescription(offer); err != nil {
|
|
return err
|
|
}
|
|
|
|
timeout := time.After(3 * time.Second)
|
|
select {
|
|
case <-timeout:
|
|
return fmt.Errorf("timed out waiting to receive offer")
|
|
case offer := <-offerChan:
|
|
if err := pcAnswer.SetRemoteDescription(offer); err != nil {
|
|
return err
|
|
}
|
|
|
|
answer, err := pcAnswer.CreateAnswer(nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err = pcAnswer.SetLocalDescription(answer); err != nil {
|
|
return err
|
|
}
|
|
|
|
err = pcOffer.SetRemoteDescription(answer)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
return nil
|
|
}
|