Getting muc room online users

I am looking for a way to get the current users in a room or a way to communicate with mod_muc_admin from within a custom module. Currently, I am trying to use the same method used in mod_muc admin -

  get_room_occupants(Room, Host) ->
case get_room_pid(Room, Host) of
  room_not_found ->
  ?INFO_MSG("muc_message_sent get_room_occ ~p~n", [room]);
  Pid -> get_room_occupants(Pid)
end.

get_room_occupants(Pid) ->
  ?INFO_MSG("muc_message_sent get_room_pstate ~p~n", [Pid]),
  S = get_room_state(Pid),
  ?INFO_MSG("muc_message_sent get_room_state S ~p~n", [S]),
  lists:map(
    fun({_LJID, Info}) ->
      {jid:to_string(Info#user.jid),
       Info#user.nick,
       atom_to_list(Info#user.role)}
    end,
  dict:to_list(S#state.users)).

%% @doc Get the Pid of an existing MUC room, or 'room_not_found'.
get_room_pid(Name, Service) ->
  case mnesia:dirty_read(muc_online_room, {Name, Service}) of
      [] ->
        ?INFO_MSG("muc_message_sent get_room_pid ~p~n", [failed]),
        room_not_found;
      [Room] ->
        ?INFO_MSG("muc_message_sent get_room_pid ~p~n", [pid]),
          Room#muc_online_room.pid
end.

get_room_state(Room_pid) ->
  {ok, R} = gen_fsm:sync_send_all_state_event(Room_pid, get_state),
  R.

But am getting an error whilst trying to get the room state.

  2016-07-25 10:43:04.802 [error] <0.13909.0>@ejabberd_hooks:run_fold1:368 {timeout,{gen_fsm,sync_send_all_state_event,[<0.13909.0>,get_state]}}
Syndicate content