Browse Source

Merge pull request #270 from longsleep/service-discovery-well-known

Implemented service discovery .well-known endpoint
pull/242/merge
Simon Eisenmann 9 years ago
parent
commit
faaebf25df
  1. 20
      doc/REST-API.txt
  2. 34
      src/app/spreed-webrtc-server/main.go

20
doc/REST-API.txt

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
Spreed WebRTC REST API v1.0.0
===============================================
(c)2014 struktur AG
(c)2016 struktur AG
The server provides a REST api end point to provide functionality outside the
the channeling API or without a established web socket connection.
@ -13,12 +13,26 @@ API or there was a problem while JSON encoding. @@ -13,12 +13,26 @@ API or there was a problem while JSON encoding.
Some end points of this API require a existing session from the channeling
API, incuding the private secret session ID. To get these it is sufficient
to connect to the channeling API with a websocket connection. The server
sends the session ID (Id) and secure session ID (Sid) within the Self
sends the session ID (Id) and secure session ID (Sid) within the Self
document after connection was established.
Available end points with request methods and content-type:
/.well-known/spreed-configuration
The well-known end points can be used to discover the base addresses for
other end points. Spreed WebRTC provides this for compatibility with
larger setups so clients using this can find the Spreed WebRTC end point.
GET application/x-www-form-urlencoded
No parameters.
Response 200:
{
"spreed-webrtc_endpoint": "http://localhost:8093"
}
/api/v1/config
The config end points returns the server configuration. As it is available
@ -178,4 +192,4 @@ https://github.com/strukturag/spreed-webrtc @@ -178,4 +192,4 @@ https://github.com/strukturag/spreed-webrtc
For questions, contact mailto:opensource@struktur.de.
(c)2014 struktur AG
(c)2016 struktur AG

34
src/app/spreed-webrtc-server/main.go

@ -25,6 +25,7 @@ import ( @@ -25,6 +25,7 @@ import (
"bytes"
"crypto/rand"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"github.com/gorilla/mux"
@ -92,6 +93,38 @@ func sandboxHandler(w http.ResponseWriter, r *http.Request) { @@ -92,6 +93,38 @@ func sandboxHandler(w http.ResponseWriter, r *http.Request) {
}
func wellKnownHandler(w http.ResponseWriter, r *http.Request) {
// Detect if the request was made with SSL.
ssl := r.TLS != nil
scheme := "http"
proto, ok := r.Header["X-Forwarded-Proto"]
if ok {
ssl = proto[0] == "https"
}
if ssl {
scheme = "https"
}
// Construct our URL.
url := url.URL{
Scheme: scheme,
Host: r.Host,
Path: strings.TrimSuffix(config.B, "/"),
}
doc := &map[string]string{
"spreed-webrtc_endpoint": url.String(),
}
data, err := json.MarshalIndent(doc, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
w.Header().Set("Content-Type", "application/json")
w.Write(data)
}
func makeImageHandler(buddyImages ImageCache, expires time.Duration) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@ -432,6 +465,7 @@ func runner(runtime phoenix.Runtime) error { @@ -432,6 +465,7 @@ func runner(runtime phoenix.Runtime) error {
r.Handle("/robots.txt", http.StripPrefix(config.B, http.FileServer(http.Dir(path.Join(rootFolder, "static")))))
r.Handle("/favicon.ico", http.StripPrefix(config.B, http.FileServer(http.Dir(path.Join(rootFolder, "static", "img")))))
r.Handle("/ws", makeWSHandler(statsManager, sessionManager, codec, channellingAPI))
r.HandleFunc("/.well-known/spreed-configuration", wellKnownHandler)
// Simple room handler.
r.HandleFunc("/{room}", httputils.MakeGzipHandler(roomHandler))

Loading…
Cancel
Save