Skip to content
Permalink
Browse files

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
  • Loading branch information...
giongto35 committed May 30, 2019
1 parent a9b4e31 commit fcd30ac14f60457591c56474d8692f09c2076310
Showing with 36 additions and 18 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 README.md
  3. +3 −0 config/config.go
  4. +21 −5 overlord/handlers.go
  5. +1 −0 static/game.html
  6. +1 −0 static/js/global.js
  7. +8 −12 static/js/ws.js
@@ -48,4 +48,5 @@ Temporary Items
### Production
DockerfileProd
key.json
run_prod_docker.sh
prod/
@@ -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.

![screenshot](document/img/landing-page.gif)

@@ -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
@@ -74,6 +74,7 @@

<script>
DEBUG = true;
STUNTURN = {{.STUNTURN}};
</script>

<script src="/static/js/jquery-3.3.1.min.js"></script>
@@ -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"}]
@@ -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;

0 comments on commit fcd30ac

Please sign in to comment.
You can’t perform that action at this time.