summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-04-16 21:14:31 -0400
committerGitHub <noreply@github.com>2017-04-16 21:14:31 -0400
commit74ffb6f98f7ee8b4e61743919ab20460c57ad4da (patch)
treead840112478819775c5c2acec88f508cebc28713 /api4
parentc7f26bb1103e75c451eba3b720ac41097c427fbc (diff)
downloadchat-74ffb6f98f7ee8b4e61743919ab20460c57ad4da.tar.gz
chat-74ffb6f98f7ee8b4e61743919ab20460c57ad4da.tar.bz2
chat-74ffb6f98f7ee8b4e61743919ab20460c57ad4da.zip
Implement GET /webrtc/token endpoint for APIv4 (#6046)
Diffstat (limited to 'api4')
-rw-r--r--api4/api.go1
-rw-r--r--api4/webrtc.go29
-rw-r--r--api4/webrtc_test.go29
3 files changed, 59 insertions, 0 deletions
diff --git a/api4/api.go b/api4/api.go
index 45581525e..a91fb80b5 100644
--- a/api4/api.go
+++ b/api4/api.go
@@ -178,6 +178,7 @@ func InitApi(full bool) {
InitWebSocket()
InitEmoji()
InitReaction()
+ InitWebrtc()
app.Srv.Router.Handle("/api/v4/{anything:.*}", http.HandlerFunc(Handle404))
diff --git a/api4/webrtc.go b/api4/webrtc.go
new file mode 100644
index 000000000..81a1599b2
--- /dev/null
+++ b/api4/webrtc.go
@@ -0,0 +1,29 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api4
+
+import (
+ "net/http"
+
+ l4g "github.com/alecthomas/log4go"
+ "github.com/mattermost/platform/app"
+ "github.com/mattermost/platform/utils"
+)
+
+func InitWebrtc() {
+ l4g.Debug(utils.T("api.webrtc.init.debug"))
+
+ BaseRoutes.Webrtc.Handle("/token", ApiSessionRequired(webrtcToken)).Methods("GET")
+}
+
+func webrtcToken(c *Context, w http.ResponseWriter, r *http.Request) {
+ result, err := app.GetWebrtcInfoForSession(c.Session.Id)
+
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ w.Write([]byte(result.ToJson()))
+}
diff --git a/api4/webrtc_test.go b/api4/webrtc_test.go
new file mode 100644
index 000000000..806118f76
--- /dev/null
+++ b/api4/webrtc_test.go
@@ -0,0 +1,29 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api4
+
+import (
+ "testing"
+
+ "github.com/mattermost/platform/utils"
+)
+
+func TestGetWebrtcToken(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ enableWebrtc := *utils.Cfg.WebrtcSettings.Enable
+ defer func() {
+ *utils.Cfg.WebrtcSettings.Enable = enableWebrtc
+ }()
+ *utils.Cfg.WebrtcSettings.Enable = false
+
+ _, resp := Client.GetWebrtcToken()
+ CheckNotImplementedStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.GetWebrtcToken()
+ CheckUnauthorizedStatus(t, resp)
+}