import(mod_conference)

initial state start;

state lobby;

transition "start to lobby" start - sessionStart / { 
    set($is_spkonly=0);
    set($is_listenonly=0);
    playFile(wav//default_en.wav) 
} -> lobby;

state room;

transition "lobby to room" lobby - noAudioTest /  {
   conference.setPlayoutType(adaptive);
   conference.join(myroom);
} -> room;

transition "key 1 pressed" room - keyPress(1); test($is_spkonly == 0) / {
 set($is_spkonly=1);
 flushPlaylist();
 conference.rejoin(myroom, speakonly);
} -> room;

transition "key 1 pressed - spkonly" room - keyPress(1); test($is_spkonly == 1) / {
 set($is_spkonly=0);
 flushPlaylist();
 conference.rejoin(myroom);
} -> room;

transition "key 2 pressed" room - keyPress(2); test($is_listenonly == 0) / {
 set($is_listenonly=1);
 flushPlaylist();
 conference.rejoin(myroom, listenonly);
} -> room;

transition "key 2 pressed - listenonly" room - keyPress(2); test($is_listenonly == 1) / {
 set($is_listenonly=0);
 flushPlaylist();
 conference.rejoin(myroom);
} -> room;

state end;

transition "kick event" room - eventTest(#action==kick) / flushPlaylist(); conference.leave(); stop(true) -> end;

transition "leave event" room - eventTest(#action==leave) /  {
   flushPlaylist(); 
  conference.leave() 
} -> outside;

state outside
   enter { 
     log(2, now outside); 
   };

transition "join event" outside - eventTest(#action==join) / conference.join(myroom) -> room;
transition "join event" outside - eventTest(#action==joinroom) / conference.join(#room) -> room;

transition "bye recvd" (start, lobby, room, outside, end) - hangup / flushPlaylist(); conference.leave();  stop(false); -> end;
