mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
Rename Session to LiveSession, a better name
This commit is contained in:
@@ -9,7 +9,7 @@ use failure::Fail;
|
||||
use crate::{
|
||||
project::{Project, ProjectLoadFuzzyError},
|
||||
web::Server,
|
||||
session::Session,
|
||||
live_session::LiveSession,
|
||||
};
|
||||
|
||||
const DEFAULT_PORT: u16 = 34872;
|
||||
@@ -38,8 +38,8 @@ pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
|
||||
info!("Found project at {}", project.file_location.display());
|
||||
info!("Using project {:#?}", project);
|
||||
|
||||
let session = Arc::new(Session::new(Arc::clone(&project)).unwrap());
|
||||
let server = Server::new(Arc::clone(&session));
|
||||
let live_session = Arc::new(LiveSession::new(Arc::clone(&project)).unwrap());
|
||||
let server = Server::new(Arc::clone(&live_session));
|
||||
|
||||
let port = options.port
|
||||
.or(project.serve_port)
|
||||
|
||||
@@ -11,7 +11,7 @@ pub mod path_map;
|
||||
pub mod project;
|
||||
pub mod rbx_session;
|
||||
pub mod rbx_snapshot;
|
||||
pub mod session;
|
||||
pub mod live_session;
|
||||
pub mod session_id;
|
||||
pub mod snapshot_reconciler;
|
||||
pub mod visualize;
|
||||
|
||||
@@ -13,7 +13,8 @@ use crate::{
|
||||
fs_watcher::FsWatcher,
|
||||
};
|
||||
|
||||
pub struct Session {
|
||||
/// Contains all of the state for a Rojo live-sync session.
|
||||
pub struct LiveSession {
|
||||
pub project: Arc<Project>,
|
||||
pub session_id: SessionId,
|
||||
pub message_queue: Arc<MessageQueue<InstanceChanges>>,
|
||||
@@ -22,8 +23,8 @@ pub struct Session {
|
||||
_fs_watcher: FsWatcher,
|
||||
}
|
||||
|
||||
impl Session {
|
||||
pub fn new(project: Arc<Project>) -> io::Result<Session> {
|
||||
impl LiveSession {
|
||||
pub fn new(project: Arc<Project>) -> io::Result<LiveSession> {
|
||||
let imfs = {
|
||||
let mut imfs = Imfs::new();
|
||||
imfs.add_roots_from_project(&project)?;
|
||||
@@ -45,7 +46,7 @@ impl Session {
|
||||
|
||||
let session_id = SessionId::new();
|
||||
|
||||
Ok(Session {
|
||||
Ok(LiveSession {
|
||||
project,
|
||||
session_id,
|
||||
message_queue,
|
||||
@@ -15,7 +15,7 @@ use rouille::{
|
||||
use rbx_tree::{RbxId, RbxInstance};
|
||||
|
||||
use crate::{
|
||||
session::Session,
|
||||
live_session::LiveSession,
|
||||
session_id::SessionId,
|
||||
snapshot_reconciler::InstanceChanges,
|
||||
visualize::{VisualizeRbxSession, VisualizeImfs, graphviz_to_svg},
|
||||
@@ -77,14 +77,14 @@ pub struct SubscribeResponse<'a> {
|
||||
}
|
||||
|
||||
pub struct Server {
|
||||
session: Arc<Session>,
|
||||
live_session: Arc<LiveSession>,
|
||||
server_version: &'static str,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
pub fn new(session: Arc<Session>) -> Server {
|
||||
pub fn new(live_session: Arc<LiveSession>) -> Server {
|
||||
Server {
|
||||
session,
|
||||
live_session,
|
||||
server_version: env!("CARGO_PKG_VERSION"),
|
||||
}
|
||||
}
|
||||
@@ -101,14 +101,14 @@ impl Server {
|
||||
(GET) (/api/rojo) => {
|
||||
// Get a summary of information about the server.
|
||||
|
||||
let rbx_session = self.session.rbx_session.lock().unwrap();
|
||||
let rbx_session = self.live_session.rbx_session.lock().unwrap();
|
||||
let tree = rbx_session.get_tree();
|
||||
|
||||
Response::json(&ServerInfoResponse {
|
||||
server_version: self.server_version,
|
||||
protocol_version: 2,
|
||||
session_id: self.session.session_id,
|
||||
expected_place_ids: self.session.project.serve_place_ids.clone(),
|
||||
session_id: self.live_session.session_id,
|
||||
expected_place_ids: self.live_session.project.serve_place_ids.clone(),
|
||||
root_instance_id: tree.get_root_id(),
|
||||
})
|
||||
},
|
||||
@@ -117,7 +117,7 @@ impl Server {
|
||||
// Retrieve any messages past the given cursor index, and if
|
||||
// there weren't any, subscribe to receive any new messages.
|
||||
|
||||
let message_queue = Arc::clone(&self.session.message_queue);
|
||||
let message_queue = Arc::clone(&self.live_session.message_queue);
|
||||
|
||||
// Did the client miss any messages since the last subscribe?
|
||||
{
|
||||
@@ -125,7 +125,7 @@ impl Server {
|
||||
|
||||
if !new_messages.is_empty() {
|
||||
return Response::json(&SubscribeResponse {
|
||||
session_id: self.session.session_id,
|
||||
session_id: self.live_session.session_id,
|
||||
messages: Cow::Borrowed(&new_messages),
|
||||
message_cursor: new_cursor,
|
||||
})
|
||||
@@ -147,7 +147,7 @@ impl Server {
|
||||
let (new_cursor, new_messages) = message_queue.get_messages_since(cursor);
|
||||
|
||||
return Response::json(&SubscribeResponse {
|
||||
session_id: self.session.session_id,
|
||||
session_id: self.live_session.session_id,
|
||||
messages: Cow::Owned(new_messages),
|
||||
message_cursor: new_cursor,
|
||||
})
|
||||
@@ -155,7 +155,7 @@ impl Server {
|
||||
},
|
||||
|
||||
(GET) (/api/read/{ id_list: String }) => {
|
||||
let message_queue = Arc::clone(&self.session.message_queue);
|
||||
let message_queue = Arc::clone(&self.live_session.message_queue);
|
||||
|
||||
let requested_ids: Option<Vec<RbxId>> = id_list
|
||||
.split(',')
|
||||
@@ -167,7 +167,7 @@ impl Server {
|
||||
None => return rouille::Response::text("Malformed ID list").with_status_code(400),
|
||||
};
|
||||
|
||||
let rbx_session = self.session.rbx_session.lock().unwrap();
|
||||
let rbx_session = self.live_session.rbx_session.lock().unwrap();
|
||||
let tree = rbx_session.get_tree();
|
||||
|
||||
let message_cursor = message_queue.get_message_cursor();
|
||||
@@ -197,14 +197,14 @@ impl Server {
|
||||
}
|
||||
|
||||
Response::json(&ReadResponse {
|
||||
session_id: self.session.session_id,
|
||||
session_id: self.live_session.session_id,
|
||||
message_cursor,
|
||||
instances,
|
||||
})
|
||||
},
|
||||
|
||||
(GET) (/visualize/rbx) => {
|
||||
let rbx_session = self.session.rbx_session.lock().unwrap();
|
||||
let rbx_session = self.live_session.rbx_session.lock().unwrap();
|
||||
|
||||
let dot_source = format!("{}", VisualizeRbxSession(&rbx_session));
|
||||
|
||||
@@ -212,7 +212,7 @@ impl Server {
|
||||
},
|
||||
|
||||
(GET) (/visualize/imfs) => {
|
||||
let imfs = self.session.imfs.lock().unwrap();
|
||||
let imfs = self.live_session.imfs.lock().unwrap();
|
||||
|
||||
let dot_source = format!("{}", VisualizeImfs(&imfs));
|
||||
|
||||
@@ -220,7 +220,7 @@ impl Server {
|
||||
},
|
||||
|
||||
(GET) (/visualize/path_metadata) => {
|
||||
let rbx_session = self.session.rbx_session.lock().unwrap();
|
||||
let rbx_session = self.live_session.rbx_session.lock().unwrap();
|
||||
|
||||
Response::json(&rbx_session.debug_get_metadata_per_path())
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user