@@ -162,6 +162,12 @@ export class WebRTCAdaptor {
162
162
*/
163
163
this . debug = false ;
164
164
165
+ /**
166
+ * This is the flag to indicate if the stream is published or not after the connection fails
167
+ * @type {boolean }
168
+ */
169
+ this . iceRestart = false ;
170
+
165
171
/**
166
172
* This is the Stream Id for the publisher. One @WebRCTCAdaptor supports only one publishing
167
173
* session for now (23.02.2022).
@@ -1092,8 +1098,18 @@ export class WebRTCAdaptor {
1092
1098
this . onTrack ( event , closedStreamId ) ;
1093
1099
}
1094
1100
1095
- this . remotePeerConnection [ streamId ] . onnegotiationneeded = event => {
1101
+ this . remotePeerConnection [ streamId ] . onnegotiationneeded = async event => {
1096
1102
Logger . debug ( "onnegotiationneeded" ) ;
1103
+ //If ice restart is not true, then server will handle negotiation
1104
+ if ( ! this . iceRestart ) {
1105
+ return ;
1106
+ }
1107
+ try {
1108
+ await this . remotePeerConnection [ streamId ] . setLocalDescription ( await this . remotePeerConnection [ streamId ] . createOffer ( { iceRestart : this . iceRestart } ) ) ;
1109
+ this . webSocketAdaptor . send ( { desc : this . remotePeerConnection [ streamId ] . localDescription } ) ;
1110
+ } catch ( error ) {
1111
+ Logger . error ( 'Error during negotiation' , error ) ;
1112
+ }
1097
1113
}
1098
1114
1099
1115
if ( this . dataChannelEnabled ) {
@@ -1136,7 +1152,12 @@ export class WebRTCAdaptor {
1136
1152
1137
1153
this . remotePeerConnection [ streamId ] . oniceconnectionstatechange = event => {
1138
1154
var obj = { state : this . remotePeerConnection [ streamId ] . iceConnectionState , streamId : streamId } ;
1139
- if ( obj . state == "failed" || obj . state == "disconnected" || obj . state == "closed" ) {
1155
+ if ( obj . state === "stable" ) {
1156
+ this . iceRestart = false ;
1157
+ } else if ( obj . state === "failed" ) {
1158
+ this . iceRestart = true ;
1159
+ this . remotePeerConnection [ streamId ] . restartIce ( ) ;
1160
+ } else if ( obj . state === "disconnected" || obj . state === "closed" ) {
1140
1161
this . reconnectIfRequired ( 3000 ) ;
1141
1162
}
1142
1163
this . notifyEventListeners ( "ice_connection_state_changed" , obj ) ;
0 commit comments