Turn call an OK
parent
e1ee647767
commit
5418ef2b37
|
|
@ -1,20 +1,4 @@
|
||||||
class Config {
|
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) {
|
static getCookie(cname) {
|
||||||
var name = cname + "=";
|
var name = cname + "=";
|
||||||
var decodedCookie = decodeURIComponent(document.cookie);
|
var decodedCookie = decodeURIComponent(document.cookie);
|
||||||
|
|
@ -56,6 +40,17 @@ class Config {
|
||||||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
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 {
|
class View {
|
||||||
static write(foo, color) {
|
static write(foo, color) {
|
||||||
|
|
@ -101,7 +96,7 @@ class Preview {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
static server;
|
server = null;
|
||||||
|
|
||||||
constructor(address, cb) {
|
constructor(address, cb) {
|
||||||
Server.server = new WebSocket(address);
|
Server.server = new WebSocket(address);
|
||||||
|
|
@ -110,8 +105,6 @@ class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Peer {
|
class Peer {
|
||||||
peer;
|
|
||||||
|
|
||||||
constructor(stream) {
|
constructor(stream) {
|
||||||
this.peer = new RTCPeerConnection(Config.iceConfig);
|
this.peer = new RTCPeerConnection(Config.iceConfig);
|
||||||
this.peer.onicecandidate = this.gotIceCandidate;
|
this.peer.onicecandidate = this.gotIceCandidate;
|
||||||
|
|
@ -135,11 +128,9 @@ class Peer {
|
||||||
.catch(View.error);
|
.catch(View.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Peer.peer = null;
|
||||||
|
|
||||||
class Entropy {
|
class Entropy {
|
||||||
static local = null;
|
|
||||||
static peer = null;
|
|
||||||
|
|
||||||
static pageReady() {
|
static pageReady() {
|
||||||
Entropy.local = Local.build("video");
|
Entropy.local = Local.build("video");
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +143,7 @@ class Entropy {
|
||||||
}
|
}
|
||||||
|
|
||||||
static gotMessageFromServer(message) {
|
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);
|
var signal = JSON.parse(message.data);
|
||||||
|
|
||||||
|
|
@ -185,6 +176,8 @@ class Entropy {
|
||||||
.catch(View.error);
|
.catch(View.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Entropy.local = null;
|
||||||
|
Entropy.peer = null;
|
||||||
|
|
||||||
class Local {
|
class Local {
|
||||||
stream = null;
|
stream = null;
|
||||||
|
|
@ -250,7 +243,11 @@ window.console = console;
|
||||||
|
|
||||||
function pageReady() {
|
function pageReady() {
|
||||||
Config.getUUID();
|
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();
|
Entropy.pageReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,10 @@ func New() *Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Println("base", path.Base(r.URL.Path))
|
||||||
if !s.Authorize(w, r) {
|
if !s.Authorize(w, r) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("ext", path.Ext(r.URL.Path))
|
|
||||||
if path.Ext(r.URL.Path) != "" {
|
if path.Ext(r.URL.Path) != "" {
|
||||||
s.fs.ServeHTTP(w, r)
|
s.fs.ServeHTTP(w, r)
|
||||||
} else if _, err := os.Stat(path.Join(config().GetString("d"), r.URL.Path[1:])); os.IsNotExist(err) {
|
} else if _, err := os.Stat(path.Join(config().GetString("d"), r.URL.Path[1:])); os.IsNotExist(err) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue