Code refactoring
Code refactoring
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
## Userful links
|
||||
|
||||
- https://www.ietf.org/archive/id/draft-ietf-wish-whip-01.html
|
||||
- https://www.ietf.org/id/draft-murillo-whep-01.html
|
||||
- https://github.com/Glimesh/broadcast-box/
|
||||
- https://github.com/obsproject/obs-studio/pull/7926
|
||||
@@ -61,7 +61,7 @@ func asyncCandidates(tr *api.Transport, cons *webrtc.Conn) {
|
||||
if candidates, ok := ctx["candidate"].([]string); ok {
|
||||
// process candidates that receive before this moment
|
||||
for _, candidate := range candidates {
|
||||
cons.AddCandidate(candidate)
|
||||
_ = cons.AddCandidate(candidate)
|
||||
}
|
||||
|
||||
// remove already processed candidates
|
||||
|
||||
+1
-2
@@ -84,8 +84,7 @@ func Do(req *http.Request) (*http.Response, error) {
|
||||
|
||||
req.Header.Set("Authorization", header)
|
||||
|
||||
res, err = client.Do(req)
|
||||
if err != nil {
|
||||
if res, err = client.Do(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
## StateChange
|
||||
|
||||
1. offer = pc.CreateOffer()
|
||||
2. pc.SetLocalDescription(offer)
|
||||
3. OnICEGatheringStateChange: gathering
|
||||
4. OnSignalingStateChange: have-local-offer
|
||||
*. OnICEGatheringStateChange: complete
|
||||
5. pc.SetRemoteDescription(answer)
|
||||
6. OnSignalingStateChange: stable
|
||||
7. OnICEConnectionStateChange: checking
|
||||
8. OnICEConnectionStateChange: connected
|
||||
@@ -57,7 +57,7 @@ func (c *Conn) GetAnswer() (answer string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
return desc.SDP, nil
|
||||
return c.pc.LocalDescription().SDP, nil
|
||||
}
|
||||
|
||||
func (c *Conn) GetCompleteAnswer() (answer string, err error) {
|
||||
|
||||
+13
-12
@@ -27,14 +27,17 @@
|
||||
<video id="video" autoplay controls playsinline muted></video>
|
||||
<script>
|
||||
// support api_path
|
||||
let baseUrl = location.origin + location.pathname.substr(
|
||||
const baseUrl = location.origin + location.pathname.substr(
|
||||
0, location.pathname.lastIndexOf("/")
|
||||
);
|
||||
|
||||
let pc = new RTCPeerConnection({
|
||||
iceServers: [{urls: 'stun:stun.l.google.com:19302'}]
|
||||
const pc = new RTCPeerConnection({
|
||||
iceServers: [
|
||||
{urls: 'stun:stun.l.google.com:19302'},
|
||||
]
|
||||
});
|
||||
pc.onicegatheringstatechange = async () => {
|
||||
|
||||
pc.addEventListener('icegatheringstatechange', async () => {
|
||||
if (pc.iceGatheringState !== 'complete') return;
|
||||
|
||||
let r = await fetch(`${baseUrl}/api/webrtc${location.search}`, {
|
||||
@@ -43,20 +46,18 @@
|
||||
await pc.setRemoteDescription({
|
||||
type: 'answer', sdp: await r.text()
|
||||
});
|
||||
}
|
||||
pc.ontrack = ev => {
|
||||
});
|
||||
pc.addEventListener('track', ev => {
|
||||
let video = document.getElementById('video');
|
||||
if (video.srcObject === null) {
|
||||
video.srcObject = ev.streams[0];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
pc.addTransceiver('video');
|
||||
pc.addTransceiver('audio');
|
||||
pc.addTransceiver('video', {direction: 'recvonly'});
|
||||
pc.addTransceiver('audio', {direction: 'recvonly'});
|
||||
|
||||
pc.createOffer({
|
||||
offerToReceiveVideo: true, offerToReceiveAudio: true
|
||||
}).then(offer => {
|
||||
pc.createOffer().then(offer => {
|
||||
pc.setLocalDescription(offer);
|
||||
});
|
||||
</script>
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@
|
||||
|
||||
if (ev.candidate !== null) {
|
||||
ws.send(JSON.stringify({
|
||||
type: 'webrtc/candidate', value: ev.candidate.toJSON().candidate
|
||||
type: 'webrtc/candidate', value: ev.candidate.candidate
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user