mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-19 09:34:12 +00:00
Update turn by location (#46)
* Config STUN by server * Move ice timeout log under condition * STUN TURN defaut when give empty string * Update git ignore to ignore prod file * Update readme
This commit is contained in:
parent
d57e500818
commit
2d3daa2ade
7 changed files with 36 additions and 18 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -48,4 +48,5 @@ Temporary Items
|
|||
### Production
|
||||
DockerfileProd
|
||||
key.json
|
||||
run_prod_docker.sh
|
||||
prod/
|
||||
|
|
|
|||
2
README.md
vendored
2
README.md
vendored
|
|
@ -12,7 +12,7 @@ Klog is an open source Cloud Gaming Service building on [WebRTC](https://github.
|
|||
|
||||
Klog aims to bring the most convenient gaming experience to gamer. You can play any games on your browser directly, which is fully compatible on multi-platform like Desktop, Android, IOS. This flexibility enables modern online gaming experience to retro games starting with NES in this current release.
|
||||
|
||||
Note: The current state of POGO are not optimized for production. The service will still experience lag under heavy traffic. You can try hosting your own service following the instruction in the next session.
|
||||
Note: The current state of Klog are not optimized for production. The service will still experience lag under heavy traffic. You can try hosting your own service following the instruction in the next session.
|
||||
|
||||

|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,14 @@ import (
|
|||
)
|
||||
|
||||
const defaultoverlord = "ws://localhost:9000/wso"
|
||||
const DefaultSTUNTURN = `[{"urls":"stun:stun-turn.webgame2d.com:3478"},{"urls":"turn:stun-turn.webgame2d.com:3478","username":"root","credential":"root"}]`
|
||||
|
||||
var IsDebug = flag.Bool("debug", false, "Is game running in debug mode?")
|
||||
var OverlordHost = flag.String("overlordhost", defaultoverlord, "Specify the path for overlord. If the flag is `overlord`, the server will be run as overlord")
|
||||
var Port = flag.String("port", "8000", "Port of the game")
|
||||
var IsMonitor = flag.Bool("monitor", false, "Turn on monitor")
|
||||
var FrontendSTUNTURN = flag.String("stunturn", DefaultSTUNTURN, "Frontend STUN TURN servers")
|
||||
|
||||
var Width = 256
|
||||
var Height = 240
|
||||
var WSWait = 20 * time.Second
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ package overlord
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"html/template"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
|
||||
"github.com/giongto35/cloud-game/config"
|
||||
"github.com/giongto35/cloud-game/cws"
|
||||
"github.com/giongto35/cloud-game/overlord/gamelist"
|
||||
"github.com/gofrs/uuid"
|
||||
|
|
@ -16,7 +17,6 @@ import (
|
|||
|
||||
const (
|
||||
gameboyIndex = "./static/game.html"
|
||||
debugIndex = "./static/game.html"
|
||||
gamePath = "games"
|
||||
)
|
||||
|
||||
|
|
@ -38,15 +38,31 @@ func NewServer() *Server {
|
|||
}
|
||||
}
|
||||
|
||||
type RenderData struct {
|
||||
STUNTURN string
|
||||
}
|
||||
|
||||
// GetWeb returns web frontend
|
||||
func (o *Server) GetWeb(w http.ResponseWriter, r *http.Request) {
|
||||
indexFN := gameboyIndex
|
||||
stunturn := *config.FrontendSTUNTURN
|
||||
if stunturn == "" {
|
||||
stunturn = config.DefaultSTUNTURN
|
||||
}
|
||||
data := RenderData{
|
||||
STUNTURN: stunturn,
|
||||
}
|
||||
|
||||
bs, err := ioutil.ReadFile(indexFN)
|
||||
tmpl, err := template.ParseFiles(gameboyIndex)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
w.Write(bs)
|
||||
|
||||
//bs, err := ioutil.ReadFile(indexFN)
|
||||
//if err != nil {
|
||||
//log.Fatal(err)
|
||||
//}
|
||||
//w.Write(bs)
|
||||
tmpl.Execute(w, data)
|
||||
}
|
||||
|
||||
// WSO handles all connections from a new worker to overlord
|
||||
|
|
|
|||
1
static/game.html
vendored
1
static/game.html
vendored
|
|
@ -74,6 +74,7 @@
|
|||
|
||||
<script>
|
||||
DEBUG = true;
|
||||
STUNTURN = {{.STUNTURN}};
|
||||
</script>
|
||||
|
||||
<script src="/static/js/jquery-3.3.1.min.js"></script>
|
||||
|
|
|
|||
1
static/js/global.js
vendored
1
static/js/global.js
vendored
|
|
@ -61,3 +61,4 @@ let isLayoutSwitched = false;
|
|||
var gameReady = false;
|
||||
var iceSuccess = true;
|
||||
var iceSent = false; // TODO: set to false in some init event
|
||||
var defaultICE = [{urls: "stun:stun.l.google.com:19302"}]
|
||||
|
|
|
|||
20
static/js/ws.js
vendored
20
static/js/ws.js
vendored
|
|
@ -96,17 +96,13 @@ function sendPing() {
|
|||
|
||||
function startWebRTC() {
|
||||
// webrtc
|
||||
pc = new RTCPeerConnection({iceServers: [{
|
||||
urls: 'stun:stun-turn.webgame2d.com:3478'
|
||||
},
|
||||
{
|
||||
urls: 'stun:159.65.141.209:3478'
|
||||
},
|
||||
{
|
||||
urls: "turn:stun-turn.webgame2d.com:3478",
|
||||
username: "root",
|
||||
credential: "root"
|
||||
}]})
|
||||
var iceservers = [];
|
||||
if (STUNTURN == "") {
|
||||
iceservers = defaultICE
|
||||
} else {
|
||||
iceservers = JSON.parse(STUNTURN);
|
||||
}
|
||||
pc = new RTCPeerConnection({iceServers: iceservers });
|
||||
|
||||
// input channel, ordered + reliable, id 0
|
||||
inputChannel = pc.createDataChannel('a', {
|
||||
|
|
@ -221,8 +217,8 @@ function startWebRTC() {
|
|||
// TODO: tidy up, setTimeout multiple time now
|
||||
// timeout
|
||||
setTimeout(() => {
|
||||
log("Ice gathering timeout, send anyway")
|
||||
if (!iceSent) {
|
||||
log("Ice gathering timeout, send anyway")
|
||||
session = btoa(JSON.stringify(pc.localDescription));
|
||||
conn.send(JSON.stringify({"id": "initwebrtc", "data": session, "packet_id": curPacketID}));
|
||||
iceSent = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue