Turn call an OK

master
Bel LaPointe 2020-05-13 14:44:04 -06:00
parent e1ee647767
commit 5418ef2b37
2 changed files with 35 additions and 39 deletions

View File

@ -1,20 +1,4 @@
class Config {
static iceConfig = {
'iceServers': [
{'urls': 'stun:stun.stunprotocol.org:3478'},
{'urls': 'stun:stun.l.google.com:19302'},
/*
{
'urls': 'turn:turn.home.blapointe.com:5349',
'credentialType': 'password',
'username': 'user',
'credential': 'pass',
},
*/
],
'iceTransportPolicy': 'all', // all for p2p, relay for turn
};
static getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
@ -56,6 +40,17 @@ class Config {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
}
Config.iceConfig = {
'iceServers': [
{
'urls': 'turn:turn.home.blapointe.com:5349',
'credentialType': 'password',
'username': 'user',
'credential': 'pass',
},
],
'iceTransportPolicy': 'relay',
};
class View {
static write(foo, color) {
@ -101,7 +96,7 @@ class Preview {
}
class Server {
static server;
server = null;
constructor(address, cb) {
Server.server = new WebSocket(address);
@ -110,8 +105,6 @@ class Server {
}
class Peer {
peer;
constructor(stream) {
this.peer = new RTCPeerConnection(Config.iceConfig);
this.peer.onicecandidate = this.gotIceCandidate;
@ -135,11 +128,9 @@ class Peer {
.catch(View.error);
}
}
Peer.peer = null;
class Entropy {
static local = null;
static peer = null;
static pageReady() {
Entropy.local = Local.build("video");
}
@ -152,7 +143,7 @@ class Entropy {
}
static gotMessageFromServer(message) {
if(!Entropy.peer.peer) Entropy.start(false);
if(!Entropy.peer || !Entropy.peer.peer) Entropy.start(false);
var signal = JSON.parse(message.data);
@ -185,6 +176,8 @@ class Entropy {
.catch(View.error);
}
}
Entropy.local = null;
Entropy.peer = null;
class Local {
stream = null;
@ -250,7 +243,11 @@ window.console = console;
function pageReady() {
Config.getUUID();
new Server('wss://' + window.location.hostname + '/abc', Entropy.gotMessageFromServer);
var host = window.location.hostname;
if (window.location.port) {
host += ":" + window.location.port;
}
new Server('wss://' + host + '/abc', Entropy.gotMessageFromServer);
Entropy.pageReady();
}

View File

@ -30,11 +30,10 @@ func New() *Server {
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Println("base", path.Base(r.URL.Path))
if !s.Authorize(w, r) {
return
}
log.Println("ext", path.Ext(r.URL.Path))
if path.Ext(r.URL.Path) != "" {
s.fs.ServeHTTP(w, r)
} else if _, err := os.Stat(path.Join(config().GetString("d"), r.URL.Path[1:])); os.IsNotExist(err) {