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/common/src/enums/websocket-message-type.ts b/common/src/enums/websocket-message-type.ts
index 1152101..04a1f90 100644
--- a/common/src/enums/websocket-message-type.ts
+++ b/common/src/enums/websocket-message-type.ts
@@ -18,11 +18,11 @@
export enum WebSocketMessageType {
ConversationMessage = 'conversation-message',
ConversationView = 'conversation-view',
- WebRTCOffer = 'webrtc-offer',
- WebRTCAnswer = 'webrtc-answer',
- IceCandidate = 'ice-candidate',
CallBegin = 'call-begin',
CallAccept = 'call-accept',
CallRefuse = 'call-refuse',
CallEnd = 'call-end',
+ WebRtcOffer = 'webrtc-offer',
+ WebRtcAnswer = 'webrtc-answer',
+ WebRtcIceCandidate = 'webrtc-ice-candidate',
}
diff --git a/common/src/index.ts b/common/src/index.ts
index 3fb02d1..9c36a37 100644
--- a/common/src/index.ts
+++ b/common/src/index.ts
@@ -21,8 +21,6 @@
export * from './Conversation.js';
export * from './enums/http-status-code.js';
export * from './enums/websocket-message-type.js';
-export * from './interfaces/account-text-message.js';
export * from './interfaces/websocket-interfaces.js';
export * from './interfaces/websocket-message.js';
-export * from './types/websocket-callbacks.js';
export * from './util.js';
diff --git a/common/src/interfaces/account-text-message.ts b/common/src/interfaces/account-text-message.ts
deleted file mode 100644
index 68eea24..0000000
--- a/common/src/interfaces/account-text-message.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2022 Savoir-faire Linux Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation; either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this program. If not, see
- * <https://www.gnu.org/licenses/>.
- */
-export interface AccountTextMessage<T> {
- from: string;
- to: string;
- message: T;
-}
diff --git a/common/src/interfaces/websocket-interfaces.ts b/common/src/interfaces/websocket-interfaces.ts
index 2c6a109..c4d6b0b 100644
--- a/common/src/interfaces/websocket-interfaces.ts
+++ b/common/src/interfaces/websocket-interfaces.ts
@@ -17,24 +17,27 @@
*/
import { Message } from '../Conversation.js';
+export interface ContactMessage {
+ contactId: string;
+}
+
export interface ConversationMessage {
conversationId: string;
message: Message;
}
export interface ConversationView {
- accountId: string;
conversationId: string;
}
-export interface WebRtcSdp {
+export interface CallAction extends ContactMessage {
+ conversationId: string;
+}
+
+export interface WebRtcSdp extends ContactMessage {
sdp: RTCSessionDescriptionInit;
}
-export interface WebRTCIceCandidate {
+export interface WebRtcIceCandidate extends ContactMessage {
candidate: RTCIceCandidate;
}
-
-export interface CallBegin {
- conversationId: string;
-}
diff --git a/common/src/interfaces/websocket-message.ts b/common/src/interfaces/websocket-message.ts
index ff1de98..a431fcc 100644
--- a/common/src/interfaces/websocket-message.ts
+++ b/common/src/interfaces/websocket-message.ts
@@ -16,25 +16,24 @@
* <https://www.gnu.org/licenses/>.
*/
import { WebSocketMessageType } from '../enums/websocket-message-type.js';
-import { AccountTextMessage } from './account-text-message.js';
import {
- CallBegin,
+ CallAction,
ConversationMessage,
ConversationView,
- WebRTCIceCandidate,
+ WebRtcIceCandidate,
WebRtcSdp,
} from './websocket-interfaces.js';
export interface WebSocketMessageTable {
[WebSocketMessageType.ConversationMessage]: ConversationMessage;
[WebSocketMessageType.ConversationView]: ConversationView;
- [WebSocketMessageType.WebRTCOffer]: AccountTextMessage<WebRtcSdp>;
- [WebSocketMessageType.WebRTCAnswer]: AccountTextMessage<WebRtcSdp>;
- [WebSocketMessageType.IceCandidate]: AccountTextMessage<WebRTCIceCandidate>;
- [WebSocketMessageType.CallBegin]: AccountTextMessage<CallBegin>;
- [WebSocketMessageType.CallAccept]: AccountTextMessage<undefined>;
- [WebSocketMessageType.CallRefuse]: AccountTextMessage<undefined>;
- [WebSocketMessageType.CallEnd]: AccountTextMessage<undefined>;
+ [WebSocketMessageType.CallBegin]: CallAction;
+ [WebSocketMessageType.CallAccept]: CallAction;
+ [WebSocketMessageType.CallRefuse]: CallAction;
+ [WebSocketMessageType.CallEnd]: CallAction;
+ [WebSocketMessageType.WebRtcOffer]: WebRtcSdp;
+ [WebSocketMessageType.WebRtcAnswer]: WebRtcSdp;
+ [WebSocketMessageType.WebRtcIceCandidate]: WebRtcIceCandidate;
}
export interface WebSocketMessage<T extends WebSocketMessageType> {
diff --git a/common/src/types/websocket-callbacks.ts b/common/src/types/websocket-callbacks.ts
deleted file mode 100644
index 366bfee..0000000
--- a/common/src/types/websocket-callbacks.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2022 Savoir-faire Linux Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation; either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this program. If not, see
- * <https://www.gnu.org/licenses/>.
- */
-
-import { WebSocketMessageType } from '../enums/websocket-message-type.js';
-import { WebSocketMessageTable } from '../interfaces/websocket-message.js';
-
-export type WebSocketCallback<T extends WebSocketMessageType> = (data: WebSocketMessageTable[T]) => void;
-
-export type WebSocketCallbacks = {
- [key in WebSocketMessageType]: Set<WebSocketCallback<key>>;
-};
-
-export const buildWebSocketCallbacks = (): WebSocketCallbacks => {
- const webSocketCallback = {} as WebSocketCallbacks;
- for (const type of Object.values(WebSocketMessageType)) {
- webSocketCallback[type] = new Set<WebSocketCallback<typeof type>>();
- }
-
- return webSocketCallback;
-};