2017-04-12 08:27:57 -04:00
|
|
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
2017-03-28 04:58:19 -04:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package wsapi
|
|
|
|
|
|
|
|
|
|
import (
|
2017-09-06 23:05:10 -07:00
|
|
|
"github.com/mattermost/mattermost-server/model"
|
2017-03-28 04:58:19 -04:00
|
|
|
)
|
|
|
|
|
|
2017-09-27 11:52:34 -05:00
|
|
|
func (api *API) InitWebrtc() {
|
|
|
|
|
api.Router.Handle("webrtc", api.ApiWebSocketHandler(api.webrtcMessage))
|
2017-03-28 04:58:19 -04:00
|
|
|
}
|
|
|
|
|
|
2017-09-27 11:52:34 -05:00
|
|
|
func (api *API) webrtcMessage(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
|
2017-03-28 04:58:19 -04:00
|
|
|
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(model.WEBSOCKET_EVENT_WEBRTC, "", "", toUserId, nil)
|
|
|
|
|
event.Data = req.Data
|
2018-03-02 10:49:18 -06:00
|
|
|
api.App.Publish(event)
|
2017-03-28 04:58:19 -04:00
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|