PLT-3412 WebRTC Server side & System Console (#3706)
* WebRTC Server side * WebRTC System Console * Consistency on variable names * Add turn and stun uri validation
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
3b4c9d7588
Коммит
b180bb46e3
@@ -49,6 +49,8 @@ type Routes struct {
|
||||
|
||||
Emoji *mux.Router // 'api/v3/emoji'
|
||||
|
||||
Webrtc *mux.Router // 'api/v3/webrtc'
|
||||
|
||||
WebSocket *WebSocketRouter // websocket api
|
||||
}
|
||||
|
||||
@@ -77,6 +79,7 @@ func InitApi() {
|
||||
BaseRoutes.License = BaseRoutes.ApiRoot.PathPrefix("/license").Subrouter()
|
||||
BaseRoutes.Public = BaseRoutes.ApiRoot.PathPrefix("/public").Subrouter()
|
||||
BaseRoutes.Emoji = BaseRoutes.ApiRoot.PathPrefix("/emoji").Subrouter()
|
||||
BaseRoutes.Webrtc = BaseRoutes.ApiRoot.PathPrefix("/webrtc").Subrouter()
|
||||
|
||||
BaseRoutes.WebSocket = NewWebSocketRouter()
|
||||
|
||||
@@ -95,6 +98,7 @@ func InitApi() {
|
||||
InitLicense()
|
||||
InitEmoji()
|
||||
InitStatus()
|
||||
InitWebrtc()
|
||||
|
||||
// 404 on any api route before web.go has a chance to serve it
|
||||
Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404))
|
||||
|
||||
12
api/user.go
12
api/user.go
@@ -735,6 +735,10 @@ func RevokeSessionById(c *Context, sessionId string) {
|
||||
c.Err = result.Err
|
||||
}
|
||||
}
|
||||
|
||||
if webrtcInterface := einterfaces.GetWebrtcInterface(); webrtcInterface != nil {
|
||||
webrtcInterface.RevokeToken(session.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -757,6 +761,10 @@ func RevokeAllSession(c *Context, userId string) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if webrtcInterface := einterfaces.GetWebrtcInterface(); webrtcInterface != nil {
|
||||
webrtcInterface.RevokeToken(session.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -778,6 +786,10 @@ func RevokeAllSessionsNoContext(userId string) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
}
|
||||
|
||||
if webrtcInterface := einterfaces.GetWebrtcInterface(); webrtcInterface != nil {
|
||||
webrtcInterface.RevokeToken(session.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -169,6 +169,9 @@ func shouldSendEvent(webCon *WebConn, msg *model.WebSocketEvent) bool {
|
||||
} else if msg.Event == model.WEBSOCKET_EVENT_EPHEMERAL_MESSAGE {
|
||||
// For now, ephemeral messages are sent directly to individual users
|
||||
return false
|
||||
} else if msg.Event == model.WEBSOCKET_EVENT_WEBRTC {
|
||||
// No need to tell anyone that a webrtc event is going on
|
||||
return false
|
||||
}
|
||||
|
||||
// Only report events to users who are in the team for the event
|
||||
|
||||
51
api/webrtc.go
Обычный файл
51
api/webrtc.go
Обычный файл
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func InitWebrtc() {
|
||||
l4g.Debug(utils.T("api.webrtc.init.debug"))
|
||||
|
||||
BaseRoutes.Webrtc.Handle("/token", ApiUserRequired(webrtcToken)).Methods("POST")
|
||||
|
||||
BaseRoutes.WebSocket.Handle("webrtc", ApiWebSocketHandler(webrtcMessage))
|
||||
}
|
||||
|
||||
func webrtcToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
webrtcInterface := einterfaces.GetWebrtcInterface()
|
||||
|
||||
if webrtcInterface == nil {
|
||||
c.Err = model.NewLocAppError("webrtcToken", "api.webrtc.not_available.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
if result, err := webrtcInterface.Token(c.Session.Id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
w.Write([]byte(model.MapToJson(result)))
|
||||
}
|
||||
}
|
||||
|
||||
func webrtcMessage(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
|
||||
var ok bool
|
||||
var toUserId string
|
||||
if toUserId, ok = req.Data["to_user_id"].(string); !ok || len(toUserId) != 26 {
|
||||
return nil, NewInvalidWebSocketParamError(req.Action, "to_user_id")
|
||||
}
|
||||
|
||||
event := model.NewWebSocketEvent("", "", toUserId, model.WEBSOCKET_EVENT_WEBRTC)
|
||||
event.Data = req.Data
|
||||
go Publish(event)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
18
api/webrtc_test.go
Обычный файл
18
api/webrtc_test.go
Обычный файл
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package api
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestWebrtcToken(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
if _, err := th.BasicClient.GetWebrtcToken(); err != nil {
|
||||
if err.Id != "api.webrtc.not_available.app_error" {
|
||||
t.Fatal("Should have fail, webrtc not availble")
|
||||
}
|
||||
} else {
|
||||
t.Fatal("Should have fail, webrtc not availble")
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user