关于录屏相关的消息格式需要封一层,放在on-message下,利用on-message传递
This commit is contained in:
@@ -43,6 +43,89 @@ function createWebSocketSignaling(port) {
|
||||
return new WebSocketSignaling(1, `ws://localhost:${port}`);
|
||||
}
|
||||
|
||||
describe('recording signaling message envelope', () => {
|
||||
const OriginalWebSocket = window.WebSocket;
|
||||
let sentMessages;
|
||||
|
||||
beforeEach(() => {
|
||||
sentMessages = [];
|
||||
window.WebSocket = class {
|
||||
constructor() {
|
||||
this.readyState = 1;
|
||||
}
|
||||
|
||||
send(message) {
|
||||
sentMessages.push(message);
|
||||
}
|
||||
|
||||
close() {
|
||||
if (this.onclose) {
|
||||
this.onclose();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
window.WebSocket = OriginalWebSocket;
|
||||
});
|
||||
|
||||
test('sends recording offer through on-message', () => {
|
||||
const signaling = new WebSocketSignaling(1, 'ws://localhost:1234');
|
||||
|
||||
signaling.sendRecordingOffer({
|
||||
recordingId: 'recording-1',
|
||||
connectionId: 'room-1',
|
||||
participantId: 'participant-1',
|
||||
sdp: 'offer-sdp'
|
||||
});
|
||||
|
||||
expect(sentMessages).toHaveLength(1);
|
||||
const outer = JSON.parse(sentMessages[0]);
|
||||
expect(outer.type).toBe('on-message');
|
||||
expect(outer.data.connectionId).toBe('room-1');
|
||||
expect(outer.data.message).toEqual({
|
||||
type: 'recording-offer',
|
||||
data: {
|
||||
recordingId: 'recording-1',
|
||||
connectionId: 'room-1',
|
||||
participantId: 'participant-1',
|
||||
sdp: 'offer-sdp'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('dispatches wrapped recording messages as recording events', () => {
|
||||
const signaling = new WebSocketSignaling(1, 'ws://localhost:1234');
|
||||
let recordingAnswer;
|
||||
signaling.addEventListener('recording-answer', (event) => {
|
||||
recordingAnswer = event.detail;
|
||||
});
|
||||
|
||||
signaling.websocket.onmessage({
|
||||
data: JSON.stringify({
|
||||
type: 'on-message',
|
||||
from: 'room-1',
|
||||
data: JSON.stringify({
|
||||
type: 'recording-answer',
|
||||
data: {
|
||||
recordingId: 'recording-1',
|
||||
connectionId: 'room-1',
|
||||
sdp: 'answer-sdp'
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
expect(recordingAnswer).toEqual({
|
||||
type: 'recording-answer',
|
||||
recordingId: 'recording-1',
|
||||
connectionId: 'room-1',
|
||||
sdp: 'answer-sdp'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.each(signalingModes)('signaling test in public mode', ({ mode }) => {
|
||||
let signaling1;
|
||||
let signaling2;
|
||||
|
||||
Reference in New Issue
Block a user