mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-24 02:27:32 +00:00
remove isclose
This commit is contained in:
parent
ae6c26b4c8
commit
fb7082c21d
4 changed files with 8 additions and 13 deletions
|
|
@ -297,8 +297,11 @@ function endInput() {
|
|||
|
||||
|
||||
function startWebRTC() {
|
||||
// receiver only tracks
|
||||
pc.addTransceiver('video', {'direction': 'recvonly'});
|
||||
|
||||
// create SDP
|
||||
pc.createOffer({offerToReceiveVideo: true, offerToReceiveAudio: true}).then(d => {
|
||||
pc.createOffer({offerToReceiveVideo: true, offerToReceiveAudio: false}).then(d => {
|
||||
pc.setLocalDescription(d, () => {
|
||||
// send to ws
|
||||
session = btoa(JSON.stringify(pc.localDescription));
|
||||
|
|
|
|||
7
main.go
7
main.go
|
|
@ -174,15 +174,12 @@ func postSession(w http.ResponseWriter, r *http.Request) {
|
|||
// func screenshotLoop(imageChannel chan *image.RGBA) {
|
||||
func screenshotLoop(imageChannel chan *image.RGBA, webRTC *webrtc.WebRTC) {
|
||||
for image := range imageChannel {
|
||||
// Client stopped
|
||||
if webRTC.IsClosed() {
|
||||
break
|
||||
}
|
||||
|
||||
// encode frame
|
||||
if webRTC.IsConnected() {
|
||||
yuv := util.RgbaToYuv(image)
|
||||
webRTC.ImageChannel <- yuv
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func (d *Director) Start(paths []string) {
|
|||
func (d *Director) Run() {
|
||||
for {
|
||||
// quit game
|
||||
if d.webRTC.IsClosed() {
|
||||
if !d.webRTC.IsConnected() {
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,6 @@ type WebRTC struct {
|
|||
connection *webrtc.PeerConnection
|
||||
encoder *vpxEncoder.VpxEncoder
|
||||
isConnected bool
|
||||
isClosed bool
|
||||
// for yuvI420 image
|
||||
ImageChannel chan []byte
|
||||
InputChannel chan int
|
||||
|
|
@ -226,7 +225,6 @@ func (w *WebRTC) StopClient() {
|
|||
w.connection.Close()
|
||||
}
|
||||
w.connection = nil
|
||||
w.isClosed = true
|
||||
}
|
||||
|
||||
// IsConnected comment
|
||||
|
|
@ -234,9 +232,6 @@ func (w *WebRTC) IsConnected() bool {
|
|||
return w.isConnected
|
||||
}
|
||||
|
||||
func (w *WebRTC) IsClosed() bool {
|
||||
return w.isClosed
|
||||
}
|
||||
|
||||
func (w *WebRTC) startStreaming(vp8Track *webrtc.Track) {
|
||||
fmt.Println("Start streaming")
|
||||
|
|
@ -252,7 +247,7 @@ func (w *WebRTC) startStreaming(vp8Track *webrtc.Track) {
|
|||
|
||||
// receive frame buffer
|
||||
go func() {
|
||||
for i := 0; w.isConnected; i++ {
|
||||
for w.isConnected {
|
||||
bs := <-w.encoder.Output
|
||||
vp8Track.WriteSample(media.Sample{Data: bs, Samples: 1})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue