Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Commit

Permalink
experiments with online user list
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlapshin committed Oct 8, 2009
1 parent a175223 commit 66162c5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
10 changes: 10 additions & 0 deletions player/player.html
Expand Up @@ -22,6 +22,16 @@
{% endfor %} {% endfor %}
</ul> </ul>
</td> </td>


<td>
Online:
<ul>
{% for client in clients %}
<li>{{client}}</li>
{% endfor %}
</ul>
</td>
</tr> </tr>
</table> </table>
</body> </body>
Expand Down
3 changes: 3 additions & 0 deletions src/ems_fsm.erl
Expand Up @@ -191,6 +191,9 @@ init([]) ->
{next_state, 'WAIT_FOR_DATA', State, ?TIMEOUT}; {next_state, 'WAIT_FOR_DATA', State, ?TIMEOUT};
Reply -> Reply Reply -> Reply
end. end.

'WAIT_FOR_DATA'({info}, _From, #ems_fsm{addr = Address} = State) ->
{reply, [{ip, Address}], 'WAIT_FOR_DATA', State, ?TIMEOUT};




'WAIT_FOR_DATA'(Data, _From, State) -> 'WAIT_FOR_DATA'(Data, _From, State) ->
Expand Down
2 changes: 2 additions & 0 deletions src/ems_http.erl
Expand Up @@ -26,10 +26,12 @@ handle('GET', [], Req) ->
false -> "video.mp4" false -> "video.mp4"
end, end,
{ok, FileList} = file:list_dir(ems_play:file_dir()), {ok, FileList} = file:list_dir(ems_play:file_dir()),
Clients = [Address || {_Pid, [{ip, Address}]} <- ems_server:clients()],
{ok, Index} = index_template:render([ {ok, Index} = index_template:render([
{files, FileList}, {files, FileList},
{hostname, ems:get_var(host, "rtmp://localhost")}, {hostname, ems:get_var(host, "rtmp://localhost")},
{url, File}, {url, File},
{clients, []},
{session, rtmp_session:encode([{channels, [10, 12]}, {user_id, 5}]) }]), {session, rtmp_session:encode([{channels, [10, 12]}, {user_id, 5}]) }]),
Req:ok([{'Content-Type', "text/html; charset=utf8"}], Index); Req:ok([{'Content-Type', "text/html; charset=utf8"}], Index);


Expand Down
11 changes: 10 additions & 1 deletion src/ems_server.erl
Expand Up @@ -39,13 +39,22 @@
-behaviour(gen_server). -behaviour(gen_server).


%% External API %% External API
-export([start_link/2]). -export([start_link/2, clients/0]).


%% gen_server callbacks %% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
code_change/3]). code_change/3]).




%%--------------------------------------------------------------------
%% @spec () -> [Ip::tuple()]
%%
%% @doc Show list of clients
%% @end
%%----------------------------------------------------------------------
clients() ->
Timeout = 10,
lists:map(fun({_, Pid, _, _}) -> {Pid, gen_fsm:sync_send_event(Pid, {info}, Timeout)} end, supervisor:which_children(ems_client_sup)).


%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @spec (Port::integer(), Module) -> {ok, Pid} | {error, Reason} %% @spec (Port::integer(), Module) -> {ok, Pid} | {error, Reason}
Expand Down

0 comments on commit 66162c5

Please sign in to comment.