mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-08-03 07:13:08 +00:00
Update pion package
This commit is contained in:
parent
ff89a4872a
commit
1e14a49822
5 changed files with 19 additions and 19 deletions
|
|
@ -8,7 +8,7 @@ WORKDIR /go/src/github.com/giongto35/cloud-game
|
|||
RUN apt-get update
|
||||
#RUN apt-get install portaudio19-dev -y
|
||||
RUN apt-get install libvpx-dev -y
|
||||
RUN go get github.com/pions/webrtc
|
||||
RUN go get github.com/pion/webrtc
|
||||
#RUN go get github.com/gordonklaus/portaudio
|
||||
RUN go get github.com/gorilla/mux
|
||||
RUN go get github.com/gorilla/websocket
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ textarea {
|
|||
|
||||
<br/><br/>
|
||||
|
||||
<body scroll="no" style="overflow: hidden">
|
||||
<div id="remoteVideos" ></div> <br />
|
||||
|
||||
<h3>Instruction</h3>
|
||||
|
|
@ -98,8 +99,9 @@ pc.ontrack = function (event) {
|
|||
var el = document.createElement(event.track.kind)
|
||||
el.srcObject = event.streams[0]
|
||||
el.autoplay = true
|
||||
// el.controls = true
|
||||
// el.poster = new URL("https://orig00.deviantart.net/cdcd/f/2017/276/a/a/october_2nd___gameboy_poltergeist_by_wanyo-dbpdmnd.gif");
|
||||
el.width = 800;
|
||||
el.height = 600;
|
||||
el.poster = new URL("https://orig00.deviantart.net/cdcd/f/2017/276/a/a/october_2nd___gameboy_poltergeist_by_wanyo-dbpdmnd.gif");
|
||||
|
||||
document.getElementById('remoteVideos').appendChild(el)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ textarea {
|
|||
|
||||
<br/><br/>
|
||||
|
||||
<div id="remoteVideos" ></div> <br />
|
||||
<body scroll="no" style="overflow: hidden">
|
||||
<div id="remoteVideos"></div> <br />
|
||||
|
||||
<h3>Instruction</h3>
|
||||
<div>
|
||||
|
|
@ -137,6 +138,8 @@ window.startGame = () => {
|
|||
// console.log(event.streams);
|
||||
el.srcObject = event.streams[0];
|
||||
el.autoplay = true;
|
||||
el.width = 800;
|
||||
el.height = 600;
|
||||
el.poster = new URL("https://orig00.deviantart.net/cdcd/f/2017/276/a/a/october_2nd___gameboy_poltergeist_by_wanyo-dbpdmnd.gif");
|
||||
|
||||
document.getElementById('remoteVideos').appendChild(el)
|
||||
|
|
|
|||
17
main.go
17
main.go
|
|
@ -1,9 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
pionRTC "github.com/pions/webrtc"
|
||||
"os"
|
||||
|
||||
pionRTC "github.com/pion/webrtc"
|
||||
|
||||
"fmt"
|
||||
"image"
|
||||
"io/ioutil"
|
||||
|
|
@ -78,7 +79,7 @@ func ws(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
log.Println("New Connection")
|
||||
webRTC := webrtc.NewWebRTC()
|
||||
|
||||
|
||||
// streaming game
|
||||
|
||||
// start new games and webrtc stuff?
|
||||
|
|
@ -133,7 +134,7 @@ func ws(w http.ResponseWriter, r *http.Request) {
|
|||
log.Println("Starting game")
|
||||
imageChannel := make(chan *image.RGBA, 100)
|
||||
go screenshotLoop(imageChannel, webRTC)
|
||||
go startGame("games/" + gameName, imageChannel, webRTC.InputChannel, webRTC)
|
||||
go startGame("games/"+gameName, imageChannel, webRTC.InputChannel, webRTC)
|
||||
res.ID = "start"
|
||||
isDone = true
|
||||
}
|
||||
|
|
@ -152,15 +153,11 @@ func ws(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
type SessionPacket struct {
|
||||
Game string `json:"game"`
|
||||
SDP string `json:"sdp"`
|
||||
Game string `json:"game"`
|
||||
SDP string `json:"sdp"`
|
||||
}
|
||||
|
||||
|
||||
func postSession(w http.ResponseWriter, r *http.Request) {
|
||||
bs, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
|
|
@ -185,7 +182,7 @@ func postSession(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
imageChannel := make(chan *image.RGBA, 100)
|
||||
go screenshotLoop(imageChannel, webRTC)
|
||||
go startGame("games/" + postPacket.Game, imageChannel, webRTC.InputChannel, webRTC)
|
||||
go startGame("games/"+postPacket.Game, imageChannel, webRTC.InputChannel, webRTC)
|
||||
|
||||
w.Write([]byte(localSession))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import (
|
|||
"time"
|
||||
|
||||
vpxEncoder "github.com/giongto35/cloud-game/vpx-encoder"
|
||||
"github.com/pions/webrtc"
|
||||
"github.com/pions/webrtc/pkg/media"
|
||||
"github.com/pion/webrtc"
|
||||
"github.com/pion/webrtc/pkg/media"
|
||||
)
|
||||
|
||||
var config = webrtc.Configuration{ICEServers: []webrtc.ICEServer{{URLs: []string{"stun:stun.l.google.com:19302"}}}}
|
||||
|
|
@ -104,7 +104,7 @@ type WebRTC struct {
|
|||
connection *webrtc.PeerConnection
|
||||
encoder *vpxEncoder.VpxEncoder
|
||||
isConnected bool
|
||||
isClosed bool
|
||||
isClosed bool
|
||||
// for yuvI420 image
|
||||
ImageChannel chan []byte
|
||||
InputChannel chan int
|
||||
|
|
@ -147,7 +147,6 @@ func (w *WebRTC) StartClient(remoteSession string, width, height int) (string, e
|
|||
return "", err
|
||||
}
|
||||
|
||||
|
||||
// WebRTC state callback
|
||||
w.connection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||
fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String())
|
||||
|
|
@ -169,7 +168,6 @@ func (w *WebRTC) StartClient(remoteSession string, width, height int) (string, e
|
|||
fmt.Println(iceCandidate)
|
||||
})
|
||||
|
||||
|
||||
// Data channel callback
|
||||
w.connection.OnDataChannel(func(d *webrtc.DataChannel) {
|
||||
fmt.Printf("New DataChannel %s %d\n", d.Label(), d.ID())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue