@@ -6,7 +6,7 @@ import * as utils from './utils.js';
66import sessionModule from './sessionModule.js' ;
77
88/**
9- * @typedef {{callState: string, location: number, callinfo: {callid: string, from: string , to: string}, mediaInfo: {mos: float, mean_mos: float, jitter: float, mean_jitter: float, packetloss: integer, mean_rfactor: float, direction: number}, locations: string[], infrastructure: object} } SessionState
9+ * @typedef {{callState: string, location: number, callinfo: {callid: string, from: string, to: string}, mediaInfo: {mos: float, mean_mos: float, jitter: float, mean_jitter: float, packetloss: integer, mean_rfactor: float, direction: number}, locations: string[], infrastructure: object} } SessionState
1010 */
1111
1212const simulationModule = {
@@ -25,7 +25,7 @@ const simulationModule = {
2525 unAuthorizedConfig : { } ,
2626 initialize : async ( mediator , configuration ) => {
2727 simulationModule . mediator = mediator ;
28- simulationModule . mediator . subscribe ( simulationModule . receiveInput . bind ( simulationModule ) ) ;
28+ simulationModule . mediator . subscribe ( simulationModule . receiveInput ) ;
2929 simulationModule . configuration = configuration ;
3030 sessionModule . initialize ( mediator , configuration ) ;
3131 console . log ( "Simulation module initialized with configuration:" , configuration , simulationModule . mediator ) ;
@@ -53,10 +53,11 @@ const simulationModule = {
5353 return ( simulationModule . getAdjustmentFactor ( ) * 1000 ) / CPS ;
5454 } ,
5555 normalTick : async ( ) => {
56- let normalConfig = simulationModule . configuration . find ( ( s => s . name === "normal" ) ) ;
57- if ( simulationModule . debug ) console . log ( "🕒 Normal tick at" , new Date ( ) . toISOString ( ) , "with adjusted delay" , simulationModule . getAdjustedDelay ( normalConfig . cps_high ) . toFixed ( 2 ) , "resulting in" , ( 1000 / simulationModule . getAdjustedDelay ( normalConfig . cps_high ) ) . toFixed ( 2 ) , "calls per second" ) ;
58- simulationModule . mediator . send ( { type : "newSession" , config : normalConfig } ) ;
59- setTimeout ( simulationModule . normalTick , simulationModule . getAdjustedDelay ( normalConfig . cps_high ) ) ;
56+ if ( ! simulationModule . simulationStopped ) {
57+ if ( simulationModule . debug ) console . log ( "🕒 Normal tick at" , new Date ( ) . toISOString ( ) , "with adjusted delay" , simulationModule . getAdjustedDelay ( simulationModule . normalConfig . cps_high ) . toFixed ( 2 ) , "resulting in" , ( 1000 / simulationModule . getAdjustedDelay ( simulationModule . normalConfig . cps_high ) ) . toFixed ( 2 ) , "calls per second" ) ;
58+ simulationModule . mediator . send ( { type : "newSession" , config : simulationModule . normalConfig } ) ;
59+ setTimeout ( simulationModule . normalTick , simulationModule . getAdjustedDelay ( simulationModule . normalConfig . cps_high ) ) ;
60+ }
6061 } ,
6162 badTick : async ( ) => {
6263 if ( ! simulationModule . simulationStopped ) {
@@ -71,8 +72,8 @@ const simulationModule = {
7172 unAuthorizedTick : async ( ) => {
7273 if ( ! simulationModule . simulationStopped ) {
7374 console . log ( "🕒 Unauthorized tick at" , new Date ( ) . toISOString ( ) ) ;
74- for ( let i = 0 ; i < unAuthorizedConfig . count ; i ++ ) {
75- simulationModule . mediator . send ( { type : "newSession" , config : unAuthorizedConfig } ) ;
75+ for ( let i = 0 ; i < simulationModule . unAuthorizedConfig . count ; i ++ ) {
76+ simulationModule . mediator . send ( { type : "newSession" , config : simulationModule . unAuthorizedConfig } ) ;
7677 await Bun . sleep ( 300 ) ; // slight delay between bad calls to avoid bursts
7778 }
7879 setTimeout ( simulationModule . unAuthorizedTick , ( simulationModule . unAuthorizedConfig . interval * 1000 ) + utils . getRandomInteger ( 0 , 120000 ) ) ;
@@ -85,7 +86,8 @@ const simulationModule = {
8586 runSimulation : async ( ) => {
8687 /* Normal call flows */
8788 let normalConfig = simulationModule . configuration . find ( ( s => s . name === "normal" ) ) ;
88- setTimeout ( simulationModule . normalTick , simulationModule . getAdjustedDelay ( normalConfig . cps_high ) ) ;
89+ simulationModule . normalConfig = normalConfig ;
90+ setTimeout ( simulationModule . normalTick , simulationModule . getAdjustedDelay ( simulationModule . normalConfig . cps_high ) ) ;
8991 /* Bad MOS calls */
9092 let badConfig = simulationModule . configuration . find ( ( s => s . name === "bad" ) ) ;
9193 simulationModule . badConfig = badConfig ;
0 commit comments