@@ -82,6 +82,8 @@ public enum WffJsFile {
8282 // should be static final
8383 public static final boolean PRODUCTION_MODE = true ;
8484
85+ static final boolean DEV_MODE = false ;
86+
8587 public static final boolean COMPRESSED_WFF_DATA = true ;
8688
8789 private static final String allOptimizedContent ;
@@ -93,7 +95,9 @@ public enum WffJsFile {
9395 private static String [][] minifiableParts = { { "else {" , "else{" }, { "} else" , "}else" }, { "if (" , "if(" },
9496 { ") {" , "){" } };
9597
96- private static final String HEART_BEAT_JS = "setInterval(function(){try{wffWS.send([]);}catch(e){wffWS.closeSocket();}},\" ${HEARTBEAT_INTERVAL}\" );" ;
98+ private static final String HEART_BEAT_JS = """
99+ setInterval(function(){wffWS.checkCon();},"${HEARTBEAT_INTERVAL}");
100+ """ .trim ();
97101
98102 /**
99103 * INDEXED_TAGS_ARRAY
@@ -555,43 +559,75 @@ private String buildOptimizedFileContent() {
555559 * @param losslessCommunication
556560 * @param onPayloadLossJS
557561 * @return the js string for the client
558- * @author WFF
562+ * @deprecated since 12.0.9. It will be removed in future version as there
563+ * another overloading method available for the same purpose.
559564 */
565+ @ Deprecated (forRemoval = true , since = "12.0.9" )
560566 public static String getAllOptimizedContent (final String wsUrl , final String instanceId ,
561567 final boolean removePrevBPOnInitTab , final boolean removePrevBPOnClosetTab , final int heartbeatInterval ,
562568 final int wsReconnectInterval , final boolean autoremoveParentScript , final boolean losslessCommunication ,
563569 final String onPayloadLossJS ) {
570+ return getAllOptimizedContent (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
571+ heartbeatInterval , 5000 , wsReconnectInterval , autoremoveParentScript , losslessCommunication ,
572+ onPayloadLossJS );
573+ }
574+
575+ /**
576+ * NB :- This method is only for internal use.
577+ *
578+ * @param wsUrl the complete websocket url
579+ * @param instanceId the instanceId of browserPage
580+ * @param removePrevBPOnInitTab true or false
581+ * @param removePrevBPOnClosetTab true or false
582+ * @param heartbeatInterval in milliseconds
583+ * @param wsHeartbeatTimeout
584+ * @param wsReconnectInterval in milliseconds
585+ * @param autoremoveParentScript true or false
586+ * @param losslessCommunication
587+ * @param onPayloadLossJS
588+ * @return the js string for the client
589+ * @since 12.0.9 Added heartbeat timeout.
590+ */
591+ public static String getAllOptimizedContent (final String wsUrl , final String instanceId ,
592+ final boolean removePrevBPOnInitTab , final boolean removePrevBPOnClosetTab , final int heartbeatInterval ,
593+ final int wsHeartbeatTimeout , final int wsReconnectInterval , final boolean autoremoveParentScript ,
594+ final boolean losslessCommunication , final String onPayloadLossJS ) {
564595
565596 if (heartbeatInterval > 0 ) {
566597 if (autoremoveParentScript ) {
567598 return buildJsContentWithHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
568- heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS )
569- .append (AUTOREMOVE_PARENT_SCRIPT ).toString ();
599+ heartbeatInterval , wsHeartbeatTimeout , wsReconnectInterval , losslessCommunication ,
600+ onPayloadLossJS ) .append (AUTOREMOVE_PARENT_SCRIPT ).toString ();
570601 }
571602 return buildJsContentWithHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
572- heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS ).toString ();
603+ heartbeatInterval , wsHeartbeatTimeout , wsReconnectInterval , losslessCommunication , onPayloadLossJS )
604+ .toString ();
573605 }
574606
575607 if (autoremoveParentScript ) {
576608 return buildJsContentWithoutHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
577- heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS )
609+ heartbeatInterval , wsHeartbeatTimeout , wsReconnectInterval , losslessCommunication , onPayloadLossJS )
578610 .append (AUTOREMOVE_PARENT_SCRIPT ).toString ();
579611 }
580612 return buildJsContentWithoutHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
581- heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS ).toString ();
613+ heartbeatInterval , wsHeartbeatTimeout , wsReconnectInterval , losslessCommunication , onPayloadLossJS )
614+ .toString ();
582615 }
583616
584617 private static StringBuilder buildJsContentWithHeartbeat (final String wsUrl , final String instanceId ,
585618 final boolean removePrevBPOnInitTab , final boolean removePrevBPOnClosetTab , final int heartbeatInterval ,
586- final int wsReconnectInterval , final boolean losslessCommunication , final String onPayloadLossJS ) {
619+ final int wsHeartbeatTimeout , final int wsReconnectInterval , final boolean losslessCommunication ,
620+ final String onPayloadLossJS ) {
587621 return buildJsContentWithoutHeartbeat (wsUrl , instanceId , removePrevBPOnInitTab , removePrevBPOnClosetTab ,
588- heartbeatInterval , wsReconnectInterval , losslessCommunication , onPayloadLossJS ).append (
589- HEART_BEAT_JS .replace ("\" ${HEARTBEAT_INTERVAL}\" " , Integer .toString (heartbeatInterval )));
622+ heartbeatInterval , wsHeartbeatTimeout , wsReconnectInterval , losslessCommunication , onPayloadLossJS )
623+ .append (HEART_BEAT_JS .replace ("\" ${HEARTBEAT_INTERVAL}\" " ,
624+ Integer .toString (heartbeatInterval )));
590625 }
591626
592627 private static StringBuilder buildJsContentWithoutHeartbeat (final String wsUrl , final String instanceId ,
593628 final boolean removePrevBPOnInitTab , final boolean removePrevBPOnClosetTab , final int heartbeatInterval ,
594- final int wsReconnectInterval , final boolean losslessCommunication , final String onPayloadLossJS ) {
629+ final int wsHeartbeatTimeout , final int wsReconnectInterval , final boolean losslessCommunication ,
630+ final String onPayloadLossJS ) {
595631
596632 final StringBuilder globalContentBuider = new StringBuilder (WFF_GLOBAL .optimizedFileContent );
597633
@@ -626,6 +662,7 @@ private static StringBuilder buildJsContentWithoutHeartbeat(final String wsUrl,
626662
627663 StringBuilderUtil .replaceFirst (globalContentBuider , "\" ${WS_RECON}\" " , String .valueOf (wsReconnectInterval ));
628664 StringBuilderUtil .replaceFirst (globalContentBuider , "\" ${WS_HRTBT}\" " , String .valueOf (heartbeatInterval ));
665+ StringBuilderUtil .replaceFirst (globalContentBuider , "\" ${WS_HRTBT_TMT}\" " , String .valueOf (wsHeartbeatTimeout ));
629666 StringBuilderUtil .replaceFirst (globalContentBuider , "\" ${LOSSLESS_COMM}\" " ,
630667 String .valueOf (losslessCommunication ));
631668 String onLossyCommJS = onPayloadLossJS != null ? onPayloadLossJS .strip () : "" ;
@@ -634,8 +671,8 @@ private static StringBuilder buildJsContentWithoutHeartbeat(final String wsUrl,
634671
635672 final String globalContent = globalContentBuider .toString ();
636673
637- return new StringBuilder ("var wffLog = console.log;"). append ( JS_WORK_AROUND . optimizedFileContent )
638- .append (globalContent ).append (allOptimizedContent );
674+ return new StringBuilder (DEV_MODE ? " \" use strict \" \n var wffLog = console.log;" : "var wffLog = console.log;" )
675+ .append (JS_WORK_AROUND . optimizedFileContent ). append ( globalContent ).append (allOptimizedContent );
639676 }
640677
641678}
0 commit comments