mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-21 09:08:57 +00:00
remove crashed games, finish game select, fix dockerfile
This commit is contained in:
parent
1048846266
commit
bccdee4eb0
11 changed files with 92 additions and 75 deletions
|
|
@ -1,8 +1,8 @@
|
|||
From golang:1.12
|
||||
|
||||
RUN mkdir -p /go/src/github.com/giongto35/game-online
|
||||
COPY . /go/src/github.com/giongto35/game-online/
|
||||
WORKDIR /go/src/github.com/giongto35/game-online
|
||||
RUN mkdir -p /go/src/github.com/giongto35/cloud-game
|
||||
COPY . /go/src/github.com/giongto35/cloud-game/
|
||||
WORKDIR /go/src/github.com/giongto35/cloud-game
|
||||
|
||||
# Install server dependencies
|
||||
RUN apt-get update
|
||||
|
|
@ -11,6 +11,7 @@ RUN apt-get install libvpx-dev -y
|
|||
RUN go get github.com/pions/webrtc
|
||||
#RUN go get github.com/gordonklaus/portaudio
|
||||
RUN go get github.com/gorilla/mux
|
||||
RUN go install github.com/giongto35/game-online
|
||||
RUN go get github.com/gorilla/websocket
|
||||
RUN go install github.com/giongto35/cloud-game
|
||||
|
||||
EXPOSE 8000
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
140
index.html
140
index.html
|
|
@ -11,9 +11,7 @@ textarea {
|
|||
<option value="Contra.nes">Contra.nes</option>
|
||||
<option value="Kirby's Adventure.nes">Kirby's Adventure.nes</option>
|
||||
<option value="Mega Man 2.nes">Mega Man 2.nes</option>
|
||||
<option value="Mega Man.nes">Mega Man.nes</option>
|
||||
<option value="Metal Gear.nes">Metal Gear.nes</option>
|
||||
<option value="Mike Tyson.nes">Mike Tyson.nes</option>
|
||||
<option value="Mortal Kombat 4.nes">Mortal Kombat 4.nes</option>
|
||||
<option value="Super Mario Bros 2.nes">Super Mario Bros 2.nes</option>
|
||||
<option value="Super Mario Bros 3.nes">Super Mario Bros 3.nes</option>
|
||||
|
|
@ -26,9 +24,11 @@ textarea {
|
|||
<!--button id="playGame" onclick="window.startSession()" disabled>Play Mario</button-->
|
||||
<button id="play" onclick="window.startGame()">Play</button>
|
||||
|
||||
<br/>
|
||||
<br/><br/>
|
||||
|
||||
<div id="remoteVideos" ></div> <br />
|
||||
|
||||
<h3>Instruction</h3>
|
||||
<div>
|
||||
Use Up, Down, Left, Right to Move <br />
|
||||
Z to jump (A) <br />
|
||||
|
|
@ -37,13 +37,13 @@ textarea {
|
|||
V is select button <br />
|
||||
|
||||
Fullscreen media for better gaming experience<br />
|
||||
</div>
|
||||
</div><br>
|
||||
|
||||
|
||||
<div id="div"></div>
|
||||
<h3>Log:</h3>
|
||||
<pre id="div"></pre>
|
||||
|
||||
<div>
|
||||
Refresh to retry
|
||||
<u><i>Refresh to retry</i></u>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
|
|
@ -93,6 +93,16 @@ function postSession(session) {
|
|||
// web socket
|
||||
|
||||
window.startGame = () => {
|
||||
// clear
|
||||
endInput();
|
||||
document.getElementById('div').innerHTML = "";
|
||||
aa = document.getElementsByTagName("video");
|
||||
for (i = 0; i < aa.length ; ++i) {
|
||||
aa[i].remove();
|
||||
}
|
||||
// end clear
|
||||
|
||||
|
||||
conn = new WebSocket(`ws://${location.host}/ws`);
|
||||
|
||||
conn.onopen = () => {
|
||||
|
|
@ -122,29 +132,73 @@ window.startGame = () => {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// webrtc
|
||||
pc = new RTCPeerConnection({iceServers: [{urls: 'stun:stun.l.google.com:19302'}]})
|
||||
// input channel
|
||||
inputChannel = pc.createDataChannel('foo')
|
||||
inputChannel.onclose = () => {
|
||||
log('inputChannel has closed');
|
||||
}
|
||||
|
||||
inputChannel.onopen = () => {
|
||||
log('inputChannel has opened');
|
||||
}
|
||||
|
||||
inputChannel.onmessage = e => {
|
||||
log(`Message from DataChannel '${inputChannel.label}' payload '${e.data}'`);
|
||||
}
|
||||
|
||||
|
||||
pc.oniceconnectionstatechange = e => {
|
||||
log(`iceConnectionState: ${pc.iceConnectionState}`);
|
||||
|
||||
if (pc.iceConnectionState === "connected") {
|
||||
conn.send(JSON.stringify({"id": "start", "data": ""}));
|
||||
startInput();
|
||||
}
|
||||
else if (pc.iceConnectionState === "disconnected") {
|
||||
// else { // not sure about this =]
|
||||
endInput();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// stream channel
|
||||
pc.ontrack = function (event) {
|
||||
var el = document.createElement(event.track.kind)
|
||||
el.srcObject = event.streams[0]
|
||||
el.autoplay = true
|
||||
el.controls = true
|
||||
|
||||
document.getElementById('remoteVideos').appendChild(el)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// candidate packet from STUN
|
||||
pc.onicecandidate = event => {
|
||||
if (event.candidate === null) {
|
||||
// var session = btoa(JSON.stringify(pc.localDescription));
|
||||
// localSessionDescription = session;
|
||||
// postSession(session)
|
||||
} else {
|
||||
console.log(JSON.stringify(event.candidate));
|
||||
// conn.send(JSON.stringify({"id": "candidate", "data": JSON.stringify(event.candidate)}));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// webrtc
|
||||
let pc = new RTCPeerConnection({iceServers: [{urls: 'stun:stun.l.google.com:19302'}]})
|
||||
|
||||
var localSessionDescription = ""
|
||||
var remoteSessionDescription = ""
|
||||
var pc, inputChannel;
|
||||
var localSessionDescription = "";
|
||||
var remoteSessionDescription = "";
|
||||
var conn;
|
||||
|
||||
|
||||
// input channel
|
||||
let inputChannel = pc.createDataChannel('foo')
|
||||
inputChannel.onclose = () => {
|
||||
log('inputChannel has closed');
|
||||
}
|
||||
|
||||
inputChannel.onopen = () => {
|
||||
log('inputChannel has opened');
|
||||
}
|
||||
|
||||
inputChannel.onmessage = e => {
|
||||
log(`Message from DataChannel '${inputChannel.label}' payload '${e.data}'`);
|
||||
}
|
||||
|
||||
|
||||
// Input handler
|
||||
|
|
@ -197,6 +251,7 @@ document.body.onkeyup = function(e){
|
|||
};
|
||||
|
||||
var timer = null;
|
||||
|
||||
function sendInput() {
|
||||
// prepare key
|
||||
/*
|
||||
|
|
@ -239,45 +294,6 @@ function endInput() {
|
|||
timer = null;
|
||||
}
|
||||
|
||||
pc.oniceconnectionstatechange = e => {
|
||||
log(`iceConnectionState: ${pc.iceConnectionState}`);
|
||||
|
||||
if (pc.iceConnectionState === "connected") {
|
||||
conn.send(JSON.stringify({"id": "start", "data": ""}));
|
||||
startInput();
|
||||
}
|
||||
else if (pc.iceConnectionState === "disconnected") {
|
||||
// else { // not sure about this =]
|
||||
endInput();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// stream channel
|
||||
pc.ontrack = function (event) {
|
||||
var el = document.createElement(event.track.kind)
|
||||
el.srcObject = event.streams[0]
|
||||
el.autoplay = true
|
||||
el.controls = true
|
||||
|
||||
document.getElementById('remoteVideos').appendChild(el)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// candidate packet from STUN
|
||||
pc.onicecandidate = event => {
|
||||
if (event.candidate === null) {
|
||||
// var session = btoa(JSON.stringify(pc.localDescription));
|
||||
// localSessionDescription = session;
|
||||
// postSession(session)
|
||||
} else {
|
||||
console.log(JSON.stringify(event.candidate));
|
||||
// conn.send(JSON.stringify({"id": "candidate", "data": JSON.stringify(event.candidate)}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function startWebRTC() {
|
||||
// create SDP
|
||||
|
|
|
|||
6
main.go
6
main.go
|
|
@ -10,9 +10,9 @@ import (
|
|||
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/game-online/ui"
|
||||
"github.com/giongto35/game-online/util"
|
||||
"github.com/giongto35/game-online/webrtc"
|
||||
"github.com/giongto35/cloud-game/ui"
|
||||
"github.com/giongto35/cloud-game/util"
|
||||
"github.com/giongto35/cloud-game/webrtc"
|
||||
|
||||
// "github.com/gorilla/mux"
|
||||
"github.com/gorilla/websocket"
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import (
|
|||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/game-online/nes"
|
||||
"github.com/giongto35/game-online/webrtc"
|
||||
"github.com/giongto35/cloud-game/nes"
|
||||
"github.com/giongto35/cloud-game/webrtc"
|
||||
)
|
||||
|
||||
type View interface {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/game-online/nes"
|
||||
"github.com/giongto35/cloud-game/nes"
|
||||
)
|
||||
|
||||
const padding = 0
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"runtime"
|
||||
|
||||
// "github.com/gordonklaus/portaudio"
|
||||
"github.com/giongto35/game-online/webrtc"
|
||||
"github.com/giongto35/cloud-game/webrtc"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"os/user"
|
||||
"path"
|
||||
|
||||
"github.com/giongto35/game-online/nes"
|
||||
"github.com/giongto35/cloud-game/nes"
|
||||
)
|
||||
|
||||
var homeDir string
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
vpxEncoder "github.com/giongto35/game-online/vpx-encoder"
|
||||
vpxEncoder "github.com/giongto35/cloud-game/vpx-encoder"
|
||||
"github.com/pions/webrtc"
|
||||
"github.com/pions/webrtc/pkg/media"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue