Implement GET /webrtc/token endpoint for APIv4 (#6046)

Этот коммит содержится в:
Joram Wilander
2017-04-16 21:14:31 -04:00
коммит произвёл GitHub
родитель c7f26bb110
Коммит 74ffb6f98f
8 изменённых файлов: 215 добавлений и 69 удалений

Просмотреть файл

@@ -2286,6 +2286,19 @@ func (c *Client4) UpdateUserStatus(userId string, userStatus *Status) (*Status,
}
}
// Webrtc Section
// GetWebrtcToken returns a valid token, stun server and turn server with credentials to
// use with the Mattermost WebRTC service.
func (c *Client4) GetWebrtcToken() (*WebrtcInfoResponse, *Response) {
if r, err := c.DoApiGet("/webrtc/token", ""); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return WebrtcInfoResponseFromJson(r.Body), BuildResponse(r)
}
}
// Emoji Section
// CreateEmoji will save an emoji to the server if the current user has permission

Просмотреть файл

@@ -1,3 +1,6 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
@@ -5,6 +8,15 @@ import (
"io"
)
type WebrtcInfoResponse struct {
Token string `json:"token"`
GatewayUrl string `json:"gateway_url"`
StunUri string `json:"stun_uri,omitempty"`
TurnUri string `json:"turn_uri,omitempty"`
TurnPassword string `json:"turn_password,omitempty"`
TurnUsername string `json:"turn_username,omitempty"`
}
type GatewayResponse struct {
Status string `json:"janus"`
}
@@ -19,3 +31,23 @@ func GatewayResponseFromJson(data io.Reader) *GatewayResponse {
return nil
}
}
func (o *WebrtcInfoResponse) ToJson() string {
b, err := json.Marshal(o)
if err != nil {
return ""
} else {
return string(b)
}
}
func WebrtcInfoResponseFromJson(data io.Reader) *WebrtcInfoResponse {
decoder := json.NewDecoder(data)
var o WebrtcInfoResponse
err := decoder.Decode(&o)
if err == nil {
return &o
} else {
return nil
}
}

19
model/webrtc_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,19 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"strings"
"testing"
)
func TestWebrtcJson(t *testing.T) {
o := WebrtcInfoResponse{Token: NewId(), GatewayUrl: NewId()}
json := o.ToJson()
ro := WebrtcInfoResponseFromJson(strings.NewReader(json))
if o.Token != ro.Token {
t.Fatal("Tokens do not match")
}
}