Refactor WebSocket message interfaces
Changes:
- Replace AccountTextMessage with an extendable ContactMessage interface
- Add accountId parameter to server-side WebSocket callbacks
- Set the accountId for WebRTC messages on server-side for security
- Rename all WebRTC and SDP variables to proper camelCase or PascalCase
GitLab: #147
Change-Id: I125b5431821b03ef4d46b751eb1c13830017ccff
diff --git a/client/src/contexts/ConversationProvider.tsx b/client/src/contexts/ConversationProvider.tsx
index 89fb450..a282664 100644
--- a/client/src/contexts/ConversationProvider.tsx
+++ b/client/src/contexts/ConversationProvider.tsx
@@ -15,7 +15,7 @@
* License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
-import { Conversation, WebSocketMessageType } from 'jami-web-common';
+import { CallAction, Conversation, ConversationView, WebSocketMessageType } from 'jami-web-common';
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
@@ -40,7 +40,7 @@
const {
urlParams: { conversationId },
} = useUrlParams<ConversationRouteParams>();
- const { account, accountId } = useAuthContext();
+ const { accountId } = useAuthContext();
const webSocket = useContext(WebSocketContext);
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
@@ -69,14 +69,12 @@
throw new Error('Could not begin call');
}
- // TODO: Could we move this logic to the server? The client could make a single request with the conversationId, and the server is tasked with sending all the individual requests to the members of the conversation
+ // TODO: Could we move this logic to the server? The client could make a single request with the conversationId,
+ // and the server is tasked with sending all the individual requests to the members of the conversation
for (const member of conversation.getMembers()) {
- const callBegin = {
- from: account.getId(),
- to: member.contact.getUri(),
- message: {
- conversationId,
- },
+ const callBegin: CallAction = {
+ contactId: member.contact.getUri(),
+ conversationId,
};
console.info('Sending CallBegin', callBegin);
@@ -84,13 +82,18 @@
}
navigate(`/conversation/${conversationId}/call?role=caller`);
- }, [conversationId, webSocket, conversation, account, navigate]);
+ }, [conversationId, webSocket, conversation, navigate]);
useEffect(() => {
if (!conversation || !webSocket) {
return;
}
- webSocket.send(WebSocketMessageType.ConversationView, { accountId, conversationId });
+
+ const conversationView: ConversationView = {
+ conversationId,
+ };
+
+ webSocket.send(WebSocketMessageType.ConversationView, conversationView);
}, [accountId, conversation, conversationId, webSocket]);
if (isLoading) {