Don't use unnecessary pointer to "json.RawMessage".

The slice is a pointer already.
This commit is contained in:
Joachim Bauch 2024-05-16 20:58:42 +02:00
parent f6125dac3f
commit 4b76a49355
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
20 changed files with 201 additions and 201 deletions

View file

@ -118,8 +118,8 @@ type BackendRoomInviteRequest struct {
UserIds []string `json:"userids,omitempty"`
// TODO(jojo): We should get rid of "AllUserIds" and find a better way to
// notify existing users the room has changed and they need to update it.
AllUserIds []string `json:"alluserids,omitempty"`
Properties *json.RawMessage `json:"properties,omitempty"`
AllUserIds []string `json:"alluserids,omitempty"`
Properties json.RawMessage `json:"properties,omitempty"`
}
type BackendRoomDisinviteRequest struct {
@ -127,13 +127,13 @@ type BackendRoomDisinviteRequest struct {
SessionIds []string `json:"sessionids,omitempty"`
// TODO(jojo): We should get rid of "AllUserIds" and find a better way to
// notify existing users the room has changed and they need to update it.
AllUserIds []string `json:"alluserids,omitempty"`
Properties *json.RawMessage `json:"properties,omitempty"`
AllUserIds []string `json:"alluserids,omitempty"`
Properties json.RawMessage `json:"properties,omitempty"`
}
type BackendRoomUpdateRequest struct {
UserIds []string `json:"userids,omitempty"`
Properties *json.RawMessage `json:"properties,omitempty"`
UserIds []string `json:"userids,omitempty"`
Properties json.RawMessage `json:"properties,omitempty"`
}
type BackendRoomDeleteRequest struct {
@ -154,7 +154,7 @@ type BackendRoomParticipantsRequest struct {
}
type BackendRoomMessageRequest struct {
Data *json.RawMessage `json:"data,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
}
type BackendRoomSwitchToSessionsList []string
@ -169,7 +169,7 @@ type BackendRoomSwitchToMessageRequest struct {
// In the map, the key is the session id, the value additional details
// (or null) for the session. The details will be included in the request
// to the connected client.
Sessions *json.RawMessage `json:"sessions,omitempty"`
Sessions json.RawMessage `json:"sessions,omitempty"`
// Internal properties
SessionsList BackendRoomSwitchToSessionsList `json:"sessionslist,omitempty"`
@ -237,8 +237,8 @@ type BackendRoomDialoutResponse struct {
// Requests from the signaling server to the Nextcloud backend.
type BackendClientAuthRequest struct {
Version string `json:"version"`
Params *json.RawMessage `json:"params"`
Version string `json:"version"`
Params json.RawMessage `json:"params"`
}
type BackendClientRequest struct {
@ -256,7 +256,7 @@ type BackendClientRequest struct {
Session *BackendClientSessionRequest `json:"session,omitempty"`
}
func NewBackendClientAuthRequest(params *json.RawMessage) *BackendClientRequest {
func NewBackendClientAuthRequest(params json.RawMessage) *BackendClientRequest {
return &BackendClientRequest{
Type: "auth",
Auth: &BackendClientAuthRequest{
@ -284,9 +284,9 @@ type BackendClientResponse struct {
}
type BackendClientAuthResponse struct {
Version string `json:"version"`
UserId string `json:"userid"`
User *json.RawMessage `json:"user"`
Version string `json:"version"`
UserId string `json:"userid"`
User json.RawMessage `json:"user"`
}
type BackendClientRoomRequest struct {
@ -315,14 +315,14 @@ func NewBackendClientRoomRequest(roomid string, userid string, sessionid string)
}
type BackendClientRoomResponse struct {
Version string `json:"version"`
RoomId string `json:"roomid"`
Properties *json.RawMessage `json:"properties"`
Version string `json:"version"`
RoomId string `json:"roomid"`
Properties json.RawMessage `json:"properties"`
// Optional information about the Nextcloud Talk session. Can be used for
// example to define a "userid" for otherwise anonymous users.
// See "RoomSessionData" for a possible content.
Session *json.RawMessage `json:"session,omitempty"`
Session json.RawMessage `json:"session,omitempty"`
Permissions *[]Permission `json:"permissions,omitempty"`
}
@ -359,12 +359,12 @@ type BackendClientRingResponse struct {
}
type BackendClientSessionRequest struct {
Version string `json:"version"`
RoomId string `json:"roomid"`
Action string `json:"action"`
SessionId string `json:"sessionid"`
UserId string `json:"userid,omitempty"`
User *json.RawMessage `json:"user,omitempty"`
Version string `json:"version"`
RoomId string `json:"roomid"`
Action string `json:"action"`
SessionId string `json:"sessionid"`
UserId string `json:"userid,omitempty"`
User json.RawMessage `json:"user,omitempty"`
}
type BackendClientSessionResponse struct {
@ -396,8 +396,8 @@ type OcsMeta struct {
}
type OcsBody struct {
Meta OcsMeta `json:"meta"`
Data *json.RawMessage `json:"data"`
Meta OcsMeta `json:"meta"`
Data json.RawMessage `json:"data"`
}
type OcsResponse struct {

View file

@ -198,12 +198,12 @@ func (r *ServerMessage) CloseAfterSend(session Session) bool {
}
func (r *ServerMessage) IsChatRefresh() bool {
if r.Type != "message" || r.Message == nil || r.Message.Data == nil || len(*r.Message.Data) == 0 {
if r.Type != "message" || r.Message == nil || len(r.Message.Data) == 0 {
return false
}
var data MessageServerMessageData
if err := json.Unmarshal(*r.Message.Data, &data); err != nil {
if err := json.Unmarshal(r.Message.Data, &data); err != nil {
return false
}
@ -366,7 +366,7 @@ func (p *HelloV2AuthParams) CheckValid() error {
type HelloV2TokenClaims struct {
jwt.RegisteredClaims
UserData *json.RawMessage `json:"userdata,omitempty"`
UserData json.RawMessage `json:"userdata,omitempty"`
}
type HelloClientMessageAuth struct {
@ -374,7 +374,7 @@ type HelloClientMessageAuth struct {
// "HelloClientTypeClient"
Type string `json:"type,omitempty"`
Params *json.RawMessage `json:"params"`
Params json.RawMessage `json:"params"`
Url string `json:"url"`
parsedUrl *url.URL
@ -401,7 +401,7 @@ func (m *HelloClientMessage) CheckValid() error {
return InvalidHelloVersion
}
if m.ResumeId == "" {
if m.Auth == nil || m.Auth.Params == nil || len(*m.Auth.Params) == 0 {
if m.Auth == nil || len(m.Auth.Params) == 0 {
return fmt.Errorf("params missing")
}
if m.Auth.Type == "" {
@ -425,14 +425,14 @@ func (m *HelloClientMessage) CheckValid() error {
case HelloVersionV1:
// No additional validation necessary.
case HelloVersionV2:
if err := json.Unmarshal(*m.Auth.Params, &m.Auth.helloV2Params); err != nil {
if err := json.Unmarshal(m.Auth.Params, &m.Auth.helloV2Params); err != nil {
return err
} else if err := m.Auth.helloV2Params.CheckValid(); err != nil {
return err
}
}
case HelloClientTypeInternal:
if err := json.Unmarshal(*m.Auth.Params, &m.Auth.internalParams); err != nil {
if err := json.Unmarshal(m.Auth.Params, &m.Auth.internalParams); err != nil {
return err
} else if err := m.Auth.internalParams.CheckValid(); err != nil {
return err
@ -534,8 +534,8 @@ func (m *RoomClientMessage) CheckValid() error {
}
type RoomServerMessage struct {
RoomId string `json:"roomid"`
Properties *json.RawMessage `json:"properties,omitempty"`
RoomId string `json:"roomid"`
Properties json.RawMessage `json:"properties,omitempty"`
}
type RoomErrorDetails struct {
@ -560,7 +560,7 @@ type MessageClientMessageRecipient struct {
type MessageClientMessage struct {
Recipient MessageClientMessageRecipient `json:"recipient"`
Data *json.RawMessage `json:"data"`
Data json.RawMessage `json:"data"`
}
type MessageClientMessageData struct {
@ -606,7 +606,7 @@ func (m *MessageClientMessageData) CheckValid() error {
}
func (m *MessageClientMessage) CheckValid() error {
if m.Data == nil || len(*m.Data) == 0 {
if len(m.Data) == 0 {
return fmt.Errorf("message empty")
}
switch m.Recipient.Type {
@ -647,7 +647,7 @@ type MessageServerMessage struct {
Sender *MessageServerMessageSender `json:"sender"`
Recipient *MessageClientMessageRecipient `json:"recipient,omitempty"`
Data *json.RawMessage `json:"data"`
Data json.RawMessage `json:"data"`
}
// Type "control"
@ -664,7 +664,7 @@ type ControlServerMessage struct {
Sender *MessageServerMessageSender `json:"sender"`
Recipient *MessageClientMessageRecipient `json:"recipient,omitempty"`
Data *json.RawMessage `json:"data"`
Data json.RawMessage `json:"data"`
}
// Type "internal"
@ -693,10 +693,10 @@ type AddSessionOptions struct {
type AddSessionInternalClientMessage struct {
CommonSessionInternalClientMessage
UserId string `json:"userid,omitempty"`
User *json.RawMessage `json:"user,omitempty"`
Flags uint32 `json:"flags,omitempty"`
InCall *int `json:"incall,omitempty"`
UserId string `json:"userid,omitempty"`
User json.RawMessage `json:"user,omitempty"`
Flags uint32 `json:"flags,omitempty"`
InCall *int `json:"incall,omitempty"`
Options *AddSessionOptions `json:"options,omitempty"`
}
@ -848,10 +848,10 @@ type InternalServerMessage struct {
// Type "event"
type RoomEventServerMessage struct {
RoomId string `json:"roomid"`
Properties *json.RawMessage `json:"properties,omitempty"`
RoomId string `json:"roomid"`
Properties json.RawMessage `json:"properties,omitempty"`
// TODO(jojo): Change "InCall" to "int" when #914 has landed in NC Talk.
InCall *json.RawMessage `json:"incall,omitempty"`
InCall json.RawMessage `json:"incall,omitempty"`
Changed []map[string]interface{} `json:"changed,omitempty"`
Users []map[string]interface{} `json:"users,omitempty"`
@ -878,8 +878,8 @@ type RoomDisinviteEventServerMessage struct {
}
type RoomEventMessage struct {
RoomId string `json:"roomid"`
Data *json.RawMessage `json:"data,omitempty"`
RoomId string `json:"roomid"`
Data json.RawMessage `json:"data,omitempty"`
}
type RoomFlagsServerMessage struct {
@ -929,10 +929,10 @@ func (m *EventServerMessage) String() string {
}
type EventServerMessageSessionEntry struct {
SessionId string `json:"sessionid"`
UserId string `json:"userid"`
User *json.RawMessage `json:"user,omitempty"`
RoomSessionId string `json:"roomsessionid,omitempty"`
SessionId string `json:"sessionid"`
UserId string `json:"userid"`
User json.RawMessage `json:"user,omitempty"`
RoomSessionId string `json:"roomsessionid,omitempty"`
}
func (e *EventServerMessageSessionEntry) Clone() *EventServerMessageSessionEntry {
@ -965,9 +965,9 @@ type AnswerOfferMessage struct {
type TransientDataClientMessage struct {
Type string `json:"type"`
Key string `json:"key,omitempty"`
Value *json.RawMessage `json:"value,omitempty"`
TTL time.Duration `json:"ttl,omitempty"`
Key string `json:"key,omitempty"`
Value json.RawMessage `json:"value,omitempty"`
TTL time.Duration `json:"ttl,omitempty"`
}
func (m *TransientDataClientMessage) CheckValid() error {

View file

@ -98,7 +98,7 @@ func TestHelloClientMessage(t *testing.T) {
&HelloClientMessage{
Version: HelloVersionV1,
Auth: &HelloClientMessageAuth{
Params: &json.RawMessage{'{', '}'},
Params: json.RawMessage("{}"),
Url: "https://domain.invalid",
},
},
@ -106,7 +106,7 @@ func TestHelloClientMessage(t *testing.T) {
Version: HelloVersionV1,
Auth: &HelloClientMessageAuth{
Type: "client",
Params: &json.RawMessage{'{', '}'},
Params: json.RawMessage("{}"),
Url: "https://domain.invalid",
},
},
@ -114,7 +114,7 @@ func TestHelloClientMessage(t *testing.T) {
Version: HelloVersionV1,
Auth: &HelloClientMessageAuth{
Type: "internal",
Params: (*json.RawMessage)(&internalAuthParams),
Params: internalAuthParams,
},
},
&HelloClientMessage{
@ -125,7 +125,7 @@ func TestHelloClientMessage(t *testing.T) {
&HelloClientMessage{
Version: HelloVersionV2,
Auth: &HelloClientMessageAuth{
Params: (*json.RawMessage)(&tokenAuthParams),
Params: tokenAuthParams,
Url: "https://domain.invalid",
},
},
@ -133,7 +133,7 @@ func TestHelloClientMessage(t *testing.T) {
Version: HelloVersionV2,
Auth: &HelloClientMessageAuth{
Type: "client",
Params: (*json.RawMessage)(&tokenAuthParams),
Params: tokenAuthParams,
Url: "https://domain.invalid",
},
},
@ -150,7 +150,7 @@ func TestHelloClientMessage(t *testing.T) {
&HelloClientMessage{
Version: HelloVersionV1,
Auth: &HelloClientMessageAuth{
Params: &json.RawMessage{'{', '}'},
Params: json.RawMessage("{}"),
Type: "invalid-type",
},
},
@ -163,13 +163,13 @@ func TestHelloClientMessage(t *testing.T) {
&HelloClientMessage{
Version: HelloVersionV1,
Auth: &HelloClientMessageAuth{
Params: &json.RawMessage{'{', '}'},
Params: json.RawMessage("{}"),
},
},
&HelloClientMessage{
Version: HelloVersionV1,
Auth: &HelloClientMessageAuth{
Params: &json.RawMessage{'{', '}'},
Params: json.RawMessage("{}"),
Url: "invalid-url",
},
},
@ -177,14 +177,14 @@ func TestHelloClientMessage(t *testing.T) {
Version: HelloVersionV1,
Auth: &HelloClientMessageAuth{
Type: "internal",
Params: &json.RawMessage{'{', '}'},
Params: json.RawMessage("{}"),
},
},
&HelloClientMessage{
Version: HelloVersionV1,
Auth: &HelloClientMessageAuth{
Type: "internal",
Params: &json.RawMessage{'x', 'y', 'z'}, // Invalid JSON.
Params: json.RawMessage("xyz"), // Invalid JSON.
},
},
// Hello version 2
@ -197,27 +197,27 @@ func TestHelloClientMessage(t *testing.T) {
&HelloClientMessage{
Version: HelloVersionV2,
Auth: &HelloClientMessageAuth{
Params: (*json.RawMessage)(&tokenAuthParams),
Params: tokenAuthParams,
},
},
&HelloClientMessage{
Version: HelloVersionV2,
Auth: &HelloClientMessageAuth{
Params: (*json.RawMessage)(&tokenAuthParams),
Params: tokenAuthParams,
Url: "invalid-url",
},
},
&HelloClientMessage{
Version: HelloVersionV2,
Auth: &HelloClientMessageAuth{
Params: (*json.RawMessage)(&internalAuthParams),
Params: internalAuthParams,
Url: "https://domain.invalid",
},
},
&HelloClientMessage{
Version: HelloVersionV2,
Auth: &HelloClientMessageAuth{
Params: &json.RawMessage{'x', 'y', 'z'}, // Invalid JSON.
Params: json.RawMessage("xyz"), // Invalid JSON.
Url: "https://domain.invalid",
},
},
@ -242,20 +242,20 @@ func TestMessageClientMessage(t *testing.T) {
Type: "session",
SessionId: "the-session-id",
},
Data: &json.RawMessage{'{', '}'},
Data: json.RawMessage("{}"),
},
&MessageClientMessage{
Recipient: MessageClientMessageRecipient{
Type: "user",
UserId: "the-user-id",
},
Data: &json.RawMessage{'{', '}'},
Data: json.RawMessage("{}"),
},
&MessageClientMessage{
Recipient: MessageClientMessageRecipient{
Type: "room",
},
Data: &json.RawMessage{'{', '}'},
Data: json.RawMessage("{}"),
},
}
invalid_messages := []testCheckValid{
@ -270,20 +270,20 @@ func TestMessageClientMessage(t *testing.T) {
Recipient: MessageClientMessageRecipient{
Type: "session",
},
Data: &json.RawMessage{'{', '}'},
Data: json.RawMessage("{}"),
},
&MessageClientMessage{
Recipient: MessageClientMessageRecipient{
Type: "session",
UserId: "the-user-id",
},
Data: &json.RawMessage{'{', '}'},
Data: json.RawMessage("{}"),
},
&MessageClientMessage{
Recipient: MessageClientMessageRecipient{
Type: "user",
},
Data: &json.RawMessage{'{', '}'},
Data: json.RawMessage("{}"),
},
&MessageClientMessage{
Recipient: MessageClientMessageRecipient{
@ -296,13 +296,13 @@ func TestMessageClientMessage(t *testing.T) {
Type: "user",
SessionId: "the-user-id",
},
Data: &json.RawMessage{'{', '}'},
Data: json.RawMessage("{}"),
},
&MessageClientMessage{
Recipient: MessageClientMessageRecipient{
Type: "unknown-type",
},
Data: &json.RawMessage{'{', '}'},
Data: json.RawMessage("{}"),
},
}
testMessages(t, "message", valid_messages, invalid_messages)
@ -394,7 +394,7 @@ func TestIsChatRefresh(t *testing.T) {
msg = ServerMessage{
Type: "message",
Message: &MessageServerMessage{
Data: (*json.RawMessage)(&data_true),
Data: data_true,
},
}
if !msg.IsChatRefresh() {
@ -405,7 +405,7 @@ func TestIsChatRefresh(t *testing.T) {
msg = ServerMessage{
Type: "message",
Message: &MessageServerMessage{
Data: (*json.RawMessage)(&data_false),
Data: data_false,
},
}
if msg.IsChatRefresh() {

View file

@ -194,7 +194,7 @@ func (b *BackendClient) PerformJSONRequest(ctx context.Context, u *url.URL, requ
if err := json.Unmarshal(body, &ocs); err != nil {
log.Printf("Could not decode OCS response %s from %s: %s", string(body), req.URL, err)
return err
} else if ocs.Ocs == nil || ocs.Ocs.Data == nil {
} else if ocs.Ocs == nil || len(ocs.Ocs.Data) == 0 {
log.Printf("Incomplete OCS response %s from %s", string(body), req.URL)
return ErrIncompleteResponse
}
@ -205,8 +205,8 @@ func (b *BackendClient) PerformJSONRequest(ctx context.Context, u *url.URL, requ
return ErrThrottledResponse
}
if err := json.Unmarshal(*ocs.Ocs.Data, response); err != nil {
log.Printf("Could not decode OCS response body %s from %s: %s", string(*ocs.Ocs.Data), req.URL, err)
if err := json.Unmarshal(ocs.Ocs.Data, response); err != nil {
log.Printf("Could not decode OCS response body %s from %s: %s", string(ocs.Ocs.Data), req.URL, err)
return err
}
} else if err := json.Unmarshal(body, response); err != nil {

View file

@ -45,7 +45,7 @@ func returnOCS(t *testing.T, w http.ResponseWriter, body []byte) {
StatusCode: http.StatusOK,
Message: "OK",
},
Data: (*json.RawMessage)(&body),
Data: body,
},
}
if strings.Contains(t.Name(), "Throttled") {

View file

@ -277,7 +277,7 @@ func (b *BackendServer) parseRequestBody(f func(http.ResponseWriter, *http.Reque
}
}
func (b *BackendServer) sendRoomInvite(roomid string, backend *Backend, userids []string, properties *json.RawMessage) {
func (b *BackendServer) sendRoomInvite(roomid string, backend *Backend, userids []string, properties json.RawMessage) {
msg := &AsyncMessage{
Type: "message",
Message: &ServerMessage{
@ -347,7 +347,7 @@ func (b *BackendServer) sendRoomDisinvite(roomid string, backend *Backend, reaso
wg.Wait()
}
func (b *BackendServer) sendRoomUpdate(roomid string, backend *Backend, notified_userids []string, all_userids []string, properties *json.RawMessage) {
func (b *BackendServer) sendRoomUpdate(roomid string, backend *Backend, notified_userids []string, all_userids []string, properties json.RawMessage) {
msg := &AsyncMessage{
Type: "message",
Message: &ServerMessage{
@ -553,11 +553,11 @@ func (b *BackendServer) sendRoomSwitchTo(roomid string, backend *Backend, reques
var wg sync.WaitGroup
var mu sync.Mutex
if request.SwitchTo.Sessions != nil {
if len(request.SwitchTo.Sessions) > 0 {
// We support both a list of sessions or a map with additional details per session.
if (*request.SwitchTo.Sessions)[0] == '[' {
if request.SwitchTo.Sessions[0] == '[' {
var sessionsList BackendRoomSwitchToSessionsList
if err := json.Unmarshal(*request.SwitchTo.Sessions, &sessionsList); err != nil {
if err := json.Unmarshal(request.SwitchTo.Sessions, &sessionsList); err != nil {
return err
}
@ -595,7 +595,7 @@ func (b *BackendServer) sendRoomSwitchTo(roomid string, backend *Backend, reques
request.SwitchTo.SessionsMap = nil
} else {
var sessionsMap BackendRoomSwitchToSessionsMap
if err := json.Unmarshal(*request.SwitchTo.Sessions, &sessionsMap); err != nil {
if err := json.Unmarshal(request.SwitchTo.Sessions, &sessionsMap); err != nil {
return err
}

View file

@ -350,7 +350,7 @@ func TestBackendServer_OldCompatAuth(t *testing.T) {
AllUserIds: []string{
userid,
},
Properties: &roomProperties,
Properties: roomProperties,
},
}
@ -481,7 +481,7 @@ func RunTestBackendServer_RoomInvite(t *testing.T) {
AllUserIds: []string{
userid,
},
Properties: &roomProperties,
Properties: roomProperties,
},
}
@ -510,8 +510,8 @@ func RunTestBackendServer_RoomInvite(t *testing.T) {
t.Errorf("Expected invite, got %+v", event)
} else if event.Invite.RoomId != roomId {
t.Errorf("Expected room %s, got %+v", roomId, event)
} else if event.Invite.Properties == nil || !bytes.Equal(*event.Invite.Properties, roomProperties) {
t.Errorf("Room properties don't match: expected %s, got %s", string(roomProperties), string(*event.Invite.Properties))
} else if !bytes.Equal(event.Invite.Properties, roomProperties) {
t.Errorf("Room properties don't match: expected %s, got %s", string(roomProperties), string(event.Invite.Properties))
}
}
@ -583,7 +583,7 @@ func RunTestBackendServer_RoomDisinvite(t *testing.T) {
roomId + "-" + hello.Hello.SessionId,
},
AllUserIds: []string{},
Properties: &roomProperties,
Properties: roomProperties,
},
}
@ -611,8 +611,8 @@ func RunTestBackendServer_RoomDisinvite(t *testing.T) {
t.Errorf("Expected disinvite, got %+v", event)
} else if event.Disinvite.RoomId != roomId {
t.Errorf("Expected room %s, got %+v", roomId, event)
} else if event.Disinvite.Properties != nil {
t.Errorf("Room properties should be omitted, got %s", string(*event.Disinvite.Properties))
} else if len(event.Disinvite.Properties) > 0 {
t.Errorf("Room properties should be omitted, got %s", string(event.Disinvite.Properties))
} else if event.Disinvite.Reason != "disinvited" {
t.Errorf("Reason should be disinvited, got %s", event.Disinvite.Reason)
}
@ -729,7 +729,7 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
UserIds: []string{
testDefaultUserId,
},
Properties: (*json.RawMessage)(&testRoomProperties),
Properties: testRoomProperties,
},
}
@ -781,7 +781,7 @@ func RunTestBackendServer_RoomUpdate(t *testing.T) {
if backend == nil {
t.Fatalf("Did not find backend")
}
room, err := hub.createRoom(roomId, &emptyProperties, backend)
room, err := hub.createRoom(roomId, emptyProperties, backend)
if err != nil {
t.Fatalf("Could not create room: %s", err)
}
@ -805,7 +805,7 @@ func RunTestBackendServer_RoomUpdate(t *testing.T) {
UserIds: []string{
userid,
},
Properties: &roomProperties,
Properties: roomProperties,
},
}
@ -833,8 +833,8 @@ func RunTestBackendServer_RoomUpdate(t *testing.T) {
t.Errorf("Expected update, got %+v", event)
} else if event.Update.RoomId != roomId {
t.Errorf("Expected room %s, got %+v", roomId, event)
} else if event.Update.Properties == nil || !bytes.Equal(*event.Update.Properties, roomProperties) {
t.Errorf("Room properties don't match: expected %s, got %s", string(roomProperties), string(*event.Update.Properties))
} else if !bytes.Equal(event.Update.Properties, roomProperties) {
t.Errorf("Room properties don't match: expected %s, got %s", string(roomProperties), string(event.Update.Properties))
}
// TODO: Use event to wait for asynchronous messages.
@ -844,8 +844,8 @@ func RunTestBackendServer_RoomUpdate(t *testing.T) {
if room == nil {
t.Fatalf("Room %s does not exist", roomId)
}
if string(*room.Properties()) != string(roomProperties) {
t.Errorf("Expected properties %s for room %s, got %s", string(roomProperties), room.Id(), string(*room.Properties()))
if string(room.Properties()) != string(roomProperties) {
t.Errorf("Expected properties %s for room %s, got %s", string(roomProperties), room.Id(), string(room.Properties()))
}
}
@ -873,7 +873,7 @@ func RunTestBackendServer_RoomDelete(t *testing.T) {
if backend == nil {
t.Fatalf("Did not find backend")
}
if _, err := hub.createRoom(roomId, &emptyProperties, backend); err != nil {
if _, err := hub.createRoom(roomId, emptyProperties, backend); err != nil {
t.Fatalf("Could not create room: %s", err)
}
@ -921,8 +921,8 @@ func RunTestBackendServer_RoomDelete(t *testing.T) {
t.Errorf("Expected disinvite, got %+v", event)
} else if event.Disinvite.RoomId != roomId {
t.Errorf("Expected room %s, got %+v", roomId, event)
} else if event.Disinvite.Properties != nil {
t.Errorf("Room properties should be omitted, got %s", string(*event.Disinvite.Properties))
} else if len(event.Disinvite.Properties) > 0 {
t.Errorf("Room properties should be omitted, got %s", string(event.Disinvite.Properties))
} else if event.Disinvite.Reason != "deleted" {
t.Errorf("Reason should be deleted, got %s", event.Disinvite.Reason)
}
@ -1500,8 +1500,8 @@ func TestBackendServer_InCallAll(t *testing.T) {
t.Error(err)
} else if !in_call_1.All {
t.Errorf("All flag not set in message %+v", in_call_1)
} else if !bytes.Equal(*in_call_1.InCall, []byte("7")) {
t.Errorf("Expected inCall flag 7, got %s", string(*in_call_1.InCall))
} else if !bytes.Equal(in_call_1.InCall, []byte("7")) {
t.Errorf("Expected inCall flag 7, got %s", string(in_call_1.InCall))
}
if msg2_a, err := client2.RunUntilMessage(ctx); err != nil {
@ -1510,8 +1510,8 @@ func TestBackendServer_InCallAll(t *testing.T) {
t.Error(err)
} else if !in_call_1.All {
t.Errorf("All flag not set in message %+v", in_call_1)
} else if !bytes.Equal(*in_call_1.InCall, []byte("7")) {
t.Errorf("Expected inCall flag 7, got %s", string(*in_call_1.InCall))
} else if !bytes.Equal(in_call_1.InCall, []byte("7")) {
t.Errorf("Expected inCall flag 7, got %s", string(in_call_1.InCall))
}
if !room1.IsSessionInCall(session1) {
@ -1581,8 +1581,8 @@ func TestBackendServer_InCallAll(t *testing.T) {
t.Error(err)
} else if !in_call_1.All {
t.Errorf("All flag not set in message %+v", in_call_1)
} else if !bytes.Equal(*in_call_1.InCall, []byte("0")) {
t.Errorf("Expected inCall flag 0, got %s", string(*in_call_1.InCall))
} else if !bytes.Equal(in_call_1.InCall, []byte("0")) {
t.Errorf("Expected inCall flag 0, got %s", string(in_call_1.InCall))
}
if msg2_a, err := client2.RunUntilMessage(ctx); err != nil {
@ -1591,8 +1591,8 @@ func TestBackendServer_InCallAll(t *testing.T) {
t.Error(err)
} else if !in_call_1.All {
t.Errorf("All flag not set in message %+v", in_call_1)
} else if !bytes.Equal(*in_call_1.InCall, []byte("0")) {
t.Errorf("Expected inCall flag 0, got %s", string(*in_call_1.InCall))
} else if !bytes.Equal(in_call_1.InCall, []byte("0")) {
t.Errorf("Expected inCall flag 0, got %s", string(in_call_1.InCall))
}
if room1.IsSessionInCall(session1) {
@ -1659,7 +1659,7 @@ func TestBackendServer_RoomMessage(t *testing.T) {
msg := &BackendServerRoomRequest{
Type: "message",
Message: &BackendRoomMessageRequest{
Data: &messageData,
Data: messageData,
},
}
@ -1685,8 +1685,8 @@ func TestBackendServer_RoomMessage(t *testing.T) {
t.Error(err)
} else if message.RoomId != roomId {
t.Errorf("Expected message for room %s, got %s", roomId, message.RoomId)
} else if !bytes.Equal(messageData, *message.Data) {
t.Errorf("Expected message data %s, got %s", string(messageData), string(*message.Data))
} else if !bytes.Equal(messageData, message.Data) {
t.Errorf("Expected message data %s, got %s", string(messageData), string(message.Data))
}
}

View file

@ -88,8 +88,8 @@ type CapabilitiesVersion struct {
}
type CapabilitiesResponse struct {
Version CapabilitiesVersion `json:"version"`
Capabilities map[string]*json.RawMessage `json:"capabilities"`
Version CapabilitiesVersion `json:"version"`
Capabilities map[string]json.RawMessage `json:"capabilities"`
}
func (c *Capabilities) getCapabilities(key string) (map[string]interface{}, bool) {
@ -191,25 +191,25 @@ func (c *Capabilities) loadCapabilities(ctx context.Context, u *url.URL) (map[st
if err := json.Unmarshal(body, &ocs); err != nil {
log.Printf("Could not decode OCS response %s from %s: %s", string(body), capUrl.String(), err)
return nil, false, err
} else if ocs.Ocs == nil || ocs.Ocs.Data == nil {
} else if ocs.Ocs == nil || len(ocs.Ocs.Data) == 0 {
log.Printf("Incomplete OCS response %s from %s", string(body), u)
return nil, false, fmt.Errorf("incomplete OCS response")
}
var response CapabilitiesResponse
if err := json.Unmarshal(*ocs.Ocs.Data, &response); err != nil {
log.Printf("Could not decode OCS response body %s from %s: %s", string(*ocs.Ocs.Data), capUrl.String(), err)
if err := json.Unmarshal(ocs.Ocs.Data, &response); err != nil {
log.Printf("Could not decode OCS response body %s from %s: %s", string(ocs.Ocs.Data), capUrl.String(), err)
return nil, false, err
}
capaObj, found := response.Capabilities[AppNameSpreed]
if !found || capaObj == nil {
if !found || len(capaObj) == 0 {
log.Printf("No capabilities received for app spreed from %s: %+v", capUrl.String(), response)
return nil, false, nil
}
var capa map[string]interface{}
if err := json.Unmarshal(*capaObj, &capa); err != nil {
if err := json.Unmarshal(capaObj, &capa); err != nil {
log.Printf("Unsupported capabilities received for app spreed from %s: %+v", capUrl.String(), response)
return nil, false, nil
}

View file

@ -80,9 +80,9 @@ func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*Capabilitie
Version: CapabilitiesVersion{
Major: 20,
},
Capabilities: map[string]*json.RawMessage{
"anotherApp": (*json.RawMessage)(&emptyArray),
"spreed": (*json.RawMessage)(&spreedCapa),
Capabilities: map[string]json.RawMessage{
"anotherApp": emptyArray,
"spreed": spreedCapa,
},
}
@ -102,7 +102,7 @@ func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*Capabilitie
StatusCode: http.StatusOK,
Message: http.StatusText(http.StatusOK),
},
Data: (*json.RawMessage)(&data),
Data: data,
}
if data, err = json.Marshal(ocs); err != nil {
t.Fatal(err)

View file

@ -248,7 +248,7 @@ func (c *SignalingClient) PublicSessionId() string {
func (c *SignalingClient) processMessageMessage(message *signaling.ServerMessage) {
var msg MessagePayload
if err := json.Unmarshal(*message.Message.Data, &msg); err != nil {
if err := json.Unmarshal(message.Message.Data, &msg); err != nil {
log.Println("Error in unmarshal", err)
return
}
@ -404,7 +404,7 @@ func (c *SignalingClient) SendMessages(clients []*SignalingClient) {
Type: "session",
SessionId: sessionIds[recipient],
},
Data: (*json.RawMessage)(&data),
Data: data,
},
}
sender.Send(msg)
@ -461,7 +461,7 @@ func registerAuthHandler(router *mux.Router) {
StatusCode: http.StatusOK,
Message: http.StatusText(http.StatusOK),
},
Data: &rawdata,
Data: rawdata,
},
}
@ -603,7 +603,7 @@ func main() {
Version: signaling.HelloVersionV1,
Auth: &signaling.HelloClientMessageAuth{
Url: backendUrl + "/auth",
Params: &json.RawMessage{'{', '}'},
Params: json.RawMessage("{}"),
},
},
}

View file

@ -57,7 +57,7 @@ type ClientSession struct {
clientType string
features []string
userId string
userData *json.RawMessage
userData json.RawMessage
inCall Flags
supportsPermissions bool
@ -313,7 +313,7 @@ func (s *ClientSession) UserId() string {
return userId
}
func (s *ClientSession) UserData() *json.RawMessage {
func (s *ClientSession) UserData() json.RawMessage {
return s.userData
}
@ -584,7 +584,7 @@ func (s *ClientSession) sendOffer(client McuClient, sender string, streamType St
Type: "session",
SessionId: sender,
},
Data: (*json.RawMessage)(&offer_data),
Data: offer_data,
},
}
@ -614,7 +614,7 @@ func (s *ClientSession) sendCandidate(client McuClient, sender string, streamTyp
Type: "session",
SessionId: sender,
},
Data: (*json.RawMessage)(&candidate_data),
Data: candidate_data,
},
}
@ -1106,13 +1106,13 @@ func (s *ClientSession) storePendingMessage(message *ServerMessage) {
func filterDisplayNames(events []*EventServerMessageSessionEntry) []*EventServerMessageSessionEntry {
result := make([]*EventServerMessageSessionEntry, 0, len(events))
for _, event := range events {
if event.User == nil {
if len(event.User) == 0 {
result = append(result, event)
continue
}
var userdata map[string]interface{}
if err := json.Unmarshal(*event.User, &userdata); err != nil {
if err := json.Unmarshal(event.User, &userdata); err != nil {
result = append(result, event)
continue
}
@ -1138,7 +1138,7 @@ func filterDisplayNames(events []*EventServerMessageSessionEntry) []*EventServer
}
e := event.Clone()
e.User = (*json.RawMessage)(&data)
e.User = data
result = append(result, e)
}
return result
@ -1233,12 +1233,12 @@ func (s *ClientSession) filterMessage(message *ServerMessage) *ServerMessage {
delete(s.seenJoinedEvents, e)
}
case "message":
if message.Event.Message == nil || message.Event.Message.Data == nil || len(*message.Event.Message.Data) == 0 || !s.HasPermission(PERMISSION_HIDE_DISPLAYNAMES) {
if message.Event.Message == nil || len(message.Event.Message.Data) == 0 || !s.HasPermission(PERMISSION_HIDE_DISPLAYNAMES) {
return message
}
var data RoomEventMessageData
if err := json.Unmarshal(*message.Event.Message.Data, &data); err != nil {
if err := json.Unmarshal(message.Event.Message.Data, &data); err != nil {
return message
}
@ -1255,7 +1255,7 @@ func (s *ClientSession) filterMessage(message *ServerMessage) *ServerMessage {
Target: message.Event.Target,
Message: &RoomEventMessage{
RoomId: message.Event.Message.RoomId,
Data: (*json.RawMessage)(&encoded),
Data: encoded,
},
},
}
@ -1265,9 +1265,9 @@ func (s *ClientSession) filterMessage(message *ServerMessage) *ServerMessage {
}
}
case "message":
if message.Message != nil && message.Message.Data != nil && len(*message.Message.Data) > 0 && s.HasPermission(PERMISSION_HIDE_DISPLAYNAMES) {
if message.Message != nil && len(message.Message.Data) > 0 && s.HasPermission(PERMISSION_HIDE_DISPLAYNAMES) {
var data MessageServerMessageData
if err := json.Unmarshal(*message.Message.Data, &data); err != nil {
if err := json.Unmarshal(message.Message.Data, &data); err != nil {
return message
}

12
hub.go
View file

@ -1542,7 +1542,7 @@ func (h *Hub) removeRoom(room *Room) {
h.roomPing.DeleteRoom(room)
}
func (h *Hub) createRoom(id string, properties *json.RawMessage, backend *Backend) (*Room, error) {
func (h *Hub) createRoom(id string, properties json.RawMessage, backend *Backend) (*Room, error) {
// Note the write lock must be held.
room, err := NewRoom(id, properties, h, h.events, backend)
if err != nil {
@ -1625,7 +1625,7 @@ func (h *Hub) processMessageMsg(sess Session, message *ClientMessage) {
if h.mcu != nil {
// Maybe this is a message to be processed by the MCU.
var data MessageClientMessageData
if err := json.Unmarshal(*msg.Data, &data); err == nil {
if err := json.Unmarshal(msg.Data, &data); err == nil {
if err := data.CheckValid(); err != nil {
log.Printf("Invalid message %+v from client %s: %v", message, session.PublicId(), err)
if err, ok := err.(*Error); ok {
@ -1740,7 +1740,7 @@ func (h *Hub) processMessageMsg(sess Session, message *ClientMessage) {
if h.mcu != nil {
var data MessageClientMessageData
if err := json.Unmarshal(*msg.Data, &data); err == nil {
if err := json.Unmarshal(msg.Data, &data); err == nil {
if err := data.CheckValid(); err != nil {
log.Printf("Invalid message %+v from client %s: %v", message, session.PublicId(), err)
if err, ok := err.(*Error); ok {
@ -2224,7 +2224,7 @@ func (h *Hub) processTransientMsg(session Session, message *ClientMessage) {
if msg.Value == nil {
room.SetTransientDataTTL(msg.Key, nil, msg.TTL)
} else {
room.SetTransientDataTTL(msg.Key, *msg.Value, msg.TTL)
room.SetTransientDataTTL(msg.Key, msg.Value, msg.TTL)
}
case "remove":
if !isAllowedToUpdateTransientData(session) {
@ -2423,7 +2423,7 @@ func (h *Hub) sendMcuMessageResponse(session *ClientSession, mcuClient McuClient
SessionId: session.PublicId(),
UserId: session.UserId(),
},
Data: (*json.RawMessage)(&answer_data),
Data: answer_data,
},
}
case "offer":
@ -2448,7 +2448,7 @@ func (h *Hub) sendMcuMessageResponse(session *ClientSession, mcuClient McuClient
SessionId: message.Recipient.SessionId,
// TODO(jojo): Set "UserId" field if known user.
},
Data: (*json.RawMessage)(&offer_data),
Data: offer_data,
},
}
default:

View file

@ -346,7 +346,7 @@ func validateBackendChecksum(t *testing.T, f func(http.ResponseWriter, *http.Req
StatusCode: http.StatusOK,
Message: http.StatusText(http.StatusOK),
},
Data: (*json.RawMessage)(&data),
Data: data,
}
if data, err = json.Marshal(ocs); err != nil {
t.Fatal(err)
@ -365,8 +365,8 @@ func processAuthRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
}
var params TestBackendClientAuthParams
if request.Auth.Params != nil && len(*request.Auth.Params) > 0 {
if err := json.Unmarshal(*request.Auth.Params, &params); err != nil {
if len(request.Auth.Params) > 0 {
if err := json.Unmarshal(request.Auth.Params, &params); err != nil {
t.Fatal(err)
}
}
@ -389,7 +389,7 @@ func processAuthRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
if data, err := json.Marshal(userdata); err != nil {
t.Fatal(err)
} else {
response.Auth.User = (*json.RawMessage)(&data)
response.Auth.User = data
}
return response
}
@ -415,7 +415,7 @@ func processRoomRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
Room: &BackendClientRoomResponse{
Version: BackendVersion,
RoomId: request.Room.RoomId,
Properties: (*json.RawMessage)(&testRoomProperties),
Properties: testRoomProperties,
},
}
switch request.Room.RoomId {
@ -427,7 +427,7 @@ func processRoomRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
if err != nil {
t.Fatalf("Could not marshal %+v: %s", data, err)
}
response.Room.Session = (*json.RawMessage)(&tmp)
response.Room.Session = tmp
case "test-room-initial-permissions":
permissions := []Permission{PERMISSION_MAY_PUBLISH_AUDIO}
response.Room.Permissions = &permissions
@ -748,8 +748,8 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
Version: CapabilitiesVersion{
Major: 20,
},
Capabilities: map[string]*json.RawMessage{
"spreed": (*json.RawMessage)(&spreedCapa),
Capabilities: map[string]json.RawMessage{
"spreed": spreedCapa,
},
}
@ -765,7 +765,7 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
StatusCode: http.StatusOK,
Message: http.StatusText(http.StatusOK),
},
Data: (*json.RawMessage)(&data),
Data: data,
}
if data, err = json.Marshal(ocs); err != nil {
t.Fatal(err)
@ -951,7 +951,7 @@ func TestClientHelloV2(t *testing.T) {
}
var userdata map[string]string
if err := json.Unmarshal(*session.UserData(), &userdata); err != nil {
if err := json.Unmarshal(session.UserData(), &userdata); err != nil {
t.Fatal(err)
}
@ -3029,8 +3029,8 @@ func TestJoinRoomTwice(t *testing.T) {
t.Fatal(err)
} else if room.Room.RoomId != roomId {
t.Fatalf("Expected room %s, got %s", roomId, room.Room.RoomId)
} else if !bytes.Equal(testRoomProperties, *room.Room.Properties) {
t.Fatalf("Expected room properties %s, got %s", string(testRoomProperties), string(*room.Room.Properties))
} else if !bytes.Equal(testRoomProperties, room.Room.Properties) {
t.Fatalf("Expected room properties %s, got %s", string(testRoomProperties), string(room.Room.Properties))
}
// We will receive a "joined" event.
@ -3077,8 +3077,8 @@ func TestJoinRoomTwice(t *testing.T) {
if roomMsg.Room.RoomId != roomId {
t.Fatalf("Expected room %s, got %+v", roomId, roomMsg.Room)
} else if !bytes.Equal(testRoomProperties, *roomMsg.Room.Properties) {
t.Fatalf("Expected room properties %s, got %s", string(testRoomProperties), string(*roomMsg.Room.Properties))
} else if !bytes.Equal(testRoomProperties, roomMsg.Room.Properties) {
t.Fatalf("Expected room properties %s, got %s", string(testRoomProperties), string(roomMsg.Room.Properties))
}
}
@ -5570,7 +5570,7 @@ func DoTestSwitchToOne(t *testing.T, details map[string]interface{}) {
Type: "switchto",
SwitchTo: &BackendRoomSwitchToMessageRequest{
RoomId: roomId2,
Sessions: &sessions,
Sessions: sessions,
},
}
@ -5710,7 +5710,7 @@ func DoTestSwitchToMultiple(t *testing.T, details1 map[string]interface{}, detai
Type: "switchto",
SwitchTo: &BackendRoomSwitchToMessageRequest{
RoomId: roomId2,
Sessions: &sessions,
Sessions: sessions,
},
}

22
room.go
View file

@ -65,7 +65,7 @@ type Room struct {
events AsyncEvents
backend *Backend
properties *json.RawMessage
properties json.RawMessage
closer *Closer
mu *sync.RWMutex
@ -95,7 +95,7 @@ func getRoomIdForBackend(id string, backend *Backend) string {
return backend.Id() + "|" + id
}
func NewRoom(roomId string, properties *json.RawMessage, hub *Hub, events AsyncEvents, backend *Backend) (*Room, error) {
func NewRoom(roomId string, properties json.RawMessage, hub *Hub, events AsyncEvents, backend *Backend) (*Room, error) {
room := &Room{
id: roomId,
hub: hub,
@ -136,7 +136,7 @@ func (r *Room) Id() string {
return r.id
}
func (r *Room) Properties() *json.RawMessage {
func (r *Room) Properties() json.RawMessage {
r.mu.RLock()
defer r.mu.RUnlock()
return r.properties
@ -270,12 +270,12 @@ func (r *Room) processBackendRoomRequestAsyncRoom(message *AsyncRoomMessage) {
}
}
func (r *Room) AddSession(session Session, sessionData *json.RawMessage) {
func (r *Room) AddSession(session Session, sessionData json.RawMessage) {
var roomSessionData *RoomSessionData
if sessionData != nil && len(*sessionData) > 0 {
if len(sessionData) > 0 {
roomSessionData = &RoomSessionData{}
if err := json.Unmarshal(*sessionData, roomSessionData); err != nil {
log.Printf("Error decoding room session data \"%s\": %s", string(*sessionData), err)
if err := json.Unmarshal(sessionData, roomSessionData); err != nil {
log.Printf("Error decoding room session data \"%s\": %s", string(sessionData), err)
roomSessionData = nil
}
}
@ -480,11 +480,11 @@ func (r *Room) publish(message *ServerMessage) error {
})
}
func (r *Room) UpdateProperties(properties *json.RawMessage) {
func (r *Room) UpdateProperties(properties json.RawMessage) {
r.mu.Lock()
defer r.mu.Unlock()
if (r.properties == nil && properties == nil) ||
(r.properties != nil && properties != nil && bytes.Equal(*r.properties, *properties)) {
if (len(r.properties) == 0 && len(properties) == 0) ||
(len(r.properties) > 0 && len(properties) > 0 && bytes.Equal(r.properties, properties)) {
// Don't notify if properties didn't change.
return
}
@ -769,7 +769,7 @@ func (r *Room) PublishUsersInCallChangedAll(inCall int) {
Type: "update",
Update: &RoomEventServerMessage{
RoomId: r.id,
InCall: &inCallMsg,
InCall: inCallMsg,
All: true,
},
},

View file

@ -125,7 +125,7 @@ func TestRoom_Update(t *testing.T) {
UserIds: []string{
testDefaultUserId,
},
Properties: &roomProperties,
Properties: roomProperties,
},
}
@ -166,13 +166,13 @@ func TestRoom_Update(t *testing.T) {
t.Error(err)
} else if msg.RoomId != roomId {
t.Errorf("Expected room id %s, got %+v", roomId, msg)
} else if msg.Properties == nil || !bytes.Equal(*msg.Properties, roomProperties) {
} else if len(msg.Properties) == 0 || !bytes.Equal(msg.Properties, roomProperties) {
t.Errorf("Expected room properties %s, got %+v", string(roomProperties), msg)
}
} else {
if msg.RoomId != roomId {
t.Errorf("Expected room id %s, got %+v", roomId, msg)
} else if msg.Properties == nil || !bytes.Equal(*msg.Properties, roomProperties) {
} else if len(msg.Properties) == 0 || !bytes.Equal(msg.Properties, roomProperties) {
t.Errorf("Expected room properties %s, got %+v", string(roomProperties), msg)
}
if err := checkMessageRoomId(message2, roomId); err != nil {
@ -193,7 +193,7 @@ loop:
// The internal room has been updated with the new properties.
if room := hub.getRoom(roomId); room == nil {
err = fmt.Errorf("Room %s not found in hub", roomId)
} else if room.Properties() == nil || !bytes.Equal(*room.Properties(), roomProperties) {
} else if len(room.Properties()) == 0 || !bytes.Equal(room.Properties(), roomProperties) {
err = fmt.Errorf("Expected room properties %s, got %+v", string(roomProperties), room.Properties())
} else {
err = nil

View file

@ -57,7 +57,7 @@ func (s *DummySession) UserId() string {
return ""
}
func (s *DummySession) UserData() *json.RawMessage {
func (s *DummySession) UserData() json.RawMessage {
return nil
}

View file

@ -61,7 +61,7 @@ type Session interface {
Data() *SessionIdData
UserId() string
UserData() *json.RawMessage
UserData() json.RawMessage
Backend() *Backend
BackendUrl() string

View file

@ -98,7 +98,7 @@ func checkMessageType(message *ServerMessage, expectedType string) error {
case "message":
if message.Message == nil {
return fmt.Errorf("Expected \"%s\" message, got %+v", expectedType, message)
} else if message.Message.Data == nil || len(*message.Message.Data) == 0 {
} else if len(message.Message.Data) == 0 {
return fmt.Errorf("Received message without data")
}
case "room":
@ -140,7 +140,7 @@ func checkReceiveClientMessageWithSenderAndRecipient(ctx context.Context, client
} else if err := checkMessageSender(client.hub, message.Message.Sender, senderType, hello); err != nil {
return err
} else {
if err := json.Unmarshal(*message.Message.Data, payload); err != nil {
if err := json.Unmarshal(message.Message.Data, payload); err != nil {
return err
}
}
@ -170,7 +170,7 @@ func checkReceiveClientControlWithSenderAndRecipient(ctx context.Context, client
} else if err := checkMessageSender(client.hub, message.Control.Sender, senderType, hello); err != nil {
return err
} else {
if err := json.Unmarshal(*message.Control.Data, payload); err != nil {
if err := json.Unmarshal(message.Control.Data, payload); err != nil {
return err
}
}
@ -416,7 +416,7 @@ func (c *TestClient) SendHelloV2WithTimes(userid string, issuedAt time.Time, exp
Issuer: c.server.URL,
Subject: userid,
},
UserData: (*json.RawMessage)(&data),
UserData: data,
}
if !issuedAt.IsZero() {
claims.IssuedAt = jwt.NewNumericDate(issuedAt)
@ -498,7 +498,7 @@ func (c *TestClient) SendHelloParams(url string, version string, clientType stri
Auth: &HelloClientMessageAuth{
Type: clientType,
Url: url,
Params: (*json.RawMessage)(&data),
Params: data,
},
},
}
@ -525,7 +525,7 @@ func (c *TestClient) SendMessage(recipient MessageClientMessageRecipient, data i
Type: "message",
Message: &MessageClientMessage{
Recipient: recipient,
Data: (*json.RawMessage)(&payload),
Data: payload,
},
}
return c.WriteJSON(message)
@ -543,7 +543,7 @@ func (c *TestClient) SendControl(recipient MessageClientMessageRecipient, data i
Control: &ControlClientMessage{
MessageClientMessage: MessageClientMessage{
Recipient: recipient,
Data: (*json.RawMessage)(&payload),
Data: payload,
},
},
}
@ -610,7 +610,7 @@ func (c *TestClient) SetTransientData(key string, value interface{}, ttl time.Du
TransientData: &TransientDataClientMessage{
Type: "set",
Key: key,
Value: (*json.RawMessage)(&payload),
Value: payload,
TTL: ttl,
},
}
@ -973,7 +973,7 @@ func (c *TestClient) RunUntilOffer(ctx context.Context, offer string) error {
}
var data map[string]interface{}
if err := json.Unmarshal(*message.Message.Data, &data); err != nil {
if err := json.Unmarshal(message.Message.Data, &data); err != nil {
return err
}
@ -1004,7 +1004,7 @@ func (c *TestClient) RunUntilAnswer(ctx context.Context, answer string) error {
}
var data map[string]interface{}
if err := json.Unmarshal(*message.Message.Data, &data); err != nil {
if err := json.Unmarshal(message.Message.Data, &data); err != nil {
return err
}
@ -1076,7 +1076,7 @@ func checkMessageInCallAll(message *ServerMessage, roomId string, inCall int) er
return fmt.Errorf("Expected participants update event for room %s, got %+v", roomId, message.Event.Update)
} else if !message.Event.Update.All {
return fmt.Errorf("Expected participants update event for all, got %+v", message.Event.Update)
} else if !bytes.Equal(*message.Event.Update.InCall, []byte(strconv.FormatInt(int64(inCall), 10))) {
} else if !bytes.Equal(message.Event.Update.InCall, []byte(strconv.FormatInt(int64(inCall), 10))) {
return fmt.Errorf("Expected incall flags %d, got %+v", inCall, message.Event.Update)
}
return nil

View file

@ -45,7 +45,7 @@ type VirtualSession struct {
sessionId string
userId string
userData *json.RawMessage
userData json.RawMessage
inCall Flags
flags Flags
options *AddSessionOptions
@ -133,7 +133,7 @@ func (s *VirtualSession) UserId() string {
return s.userId
}
func (s *VirtualSession) UserData() *json.RawMessage {
func (s *VirtualSession) UserData() json.RawMessage {
return s.userData
}
@ -304,7 +304,7 @@ func (s *VirtualSession) ProcessAsyncSessionMessage(message *AsyncMessage) {
SessionId: s.SessionId(),
UserId: s.UserId(),
},
Data: (*json.RawMessage)(&data),
Data: data,
},
},
})

View file

@ -40,7 +40,7 @@ func TestVirtualSession(t *testing.T) {
id: "compat",
compat: true,
}
room, err := hub.createRoom(roomId, &emptyProperties, backend)
room, err := hub.createRoom(roomId, emptyProperties, backend)
if err != nil {
t.Fatalf("Could not create room: %s", err)
}
@ -285,7 +285,7 @@ func TestVirtualSession(t *testing.T) {
}
var payload string
if err := json.Unmarshal(*msg2.Message.Data, &payload); err != nil {
if err := json.Unmarshal(msg2.Message.Data, &payload); err != nil {
t.Error(err)
} else if payload != data {
t.Errorf("Expected payload %s, got %s", data, payload)
@ -350,7 +350,7 @@ func TestVirtualSessionCustomInCall(t *testing.T) {
id: "compat",
compat: true,
}
room, err := hub.createRoom(roomId, &emptyProperties, backend)
room, err := hub.createRoom(roomId, emptyProperties, backend)
if err != nil {
t.Fatalf("Could not create room: %s", err)
}
@ -583,7 +583,7 @@ func TestVirtualSessionCleanup(t *testing.T) {
id: "compat",
compat: true,
}
room, err := hub.createRoom(roomId, &emptyProperties, backend)
room, err := hub.createRoom(roomId, emptyProperties, backend)
if err != nil {
t.Fatalf("Could not create room: %s", err)
}