Skip to content

Commit

Permalink
Merge pull request #250 from rdeits/hf/julia-1.10
Browse files Browse the repository at this point in the history
Add PrecompileTools.jl dependency and method to close server
  • Loading branch information
ferrolho authored Mar 17, 2024
2 parents 3839d9a + bd28bab commit ff4679f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeshCat"
uuid = "283c5d60-a78f-5afe-a0af-af636b173e11"
authors = ["Robin Deits <[email protected]>"]
version = "0.16.0"
version = "0.16.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand All @@ -17,6 +17,7 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
MsgPack = "99f44e22-a591-53d1-9472-aa23ef4bd671"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Expand All @@ -36,6 +37,7 @@ MeshIO = "0.4"
Meshing = "0.5"
MsgPack = "1"
Parameters = "0.10, 0.11, 0.12"
PrecompileTools = "1"
Requires = "0.5, 1"
Rotations = "1.3"
StaticArrays = "0.10, 0.11, 0.12, 1"
Expand Down
2 changes: 2 additions & 0 deletions src/MeshCat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,7 @@ function __init__()
setup_integrations()
end

# Code to "exercise" the package - see https://julialang.github.io/PrecompileTools.jl/stable/
include("./precompile.jl")

end
6 changes: 6 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import PrecompileTools

PrecompileTools.@compile_workload begin
vis = Visualizer()
close_server!(vis.core)
end
19 changes: 14 additions & 5 deletions src/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
Low-level type which manages the actual meshcat server. See [`Visualizer`](@ref)
for the public-facing interface.
"""
struct CoreVisualizer
mutable struct CoreVisualizer
tree::SceneNode
connections::Set{HTTP.WebSockets.WebSocket}
host::IPAddr
port::Int
server::HTTP.Server

function CoreVisualizer(host::IPAddr = ip"127.0.0.1", default_port=8700)
connections = Set([])
tree = SceneNode()
port = find_open_port(host, default_port, 500)
core = new(tree, connections, host, port)
start_server(core)
core.server = start_server(core)
return core
end
end
Expand Down Expand Up @@ -53,14 +54,22 @@ function start_server(core::CoreVisualizer)
if HTTP.WebSockets.isupgrade(http.message)
HTTP.WebSockets.upgrade(http) do websocket
push!(core.connections, websocket)
send_scene(core, websocket)
send_scene(core.tree, websocket)
wait()
end
else
HTTP.streamhandler(router)(http)
end
end
@info "MeshCat server started. You can open the visualizer by visiting the following URL in your browser:\n$(url(core))"
return server
end

function close_server!(core::CoreVisualizer)
if !isnothing(core.server) && isopen(core.server)
HTTP.close(core.server)
@info "MeshCat server closed."
end
end

function url(core::CoreVisualizer)
Expand Down Expand Up @@ -95,8 +104,8 @@ function update_tree!(core::CoreVisualizer, cmd::SaveImage, data)
nothing
end

function send_scene(core::CoreVisualizer, connection)
foreach(core.tree) do node
function send_scene(tree::SceneNode, connection)
foreach(tree) do node
if node.object !== nothing
HTTP.WebSockets.send(connection, node.object)
end
Expand Down

2 comments on commit ff4679f

@ferrolho
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/103041

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.16.1 -m "<description of version>" ff4679fec4df749465d7660da18c0cf7cffec340
git push origin v0.16.1

Please sign in to comment.