Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump follow-redirects from 1.15.2 to 1.15.5 #291

Closed
Closed
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
417f51c
Outside of browser environment
sirknightj Oct 1, 2023
65a9336
Remove Buffer
sirknightj Oct 1, 2023
64db67d
Remove unnecessary import
sirknightj Oct 2, 2023
f46cdef
Increase max package size
sirknightj Oct 2, 2023
8c1b74f
Remove _
sirknightj Oct 2, 2023
23a7aaf
Add options allowing for fine-grained control of sending and receivin…
sirknightj Sep 29, 2023
056a65c
Add description
sirknightj Sep 29, 2023
f1cf7c3
Add presets
sirknightj Sep 29, 2023
0bfdf83
Fix wrong method name
sirknightj Sep 29, 2023
fe9e9da
Remove debugging artifacts
sirknightj Sep 29, 2023
8898e8f
Remove extra newlines
sirknightj Sep 29, 2023
3440d1a
Extract to common method
sirknightj Oct 2, 2023
bbac099
sample: Add manual JoinStorageSession button
sirknightj Sep 1, 2023
ad145b0
sample: Adjust labels
sirknightj Sep 1, 2023
b44510d
master role
sirknightj Sep 1, 2023
04210b7
sample: move the connected check to after the SDP answer is sent
sirknightj Sep 1, 2023
d6857c4
Add correlationId to sdp answer for joinStorageSession
sirknightj Oct 11, 2023
44e6cd1
100% code coverage in the unit tests
sirknightj Oct 11, 2023
444dd88
Increase package size
sirknightj Oct 11, 2023
5095d53
Remove testing artifact
sirknightj Oct 11, 2023
21345ab
Update README for correlationId
sirknightj Oct 12, 2023
e70cde0
Fix boolean flag
sirknightj Oct 18, 2023
7930faf
Adjust css
sirknightj Oct 18, 2023
98a0964
Disable datachannel for WebRTC ingestion and remove remote-view in in…
sirknightj Oct 18, 2023
2722dd3
Adjust stop button color
sirknightj Oct 18, 2023
d779af5
reset storage client on next run
sirknightj Oct 18, 2023
ea91633
reset storage client on next run
sirknightj Oct 18, 2023
8bd81dd
Adjust comment for correlationId
sirknightj Oct 19, 2023
d4b5469
Bump @babel/traverse from 7.21.4 to 7.23.2
dependabot[bot] Oct 19, 2023
0f9aefc
Bump react-devtools-core from 4.27.6 to 4.28.4
dependabot[bot] Oct 21, 2023
69ca654
Bump version
sirknightj Nov 7, 2023
fb1d4a3
Bump package lock
sirknightj Nov 7, 2023
a71746b
Bump follow-redirects from 1.15.2 to 1.15.5
dependabot[bot] Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add correlationId to sdp answer for joinStorageSession
sirknightj committed Nov 7, 2023
commit d6857c48af1100d2e007ca2e1fc35db6df984889
4 changes: 4 additions & 0 deletions examples/app.js
Original file line number Diff line number Diff line change
@@ -615,6 +615,10 @@ function shouldSendIceCandidate(formValues, candidate) {
}
}

function randomString() {
return Date.now().toString();
}

function extractTransportAndType(candidate) {
const words = candidate.candidate.split(' ');

21 changes: 16 additions & 5 deletions examples/master.js
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ async function startMaster(localView, remoteView, formValues, onStatsReport, onR
if (mediaServiceMode) {
if (!formValues.sendAudio || !formValues.sendVideo) {
console.error('[MASTER] Both Send Video and Send Audio checkboxes need to be checked to ingest and store media.');
return;
// return;
}
protocols.push('WEBRTC');
master.streamARN = mediaStorageConfiguration.StreamARN;
@@ -278,8 +278,9 @@ async function startMaster(localView, remoteView, formValues, onStatsReport, onR
// When trickle ICE is disabled, send the answer now that all the ICE candidates have ben generated.
if (!formValues.useTrickleICE) {
printSignalingLog('[MASTER] Sending SDP answer to client', remoteClientId);
console.debug('SDP answer:', peerConnection.localDescription);
master.signalingClient.sendSdpAnswer(peerConnection.localDescription, remoteClientId);
const correlationId = randomString();
console.debug('SDP answer:', peerConnection.localDescription, 'correlationId:', correlationId);
master.signalingClient.sendSdpAnswer(peerConnection.localDescription, remoteClientId, correlationId);
}
}
});
@@ -308,8 +309,9 @@ async function startMaster(localView, remoteView, formValues, onStatsReport, onR
// When trickle ICE is enabled, send the answer now and then send ICE candidates as they are generated. Otherwise wait on the ICE candidates.
if (formValues.useTrickleICE) {
printSignalingLog('[MASTER] Sending SDP answer to client', remoteClientId);
console.debug('SDP answer:', peerConnection.localDescription);
master.signalingClient.sendSdpAnswer(peerConnection.localDescription, remoteClientId);
const correlationId = randomString();
console.debug('SDP answer:', peerConnection.localDescription, 'correlationId:', correlationId);
master.signalingClient.sendSdpAnswer(peerConnection.localDescription, remoteClientId, correlationId);
}
printSignalingLog('[MASTER] Generating ICE candidates for client', remoteClientId);

@@ -343,6 +345,15 @@ async function startMaster(localView, remoteView, formValues, onStatsReport, onR
}
});

master.signalingClient.on('statusResponse', (statusResponse, senderClientId) => {
console.error('[MASTER] Received response from Signaling:', statusResponse, senderClientId || '(no senderClientId provided)');

if (master.streamARN) {
console.error('[MASTER] Encountered a fatal error. Stopping the application.');
onStop();
}
});

master.signalingClient.on('close', () => {
master.websocketOpened = false;
master.runId++;
56 changes: 47 additions & 9 deletions src/SignalingClient.ts
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ enum MessageType {
SDP_ANSWER = 'SDP_ANSWER',
SDP_OFFER = 'SDP_OFFER',
ICE_CANDIDATE = 'ICE_CANDIDATE',
STATUS_RESPONSE = 'STATUS_RESPONSE',
}

enum ReadyState {
@@ -46,6 +47,14 @@ interface WebSocketMessage {
messageType: MessageType;
messagePayload: string;
senderClientId?: string;
statusResponse?: StatusResponse;
}

interface StatusResponse {
correlationId: 'string';
errorType: 'string';
statusCode: 'string';
description: 'string';
}

/**
@@ -165,9 +174,11 @@ export class SignalingClient extends EventEmitter {
* Typically, only the 'VIEWER' role should send an SDP offer.
* @param {RTCSessionDescription} sdpOffer - SDP offer to send.
* @param {string} [recipientClientId] - ID of the client to send the message to. Required for 'MASTER' role. Should not be present for 'VIEWER' role.
* @param {string} [correlationId] - Unique ID for this message. If this is present and there is an error,
* Signaling will send a StatusResponse message describing the error. If this is not present, no error will be returned.
*/
public sendSdpOffer(sdpOffer: RTCSessionDescription, recipientClientId?: string): void {
this.sendMessage(MessageType.SDP_OFFER, sdpOffer, recipientClientId);
public sendSdpOffer(sdpOffer: RTCSessionDescription, recipientClientId?: string, correlationId?: string): void {
this.sendMessage(MessageType.SDP_OFFER, sdpOffer, recipientClientId, correlationId);
}

/**
@@ -176,9 +187,11 @@ export class SignalingClient extends EventEmitter {
* Typically, only the 'MASTER' role should send an SDP answer.
* @param {RTCSessionDescription} sdpAnswer - SDP answer to send.
* @param {string} [recipientClientId] - ID of the client to send the message to. Required for 'MASTER' role. Should not be present for 'VIEWER' role.
* @param {string} [correlationId] - Unique ID for this message. If this is present and there is an error,
* Signaling will send a StatusResponse message describing the error. If this is not present, no error will be returned.
*/
public sendSdpAnswer(sdpAnswer: RTCSessionDescription, recipientClientId?: string): void {
this.sendMessage(MessageType.SDP_ANSWER, sdpAnswer, recipientClientId);
public sendSdpAnswer(sdpAnswer: RTCSessionDescription, recipientClientId?: string, correlationId?: string): void {
this.sendMessage(MessageType.SDP_ANSWER, sdpAnswer, recipientClientId, correlationId);
}

/**
@@ -187,26 +200,30 @@ export class SignalingClient extends EventEmitter {
* Typically, both the 'VIEWER' role and 'MASTER' role should send ICE candidates.
* @param {RTCIceCandidate} iceCandidate - ICE candidate to send.
* @param {string} [recipientClientId] - ID of the client to send the message to. Required for 'MASTER' role. Should not be present for 'VIEWER' role.
* @param {string} [correlationId] - Unique ID for this message. If this is present and there is an error,
* Signaling will send a StatusResponse message describing the error. If this is not present, no error will be returned.
*/
public sendIceCandidate(iceCandidate: RTCIceCandidate, recipientClientId?: string): void {
this.sendMessage(MessageType.ICE_CANDIDATE, iceCandidate, recipientClientId);
public sendIceCandidate(iceCandidate: RTCIceCandidate, recipientClientId?: string, correlationId?: string): void {
this.sendMessage(MessageType.ICE_CANDIDATE, iceCandidate, recipientClientId, correlationId);
}

/**
* Validates the WebSocket connection is open and that the recipient client id is present if sending as the 'MASTER'. Encodes the given message payload
* and sends the message to the signaling service.
*/
private sendMessage(action: MessageType, messagePayload: object, recipientClientId?: string): void {
private sendMessage(action: MessageType, messagePayload: object, recipientClientId?: string, correlationId?: string): void {
if (this.readyState !== ReadyState.OPEN) {
throw new Error('Could not send message because the connection to the signaling service is not open.');
}
this.validateRecipientClientId(recipientClientId);
this.validateCorrelationId(correlationId);

this.websocket.send(
JSON.stringify({
action,
messagePayload: SignalingClient.serializeJSONObjectAsBase64String(messagePayload),
recipientClientId: recipientClientId || undefined,
correlationId: correlationId || undefined,
}),
);
}
@@ -241,13 +258,22 @@ export class SignalingClient extends EventEmitter {
let parsedMessagePayload: object;
try {
parsedEventData = JSON.parse(event.data) as WebSocketMessage;
parsedMessagePayload = SignalingClient.parseJSONObjectFromBase64String(parsedEventData.messagePayload);
} catch (e) {
// For forwards compatibility we ignore messages that are not able to be parsed.
// TODO: Consider how to make it easier for users to be aware of dropped messages.
return;
}
const { messageType, senderClientId } = parsedEventData;
try {
parsedMessagePayload = SignalingClient.parseJSONObjectFromBase64String(parsedEventData.messagePayload);
} catch (e) {
// TODO: Consider how to make it easier for users to be aware of dropped messages.
}
const { messageType, senderClientId, statusResponse } = parsedEventData;
if (!parsedMessagePayload && !statusResponse) {
// TODO: Consider how to make it easier for users to be aware of dropped messages.
return;
}

switch (messageType) {
case MessageType.SDP_OFFER:
this.emit('sdpOffer', parsedMessagePayload, senderClientId);
@@ -260,6 +286,9 @@ export class SignalingClient extends EventEmitter {
case MessageType.ICE_CANDIDATE:
this.emitOrQueueIceCandidate(parsedMessagePayload, senderClientId);
return;
case MessageType.STATUS_RESPONSE:
this.emit('statusResponse', statusResponse, senderClientId);
return;
}
}

@@ -326,6 +355,15 @@ export class SignalingClient extends EventEmitter {
}
}

/**
* Throws an error if the recipient client id is null and the current role is 'MASTER' as all messages sent as 'MASTER' should have a recipient client id.
*/
private validateCorrelationId(correlationId?: string): void {
if (correlationId && !/^[a-zA-Z0-9_.-]{1,256}$/.test(correlationId)) {
throw new Error('Correlation id does not fit the constraint!');
}
}

/**
* 'error' event handler. Forwards the error onto listeners.
*/