Skip to content

Commit a5ffa65

Browse files
author
Mustafa BOLEKEN
authored
Merge branch 'master' into addPaginationMechanism
2 parents 69cd8a0 + 1561586 commit a5ffa65

File tree

5 files changed

+198
-77
lines changed

5 files changed

+198
-77
lines changed

pom.xml

+7-14
Original file line numberDiff line numberDiff line change
@@ -234,47 +234,40 @@
234234
<dependency>
235235
<groupId>org.springframework.security</groupId>
236236
<artifactId>spring-security-core</artifactId>
237-
<version>6.2.0</version>
237+
<scope>provided</scope>
238238
</dependency>
239239
<dependency>
240240
<groupId>org.springframework.security</groupId>
241241
<artifactId>spring-security-config</artifactId>
242-
<version>6.2.0</version>
242+
<scope>provided</scope>
243243
</dependency>
244244
<dependency>
245245
<groupId>org.springframework.security</groupId>
246246
<artifactId>spring-security-web</artifactId>
247-
<version>6.2.0</version>
247+
<scope>provided</scope>
248248
</dependency>
249249
<dependency>
250250
<groupId>org.springframework.security</groupId>
251251
<artifactId>spring-security-crypto</artifactId>
252-
<version>6.2.0</version>
252+
<scope>provided</scope>
253253
</dependency>
254254
<dependency>
255255
<groupId>org.springframework.security</groupId>
256256
<artifactId>spring-security-oauth2-authorization-server</artifactId>
257-
<version>1.1.6</version>
257+
<scope>provided</scope>
258258
</dependency>
259259

260260

261-
262-
263261
<!-- OAuth2 dependencies -->
264-
<dependency>
265-
<groupId>org.springframework.security.oauth</groupId>
266-
<artifactId>spring-security-oauth2</artifactId>
267-
<version>2.5.2.RELEASE</version>
268-
</dependency>
269262
<dependency>
270263
<groupId>org.springframework.security</groupId>
271264
<artifactId>spring-security-oauth2-client</artifactId>
272-
<version>6.2.0</version>
265+
<scope>provided</scope>
273266
</dependency>
274267
<dependency>
275268
<groupId>org.springframework.security</groupId>
276269
<artifactId>spring-security-oauth2-jose</artifactId>
277-
<version>6.2.0</version>
270+
<scope>provided</scope>
278271
</dependency>
279272

280273
<dependency>

src/main/js/webrtc_adaptor.js

+80-56
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ export class WebRTCAdaptor {
358358
* This is the time info for the last reconnection attempt
359359
*/
360360
this.lastReconnectiontionTrialTime = 0;
361+
362+
/**
363+
* TimerId for the pending try again call
364+
*/
365+
this.pendingTryAgainTimerId = -1;
361366

362367
/**
363368
* All media management works for teh local stream are made by @MediaManager class.
@@ -516,15 +521,8 @@ export class WebRTCAdaptor {
516521
}
517522
//init peer connection for reconnectIfRequired
518523
this.initPeerConnection(streamId, "publish");
519-
setTimeout(() => {
520-
//check if it is connected or not
521-
//this resolves if the server responds with some error message
522-
if (this.iceConnectionState(this.publishStreamId) != "checking" && this.iceConnectionState(this.publishStreamId) != "connected" && this.iceConnectionState(this.publishStreamId) != "completed") {
523-
//if it is not connected, try to reconnect
524-
this.reconnectIfRequired(0);
525-
}
526-
}, 3000);
527-
524+
525+
this.reconnectIfRequired(3000, false);
528526
}
529527

530528
sendPublishCommand(streamId, token, subscriberId, subscriberCode, streamName, mainTrack, metaData, role, videoEnabled, audioEnabled) {
@@ -605,43 +603,44 @@ export class WebRTCAdaptor {
605603

606604
//init peer connection for reconnectIfRequired
607605
this.initPeerConnection(streamId, "play");
608-
609-
setTimeout(() => {
610-
//check if it is connected or not
611-
//this resolves if the server responds with some error message
612-
if (this.iceConnectionState(streamId) != "checking" &&
613-
this.iceConnectionState(streamId) != "connected" &&
614-
this.iceConnectionState(streamId) != "completed") {
615-
//if it is not connected, try to reconnect
616-
this.reconnectIfRequired(0);
617-
}
618-
}, 3000);
606+
this.reconnectIfRequired(3000, false);
619607
}
620608

621609
/**
622610
* Reconnects to the stream if it is not stopped on purpose
623611
* @param {number} [delayMs]
624612
* @returns
625613
*/
626-
reconnectIfRequired(delayMs = 3000) {
614+
reconnectIfRequired(delayMs = 3000, forceReconnect = false) {
627615
if (this.reconnectIfRequiredFlag) {
628-
//It's important to run the following methods after 3000 ms because the stream may be stopped by the user in the meantime
629-
if (delayMs > 0) {
630-
setTimeout(() => {
631-
this.tryAgain();
632-
}, delayMs);
616+
if (delayMs <= 0) {
617+
delayMs = 500;
618+
//clear the timer because there is a demand to reconnect without delay
619+
clearTimeout(this.pendingTryAgainTimerId);
620+
this.pendingTryAgainTimerId = -1;
633621
}
634-
else {
635-
this.tryAgain()
622+
623+
if (this.pendingTryAgainTimerId == -1)
624+
{
625+
this.pendingTryAgainTimerId = setTimeout(() =>
626+
{
627+
this.pendingTryAgainTimerId = -1;
628+
this.tryAgain(forceReconnect);
629+
},
630+
delayMs);
636631
}
637632
}
638633
}
639634

640-
tryAgain() {
635+
tryAgain(forceReconnect) {
641636

642637
const now = Date.now();
643638
//to prevent too many trial from different paths
644-
if (now - this.lastReconnectiontionTrialTime < 3000) {
639+
const timeDiff = now - this.lastReconnectiontionTrialTime;;
640+
if (timeDiff < 3000 && forceReconnect == false) {
641+
//check again 1 seconds later if it is not stopped on purpose
642+
Logger.debug("Reconnection request received after "+ timeDiff+" ms. It should be at least 3000ms. It will try again after 1000ms");
643+
this.reconnectIfRequired(1000, forceReconnect);
645644
return;
646645
}
647646
this.lastReconnectiontionTrialTime = now;
@@ -650,10 +649,10 @@ export class WebRTCAdaptor {
650649
//if remotePeerConnection has a peer connection for the stream id, it means that it is not stopped on purpose
651650

652651
if (this.remotePeerConnection[this.publishStreamId] != null &&
652+
(forceReconnect ||
653653
//check connection status to not stop streaming an active stream
654-
this.iceConnectionState(this.publishStreamId) != "checking" &&
655-
this.iceConnectionState(this.publishStreamId) != "connected" &&
656-
this.iceConnectionState(this.publishStreamId) != "completed") {
654+
["checking", "connected", "completed"].indexOf(this.iceConnectionState(this.publishStreamId)) === -1)
655+
) {
657656
// notify that reconnection process started for publish
658657
this.notifyEventListeners("reconnection_attempt_for_publisher", this.publishStreamId);
659658

@@ -669,11 +668,12 @@ export class WebRTCAdaptor {
669668
//reconnect play
670669
for (var index in this.playStreamId) {
671670
let streamId = this.playStreamId[index];
672-
if (this.remotePeerConnection[streamId] != "null" &&
673-
//check connection status to not stop streaming an active stream
674-
this.iceConnectionState(streamId) != "checking" &&
675-
this.iceConnectionState(streamId) != "connected" &&
676-
this.iceConnectionState(streamId) != "completed") {
671+
if (this.remotePeerConnection[streamId] != null &&
672+
(forceReconnect ||
673+
//check connection status to not stop streaming an active stream
674+
["checking", "connected", "completed"].indexOf(this.iceConnectionState(streamId)) === -1
675+
)
676+
) {
677677
// notify that reconnection process started for play
678678
this.notifyEventListeners("reconnection_attempt_for_player", streamId);
679679

@@ -1152,27 +1152,38 @@ export class WebRTCAdaptor {
11521152

11531153
this.remotePeerConnection[streamId].oniceconnectionstatechange = event => {
11541154
var obj = { state: this.remotePeerConnection[streamId].iceConnectionState, streamId: streamId };
1155-
if (obj.state == "failed" || obj.state == "disconnected" || obj.state == "closed") {
1156-
this.reconnectIfRequired(3000);
1157-
}
1158-
this.notifyEventListeners("ice_connection_state_changed", obj);
1159-
1160-
//
1161-
if (!this.isPlayMode && !this.playStreamId.includes(streamId)) {
1162-
if (this.remotePeerConnection[streamId].iceConnectionState == "connected") {
11631155

1164-
this.mediaManager.changeBandwidth(this.mediaManager.bandwidth, streamId).then(() => {
1165-
Logger.debug("Bandwidth is changed to " + this.mediaManager.bandwidth);
1166-
})
1167-
.catch(e => Logger.warn(e));
1168-
}
1169-
}
1156+
this.oniceconnectionstatechangeCallback(obj);
11701157
}
11711158

11721159
}
11731160

11741161
return this.remotePeerConnection[streamId];
11751162
}
1163+
1164+
oniceconnectionstatechangeCallback(obj)
1165+
{
1166+
Logger.debug("ice connection state is " +obj.state + " for streamId: " + obj.streamId);
1167+
if (obj.state == "failed" || obj.state == "disconnected" || obj.state == "closed") {
1168+
//try immediately
1169+
Logger.debug("ice connection state is failed, disconnected or closed for streamId: " + obj.streamId + " it will try to reconnect immediately");
1170+
this.reconnectIfRequired(0, false);
1171+
}
1172+
this.notifyEventListeners("ice_connection_state_changed", obj);
1173+
1174+
//
1175+
if (!this.isPlayMode && !this.playStreamId.includes(obj.streamId)) {
1176+
if (this.remotePeerConnection[obj.streamId] != null && this.remotePeerConnection[obj.streamId].iceConnectionState == "connected") {
1177+
1178+
this.mediaManager.changeBandwidth(this.mediaManager.bandwidth, obj.streamId).then(() => {
1179+
Logger.debug("Bandwidth is changed to " + this.mediaManager.bandwidth);
1180+
})
1181+
.catch(e => Logger.warn(e));
1182+
}
1183+
}
1184+
}
1185+
1186+
11761187

11771188
/**
11781189
* Called internally to close PeerConnection.
@@ -1761,10 +1772,7 @@ export class WebRTCAdaptor {
17611772
websocket_url: this.websocketURL,
17621773
webrtcadaptor: this,
17631774
callback: (info, obj) => {
1764-
if (info == "closed") {
1765-
this.reconnectIfRequired();
1766-
}
1767-
this.notifyEventListeners(info, obj);
1775+
this.websocketCallback(info, obj)
17681776
},
17691777
callbackError: (error, message) => {
17701778
this.notifyErrorEventListeners(error, message)
@@ -1773,6 +1781,22 @@ export class WebRTCAdaptor {
17731781
});
17741782
}
17751783
}
1784+
1785+
websocketCallback(info, obj) {
1786+
1787+
if (info == "closed" || info == "server_will_stop") {
1788+
Logger.info("Critical response from server:"+ info +". It will reconnect immediately if there is an active connection");
1789+
1790+
//close websocket reconnect again
1791+
if (info == "server_will_stop") {
1792+
this.webSocketAdaptor.close();
1793+
}
1794+
//try with forcing reconnect because webrtc will be closed as well
1795+
this.reconnectIfRequired(0, true);
1796+
}
1797+
1798+
this.notifyEventListeners(info, obj);
1799+
}
17761800

17771801
/**
17781802
* Called to stop Web Socket connection

src/main/webapp/conference.html

+7-6
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,12 @@ <h3 class="col text-muted">WebRTC Multitrack Conference</h3>
687687
var state = webRTCAdaptor
688688
.signallingState(publishStreamId);
689689
if (state != null
690-
&& state != "closed") {
690+
&& state != "closed")
691+
{
691692
var iceState = webRTCAdaptor
692693
.iceConnectionState(publishStreamId);
693-
if (iceState != null
694-
&& iceState != "failed"
695-
&& iceState != "disconnected") {
694+
if (iceState != null && iceState != "new" && iceState != "closed" && iceState != "failed" && iceState != "disconnected")
695+
{
696696
startAnimation();
697697
}
698698
}
@@ -864,10 +864,11 @@ <h3 class="col text-muted">WebRTC Multitrack Conference</h3>
864864
}
865865
else {
866866
//errorHandler(error, message);
867-
$('video').notify("Warning: " + errorHandler(error, message), {
867+
868+
$('#roomName').notify("Warning: " + errorHandler(error, message), {
868869
autoHideDelay: 5000,
869870
className: 'error',
870-
position: 'top right'
871+
position: 'top center'
871872
});
872873
}
873874

src/main/webapp/samples/publish_webrtc.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@
490490
var state = webRTCAdaptor.signallingState(streamId);
491491
if (state != null && state != "closed") {
492492
var iceState = webRTCAdaptor.iceConnectionState(streamId);
493-
if (iceState != null && iceState != "failed" && iceState != "disconnected") {
493+
if (iceState != null && iceState != "new" && iceState != "closed" && iceState != "failed" && iceState != "disconnected") {
494494
startAnimation();
495495
}
496496
else {

0 commit comments

Comments
 (0)