Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: arcusfelis/cascadae
base: 06a9921a5b
...
head fork: arcusfelis/cascadae
compare: 218e8a9d15
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitattributes
@@ -1,2 +1,3 @@
# Force binary mode
priv/socket.io-client/socket.io.min.js -crlf
+priv/socket.io-client/socket.io.js -crlf
View
24 config.json
@@ -95,7 +95,13 @@
"format" : true,
"optimize" : []
}
- }
+ },
+ "add-script" :
+ [
+ {
+ "uri" : "socket.io-client/socket.io.js"
+ }
+ ]
},
"source-hybrid" :
@@ -118,7 +124,13 @@
"format" : true,
"optimize" : []
}
- }
+ },
+ "add-script" :
+ [
+ {
+ "uri" : "socket.io-client/socket.io.js"
+ }
+ ]
},
"build" :
@@ -142,7 +154,13 @@
"optimize" : ["basecalls", "comments", "privates",
"strings", "variables", "variants"]
}
- }
+ },
+ "add-script" :
+ [
+ {
+ "uri" : "socket.io-client/socket.io.min.js"
+ }
+ ]
}
View
1  priv/html/index.html
@@ -3,7 +3,6 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cascadae</title>
- <script type="text/javascript" src="socket.io-client/socket.io.min.js"></script>
<script type="text/javascript" src="script/cascadae.js"></script>
</head>
<body></body>
View
3,841 priv/socket.io-client/socket.io.js
3,841 additions, 0 deletions not shown
View
25 q_src/class/cascadae/Container.js
@@ -5,7 +5,12 @@
qx.Class.define("cascadae.Container",
{
extend : qx.ui.container.Composite,
-
+ events :
+ {
+ "activated" : "qx.event.type.Event",
+ "deactivated" : "qx.event.type.Event",
+ "r_checkVisibility" : "qx.event.type.Event"
+ },
@@ -63,6 +68,12 @@ qx.Class.define("cascadae.Container",
// Set "dead" zones (never will get focus)
this.__header.setKeepFocus(true);
this.__toolBar.setKeepFocus(true);
+
+ this.__pageVisibility = qx.bom.PageVisibility.getInstance();
+ this.__pageVisibility.addListener("change",
+ this.__checkPageVisibility,
+ this);
+ socket.registerObject(this);
},
members :
@@ -77,6 +88,14 @@ qx.Class.define("cascadae.Container",
__viewLoaded : false,
__activeView : "",
+ __checkPageVisibility: function()
+ {
+ if (this.__pageVisibility.isHidden())
+ this.fireEvent("deactivated");
+ else
+ this.fireEvent("activated");
+ },
+
getRoot : function()
{
return this.__application.getRoot();
@@ -87,7 +106,8 @@ qx.Class.define("cascadae.Container",
var container = this;
// Do heavy calculations in idle time
- setTimeout(function() { container._initViews(); }, 3000);
+ // document.setTimeout
+ qx.event.Timer.once(container._initViews, container, 3000);
},
_initViews : function()
@@ -380,6 +400,7 @@ qx.Class.define("cascadae.Container",
{
var isFileViewEnabled = false;
var isWishViewEnabled = false;
+ this.info("Select view " + show);
switch(show)
{
View
57 q_src/class/cascadae/Socket.js
@@ -99,13 +99,8 @@ qx.Class.define("cascadae.Socket", {
/**
* Trying to using socket.io to connect and plug every event from socket.io to qooxdoo one
*/
- connect: function()
- {
- if(this.getSocket() != null)
- {
- this.getSocket().removeAllListeners();
- this.getSocket().disconnect();
- }
+ connect: function()
+ {
var address = this.getUrl() + this.getNamespace();
this.info("Connect to " + address);
var socket = io.connect(address, {
@@ -113,8 +108,8 @@ qx.Class.define("cascadae.Socket", {
'reconnect': this.getReconnect(),
'connect timeout' : this.getConnectTimeout(),
'reconnection delay': this.getReconnectionDelay(),
- 'max reconnection attempts': this.getMaxReconnectionAttemps(),
- 'force new connection': true
+ 'max reconnection attempts': this.getMaxReconnectionAttemps()
+// 'force new connection': true
})
this.setSocket(socket);
var self = this;
@@ -139,15 +134,15 @@ qx.Class.define("cascadae.Socket", {
socket.on("addListener", function(e) {
self.__addListenerFromErlang(e.name, e.hash);
- });
+ });
socket.on("fireEvent", function(e) {
self.__fireEventFromErlang(e.name, e.hash);
- });
+ });
socket.on("fireDataEvent", function(e) {
self.__fireDataEventFromErlang(e.name, e.hash, e.data);
- });
+ });
},
__addListenerFromErlang: function(eventName, objHash)
@@ -214,10 +209,32 @@ qx.Class.define("cascadae.Socket", {
reconnect : function()
{
+ this.__destroySocket();
+ this.connect();
},
reload : function()
{
+ },
+
+ __destroySocket: function()
+ {
+ var socket = this.getSocket();
+ if(socket != null)
+ {
+ this.removeAllBindings();
+
+ //Disconnecting socket.io
+ socket.disconnect();
+ ["connect", "connect_failed", "disconnect", "reconnect_failed",
+ "connecting", "message", "close", "reconnect", "reconnecting", "error",
+
+ "rd_logEvent"]
+ .map(function(eventName) {
+ socket.removeAllListeners(eventName);
+ });
+ this.setSocket(null);
+ }
}
},
@@ -226,20 +243,6 @@ qx.Class.define("cascadae.Socket", {
*/
destruct : function()
{
- var socket = this.getSocket();
- if(socket != null)
- {
- this.removeAllBindings();
-
- //Disconnecting socket.io
- socket.disconnect();
- ["connect", "connect_failed", "disconnect", "reconnect_failed",
- "connecting", "message", "close", "reconnect", "reconnecting", "error",
-
- "rd_logEvent"]
- .map(function(eventName) {
- socket.removeAllListeners(eventName);
- });
- }
+ this.__destroySocket();
}
});
View
10 q_src/class/cascadae/files/Tree.js
@@ -104,7 +104,8 @@ qx.Class.define("cascadae.files.Tree",
this.addListener("rd_dataUpdated", this.onDataUpdated, this);
this.setAlwaysShowOpenCloseSymbol(true);
- this.__preloadImages();
+ // delay preloading
+ qx.event.Timer.once(this.__preloadImages, this, 3000);
},
members : {
@@ -210,14 +211,14 @@ qx.Class.define("cascadae.files.Tree",
__preloadImages : function()
{
- var ImageLoader = qx.io.ImageLoader;
+ var il = qx.io.ImageLoader;
var am = qx.util.AliasManager.getInstance();
var rm = qx.util.ResourceManager.getInstance();
var loadImage = function(f)
{
- ImageLoader.load(rm.toUri(am.resolve(f)));
+ il.load(rm.toUri(am.resolve(f)));
};
loadImage("cascadae/icon/16/files/folder-open-partical.png");
@@ -227,6 +228,7 @@ qx.Class.define("cascadae.files.Tree",
loadImage("cascadae/icon/16/files/office-skipped.png");
loadImage("icon/16/mimetypes/office-document.png");
loadImage("icon/16/places/folder.png");
+ loadImage("icon/16/places/folder-open.png");
},
@@ -605,7 +607,7 @@ qx.Class.define("cascadae.files.Tree",
this.__dirSids = dirSids;
// this.__openSids[tid] is the same.
- for (parent_sid in psid2rows)
+ for (var parent_sid in psid2rows)
{
var rows = psid2rows[parent_sid];
dm.sortRows(rows);
View
3  src/cascadae_app.erl
@@ -20,7 +20,8 @@ start(_Type, _Args) ->
SIODir = abs_path(filename:join([PrivDir, "socket.io-client"])),
QDepsDir = abs_path(code:lib_dir(?APP, q_deps)),
QSrcDir = abs_path(code:lib_dir(?APP, q_src)),
- StaticFilesCfg = [{mimetypes, {fun mimetypes:path_to_mimes/2, default}}],
+ StaticFilesCfg = [{mimetypes, {fun mimetypes:path_to_mimes/2, default}},
+ {etag, {attributes, [filepath, filesize, inode, mtime]}}],
SIOConfig = socketio_session:configure([
{heartbeat, 5000},
{session_timeout, 30000},
View
6 src/cascadae_files.erl
@@ -46,7 +46,7 @@ deactivate(Srv) ->
%% ------------------------------------------------------------------
init([Session, Tag]) ->
- TRef = timer:send_interval(5000, update_tree),
+ {ok, TRef} = timer:send_interval(5000, update_tree),
State = #files_state{
session_pid=Session,
session_tag=Tag,
@@ -59,6 +59,7 @@ handle_call(_Request, _From, State) ->
handle_cast(activate, State=#files_state{update_tree_tref=undefined}) ->
+ lager:info("Activate timer.", []),
{ok, TRef} = timer:send_interval(5000, update_tree),
{noreply, State#files_state{update_tree_tref=TRef}};
handle_cast(activate, State=#files_state{}) ->
@@ -66,7 +67,8 @@ handle_cast(activate, State=#files_state{}) ->
handle_cast(deactivate, State=#files_state{update_tree_tref=undefined}) ->
{noreply, State};
handle_cast(deactivate, State=#files_state{update_tree_tref=TRef}) ->
- ok = timer:cancel(TRef),
+ lager:info("Deactivate timer.", []),
+ {ok, cancel} = timer:cancel(TRef),
{noreply, State#files_state{update_tree_tref=undefined}};
%% Same torrent.
handle_cast({request, TorrentID, ParentFileIDs},
View
154 src/cascadae_peers.erl
@@ -1,7 +1,107 @@
-module(cascadae_peers).
+-export([all_peers/0]).
+-behaviour(gen_server).
+-define(SERVER, ?MODULE).
+-record(peers_state, {
+ session_pid,
+ session_tag,
+ torrent_ids,
+ update_table_tref
+}).
+
+%% ------------------------------------------------------------------
+%% API Function Exports
+%% ------------------------------------------------------------------
+
+-export([start_link/2,
+ set_torrent_list/2,
+ activate/1,
+ deactivate/1]).
+
+%% ------------------------------------------------------------------
+%% gen_server Function Exports
+%% ------------------------------------------------------------------
+
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+%% ------------------------------------------------------------------
+%% API Function Definitions
+%% ------------------------------------------------------------------
+
+start_link(Session, Tag) ->
+ gen_server:start_link(?MODULE, [Session, Tag], []).
+
+set_torrent_list(Srv, TorrentIDs) ->
+ gen_server:cast(Srv, {set_torrent_list, TorrentIDs}).
+
+activate(Srv) ->
+ gen_server:cast(Srv, activate).
+
+deactivate(Srv) ->
+ gen_server:cast(Srv, deactivate).
+
+%% ------------------------------------------------------------------
+%% gen_server Function Definitions
+%% ------------------------------------------------------------------
+
+init([Session, Tag]) ->
+ TRef = timer:send_interval(5000, update_table),
+ State = #peers_state{
+ session_pid=Session,
+ session_tag=Tag,
+ update_table_tref=TRef
+ },
+ {ok, State}.
+
+handle_call(_Request, _From, State) ->
+ {reply, ok, State}.
+
+
+handle_cast(activate, State=#peers_state{update_table_tref=undefined}) ->
+ {ok, TRef} = timer:send_interval(5000, update_table),
+ {noreply, State#peers_state{update_table_tref=TRef}};
+handle_cast(activate, State=#peers_state{}) ->
+ {noreply, State};
+handle_cast(deactivate, State=#peers_state{update_table_tref=undefined}) ->
+ {noreply, State};
+handle_cast(deactivate, State=#peers_state{update_table_tref=TRef}) ->
+ ok = timer:cancel(TRef),
+ {noreply, State#peers_state{update_table_tref=undefined}}.
+
+
+handle_info(update_table, State) ->
+ lager:debug("Handle update_table timeout.", []),
+ #peers_state{
+ torrent_ids=TorrentIDs,
+ session_pid=Session,
+ session_tag=Tag
+ } = State,
+% cascadae_session:send(Session, {Tag, {diff_list, TorrentID, Diff}})
+ {noreply, State#peers_state{}}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%% ------------------------------------------------------------------
+%% Internal Function Definitions
+%% ------------------------------------------------------------------
+
+
+
+
+
+
+
+
+
+%% etorrent_peer_states:get_send_rate(Id, Pid)
+%% etorrent_peer_states:get_recv_rate(Id, Pid)
--export([all_peers/0]).
all_peers() ->
%{pid, Pid}, {ip, IP}, {port, Port},
@@ -40,20 +140,20 @@ zip_list([PL|PLT], [PLS|PLST], Acc) ->
zip_list(PLT, PLST, [El|Acc]);
Pid1 < Pid2 ->
- El = zip(PL, 'undefined'),
+ El = zip(PL, undefined),
zip_list(PLT, [PLS|PLST], [El|Acc]);
Pid1 > Pid2 ->
- El = zip('undefined', PLS),
+ El = zip(undefined, PLS),
zip_list([PL|PLT], PLST, [El|Acc])
end;
zip_list([], [PLS|PLST], Acc) ->
- El = zip('undefined', PLS),
+ El = zip(undefined, PLS),
zip_list([], PLST, [El|Acc]);
zip_list([PL|PLT], [], Acc) ->
- El = zip(PL, 'undefined'),
+ El = zip(PL, undefined),
zip_list(PLT, [], [El|Acc]);
zip_list([], [], Acc) ->
@@ -61,51 +161,51 @@ zip_list([], [], Acc) ->
-zip(PL, 'undefined') ->
+zip(PL, undefined) ->
Pid = proplists:get_value(pid, PL),
- [{'id', to_binary(Pid)}
+ [{id, to_binary(Pid)}
- ,{'ip', render_ip(proplists:get_value('ip', PL))}
- ,{'port', proplists:get_value('port', PL)}
- ,{'torrent_id', proplists:get_value('torrent_id', PL)}
- ,{'state', atom_to_binary(proplists:get_value('state', PL))}
+ ,{ip, render_ip(proplists:get_value(ip, PL))}
+ ,{port, proplists:get_value(port, PL)}
+ ,{torrent_id, proplists:get_value(torrent_id, PL)}
+ ,{state, atom_to_binary(proplists:get_value(state, PL))}
];
-zip('undefined', PLS) ->
+zip(undefined, PLS) ->
Pid = proplists:get_value(pid, PLS),
- [{'id', to_binary(Pid)}
+ [{id, to_binary(Pid)}
- ,{'choke_state', atom_to_binary(proplists:get_value('choke_state', PLS))}
- ,{'interest_state', atom_to_binary(proplists:get_value('interest_state', PLS))}
- ,{'local_choke', proplists:get_value('local_choke', PLS)} % bool
+ ,{choke_state, atom_to_binary(proplists:get_value(choke_state, PLS))}
+ ,{interest_state, atom_to_binary(proplists:get_value(interest_state, PLS))}
+ ,{local_choke, proplists:get_value(local_choke, PLS)} % bool
];
zip(PL, PLS) ->
Pid = proplists:get_value(pid, PL),
Pid = proplists:get_value(pid, PLS),
- [{'id', to_binary(Pid)}
+ [{id, to_binary(Pid)}
- ,{'ip', render_ip(proplists:get_value('ip', PL))}
- ,{'port', proplists:get_value('port', PL)}
- ,{'torrent_id', proplists:get_value('torrent_id', PL)}
- ,{'state', atom_to_binary(proplists:get_value('state', PL))}
+ ,{ip, render_ip(proplists:get_value(ip, PL))}
+ ,{port, proplists:get_value(port, PL)}
+ ,{torrent_id, proplists:get_value(torrent_id, PL)}
+ ,{state, atom_to_binary(proplists:get_value(state, PL))}
- ,{'choke_state', atom_to_binary(proplists:get_value('choke_state', PLS))}
- ,{'interest_state', atom_to_binary(proplists:get_value('interest_state', PLS))}
- ,{'local_choke', proplists:get_value('local_choke', PLS)} % bool
+ ,{choke_state, atom_to_binary(proplists:get_value(choke_state, PLS))}
+ ,{interest_state, atom_to_binary(proplists:get_value(interest_state, PLS))}
+ ,{local_choke, proplists:get_value(local_choke, PLS)} % bool
].
render_ip({A,B,C,D}) ->
- list_to_binary(io_lib:format("~w.~w.~w.~w", [A,B,C,D])).
+ iolist_to_binary(io_lib:format("~w.~w.~w.~w", [A,B,C,D])).
to_binary(Term) ->
- list_to_binary(io_lib:format("~w", [Term])).
+ iolist_to_binary(io_lib:format("~w", [Term])).
-atom_to_binary(X) -> list_to_binary(atom_to_list(X)).
+atom_to_binary(X) -> atom_to_binary(X, utf8).
View
80 src/cascadae_session.erl
@@ -2,7 +2,7 @@
-export([send/2]).
-export([open/3, recv/4, handle_info/4, close/3]).
--record(session_state, {
+-record(sess_state, {
%% Hash of the cascadae.Table object.
torrent_table_hash,
%% Hash of the cascadae.wishlist.List object.
@@ -10,7 +10,11 @@
%% Id of the ETS table with `#object{}' records.
obj_tbl,
%% Pid of `cascadae_files' worker.
- files_pid
+ files_pid,
+ %% Is an interval timer for updates active?
+ is_files_active,
+ is_files_visible,
+ is_page_visible
}).
-define(OBJ_TBL, cascadae_object_register).
-define(HUB, cascadae_hub).
@@ -30,40 +34,42 @@ open(Pid, Sid, _Opts) ->
?HUB:add_handler(),
error_logger:info_msg("open ~p ~p~n", [Pid, Sid]),
ObjTbl = ets:new(?OBJ_TBL, [{keypos, #object.hash}]),
- {ok, #session_state{obj_tbl=ObjTbl}}.
+ {ok, #sess_state{obj_tbl=ObjTbl}}.
-recv(_Pid, _Sid, {json, <<>>, Json}, State = #session_state{}) ->
+recv(_Pid, _Sid, {json, <<>>, Json}, State = #sess_state{}) ->
lager:debug("recv json ~p~n", [Json]),
{ok, State};
-recv(_Pid, _Sid, {message, <<>>, _Message}, State = #session_state{}) ->
+recv(_Pid, _Sid, {message, <<>>, _Message}, State = #sess_state{}) ->
%% socketio_session:send_message(Pid, Message),
{ok, State};
recv(_, _, {event, <<>>, <<"deactivated">>, Meta}=Mess, State) ->
- #session_state{files_pid=FilesPid} = State,
+ #sess_state{files_pid=FilesPid} = State,
Hash = proplists:get_value(<<"hash">>, Meta),
assert_hash(Hash),
#object{path=Path} = extract_object(Hash, State),
case Path of
[<<"cascadae">>,<<"files">>,<<"Tree">>] when is_pid(FilesPid) ->
- cascadae_files:deactivate(FilesPid),
- {ok, State};
+ {ok, check_file_visibility(State#sess_state{is_files_visible=false})};
+ [<<"cascadae">>,<<"Container">>] ->
+ {ok, check_file_visibility(State#sess_state{is_page_visible=false})};
_ ->
lager:debug("Ignore ~p.", [Mess]),
{ok, State}
end;
recv(_, _, {event, <<>>, <<"activated">>, Meta}=Mess, State) ->
- #session_state{files_pid=FilesPid} = State,
+ #sess_state{files_pid=FilesPid} = State,
Hash = proplists:get_value(<<"hash">>, Meta),
assert_hash(Hash),
#object{path=Path} = extract_object(Hash, State),
case Path of
[<<"cascadae">>,<<"files">>,<<"Tree">>] when is_pid(FilesPid) ->
- cascadae_files:activate(FilesPid),
- {ok, State};
+ {ok, check_file_visibility(State#sess_state{is_files_visible=true})};
+ [<<"cascadae">>,<<"Container">>] ->
+ {ok, check_file_visibility(State#sess_state{is_page_visible=true})};
_ ->
lager:debug("Ignore ~p.", [Mess]),
{ok, State}
@@ -97,21 +103,22 @@ recv(Session, _, {event, <<>>, <<"d_childrenRequest">>, Meta}, State) ->
FileIDs = proplists:get_value(<<"file_ids">>, Data),
assert_hash(Hash),
FilesPid = %% try start
- case State#session_state.files_pid of
+ case State#sess_state.files_pid of
undefined ->
{ok, Pid} = cascadae_files:start_link(Session, {files, Hash}),
Pid;
Pid -> Pid
end,
cascadae_files:request(FilesPid, TorrentID, FileIDs),
- {ok, State#session_state{files_pid=FilesPid}};
+ {ok, State#sess_state{files_pid=FilesPid,
+ is_files_active=true, is_files_visible=true}};
recv(Session, _, {event, <<>>, <<"d_wishFiles">>, Meta}, State) ->
spawn_link(fun() ->
Data = proplists:get_value(<<"data">>, Meta),
TorrentID = proplists:get_value(<<"torrent_id">>, Data),
FileIDs = proplists:get_value(<<"file_ids">>, Data),
{ok, NewWishes} = etorrent_torrent_ctl:wish_file(TorrentID, FileIDs),
- case State#session_state.wish_list_hash of
+ case State#sess_state.wish_list_hash of
undefined -> ok;
WLHash ->
RespondData = encode_wishes(TorrentID, NewWishes),
@@ -165,7 +172,7 @@ recv(Pid, Sid, Message, State) ->
handle_info(Pid, _, {torrents, What},
- State=#session_state{torrent_table_hash=Hash})
+ State=#sess_state{torrent_table_hash=Hash})
when is_binary(Hash) ->
case What of
{diff_list, Rows} ->
@@ -179,7 +186,7 @@ handle_info(Pid, _, {torrents, What},
[{<<"rows">>, Rows}])
end,
{ok, State};
-handle_info(Pid, _, {{files, Hash}, What}, State=#session_state{}) ->
+handle_info(Pid, _, {{files, Hash}, What}, State=#sess_state{}) ->
case What of
{add_list, TorrentID, Nodes} ->
Data = [{<<"torrent_id">>, TorrentID}, {<<"nodes">>, Nodes}],
@@ -189,17 +196,17 @@ handle_info(Pid, _, {{files, Hash}, What}, State=#session_state{}) ->
fire_data_event(Pid, Hash, <<"rd_dataUpdated">>, Data)
end,
{ok, State};
-handle_info(Pid, _, {log_event, Mess}, State = #session_state{}) ->
+handle_info(Pid, _, {log_event, Mess}, State = #sess_state{}) ->
Message = {event, <<"rd_logEvent">>, Mess},
socketio_session:send(Pid, Message),
{ok, State};
-handle_info(_Pid, _Sid, Info, State = #session_state{}) ->
+handle_info(_Pid, _Sid, Info, State = #sess_state{}) ->
lager:debug("Unhandled message recieved ~p.", [Info]),
{ok, State}.
-close(Pid, Sid, #session_state{}) ->
+close(Pid, Sid, #sess_state{}) ->
%% Termination.
lager:debug("close ~p ~p~n", [Pid, Sid]),
ok.
@@ -216,12 +223,12 @@ register_object(Path=[<<"cascadae">>,<<"Table">>], Hash, State) ->
end),
add_event_listener(Session, Hash, <<"d_startTorrents">>),
add_event_listener(Session, Hash, <<"d_stopTorrents">>),
- store_object(Path, Hash, State#session_state{torrent_table_hash=Hash});
+ store_object(Path, Hash, State#sess_state{torrent_table_hash=Hash});
register_object(Path=[<<"cascadae">>,<<"wishlist">>,<<"List">>], Hash, State) ->
Session = self(),
add_event_listener(Session, Hash, <<"d_wishesSave">>),
add_event_listener(Session, Hash, <<"d_wishesRequest">>),
- store_object(Path, Hash, State#session_state{wish_list_hash=Hash});
+ store_object(Path, Hash, State#sess_state{wish_list_hash=Hash});
register_object(Path=[<<"cascadae">>,<<"files">>,<<"Tree">>], Hash, State) ->
Session = self(),
add_event_listener(Session, Hash, <<"d_childrenRequest">>),
@@ -231,24 +238,33 @@ register_object(Path=[<<"cascadae">>,<<"files">>,<<"Tree">>], Hash, State) ->
add_event_listener(Session, Hash, <<"activated">>),
add_event_listener(Session, Hash, <<"deactivated">>),
store_object(Path, Hash, State);
+register_object(Path=[<<"cascadae">>,<<"Container">>], Hash, State) ->
+ Session = self(),
+ add_event_listener(Session, Hash, <<"activated">>),
+ add_event_listener(Session, Hash, <<"deactivated">>),
+ add_event_listener(Session, Hash, <<"r_checkVisibility">>),
+ store_object(Path, Hash, State);
+
register_object(Path=[<<"cascadae">>,<<"peers">>,<<"Table">>], Hash, State) ->
-% Session = self(),
+ Session = self(),
% proc_lib:spawn_link(fun() ->
% Peers = cascadae_peers:all_peers(),
% fire_data_event(Session, Hash, <<"rd_dataLoadCompleted">>,
% [{<<"rows">>, Peers}])
% end),
+ add_event_listener(Session, Hash, <<"activated">>),
+ add_event_listener(Session, Hash, <<"deactivated">>),
store_object(Path, Hash, State);
register_object(Path, Hash, State) ->
lager:warning("Cannot register objest ~p:~p.", [Path, Hash]),
State.
-store_object(Path, Hash, State=#session_state{obj_tbl=ObjTbl}) ->
+store_object(Path, Hash, State=#sess_state{obj_tbl=ObjTbl}) ->
ets:insert_new(ObjTbl, #object{path=Path, hash=Hash}),
State.
-extract_object(Hash, #session_state{obj_tbl=ObjTbl}) ->
+extract_object(Hash, #sess_state{obj_tbl=ObjTbl}) ->
case ets:lookup(ObjTbl, Hash) of
[X] -> X
end.
@@ -314,3 +330,19 @@ decode_wishes(Wishes) ->
if is_binary(V) -> binary_to_existing_atom(V, utf8);
true -> V
end} || {K, V} <- X, K =/= <<"name">>] || X <- Wishes].
+
+
+
+%% The timer must be active only when the page is visible and file view is active.
+check_file_visibility(State=#sess_state{is_page_visible=true,
+ is_files_visible=true,
+ is_files_active=false,
+ files_pid=FilesPid}) ->
+ cascadae_files:activate(FilesPid),
+ State#sess_state{is_files_active=true};
+check_file_visibility(State=#sess_state{is_files_active=true,
+ files_pid=FilesPid}) ->
+ cascadae_files:deactivate(FilesPid),
+ State#sess_state{is_files_active=false};
+check_file_visibility(State) ->
+ State.

No commit comments for this range

Something went wrong with that request. Please try again.