Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Bevy Remote Events
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Remote Events
Commits
fb674be4
Verified
Commit
fb674be4
authored
2 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Handle disconnect for web target
parent
1f6e35cb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Cargo.toml
+1
-1
1 addition, 1 deletion
Cargo.toml
README.md
+4
-1
4 additions, 1 deletion
README.md
src/wasm.rs
+38
-2
38 additions, 2 deletions
src/wasm.rs
with
43 additions
and
4 deletions
Cargo.toml
+
1
−
1
View file @
fb674be4
...
...
@@ -19,4 +19,4 @@ features = []
websocket
=
{
version
=
"0.26.5"
,
default-features
=
false
,
features
=
[
"sync"
,
"sync-ssl"
,
"bytes"
,
"native-tls"
]}
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-sockets
=
"0.2.2"
wasm-sockets
=
{
git
=
"https://lab.lcr.gr/microhacks/wasm-sockets.git"
,
rev
=
"5c8bdb2a54c1acfd816587bfcd5f64a34b3740b4"
}
This diff is collapsed.
Click to expand it.
README.md
+
4
−
1
View file @
fb674be4
...
...
@@ -15,7 +15,10 @@ This library is quite immature; many features still need to be added for it to b
-
[x] WS Connection from wasm
-
[x] Frame independent event buffering
-
[x] User initiated disconnect on desktop
-
[ ] User initiated disconnect on wasm
-
[x] User initiated disconnect on wasm
-
[x] Handle remote disconnect
-
[ ] Emit events for non-user-initiated lifecycle events
-
[ ] Correctly track status of underlying connection
-
[ ] Automatic reconnection
-
[x] Map received events to user defined types
-
[x] Send events of a user defined type
...
...
This diff is collapsed.
Click to expand it.
src/wasm.rs
+
38
−
2
View file @
fb674be4
use
std
::
fmt
::
Debug
;
use
std
::
marker
::
PhantomData
;
use
std
::
ops
::
Deref
;
use
std
::
sync
::{
Arc
,
Mutex
};
use
bevy
::
ecs
::
event
::
Events
;
...
...
@@ -9,7 +10,7 @@ use bevy::prelude::{
IntoExclusiveSystem
,
NonSendMut
,
Plugin
,
ResMut
,
World
,
};
use
thiserror
::
Error
;
use
wasm_sockets
::
Message
;
use
wasm_sockets
::
{
EventClient
,
Message
}
;
use
crate
::
events
::{
FromSocketMessage
,
SocketControlEvent
,
SocketState
,
ToSocketMessage
};
...
...
@@ -34,6 +35,21 @@ where
client
:
wasm_sockets
::
PollingClient
,
}
pub
trait
ClosableExt
{
fn
close
(
&
mut
self
);
}
impl
<
SentMessageType
,
ReceivedMessageType
>
Drop
for
RemoteEventDispatcher
<
SentMessageType
,
ReceivedMessageType
>
where
ReceivedMessageType
:
FromSocketMessage
+
Send
+
Sync
+
'static
,
SentMessageType
:
ToSocketMessage
+
Send
+
Sync
+
'static
,
{
fn
drop
(
&
mut
self
)
{
self
.client
.close
();
}
}
fn
connect_to
<
SentMessageType
,
ReceivedMessageType
,
T
:
ToString
>
(
remote_host
:
T
,
)
->
crate
::
events
::
RemoteEventResult
<
RemoteEventDispatcher
<
SentMessageType
,
ReceivedMessageType
>>
...
...
@@ -61,6 +77,7 @@ where
)
>
=
SystemState
::
new
(
&
mut
world
);
let
mut
client_to_insert
=
None
;
let
mut
remove_client
=
false
;
{
let
(
mut
maybe_client
,
mut
reader
):
(
...
...
@@ -68,6 +85,18 @@ where
EventReader
<
SocketControlEvent
>
,
)
=
state
.get_mut
(
&
mut
world
);
if
let
Some
(
ref
client
)
=
maybe_client
{
if
client
.client.status
.borrow
()
.deref
()
==
&
wasm_sockets
::
ConnectionStatus
::
Disconnected
{
#[rustfmt::skip]
// rustfmt breaks the ending "();" to put ");" on its own line...
let
it
=
world
.remove_non_send_resource
::
<
RemoteEventDispatcher
<
SentMessageType
,
ReceivedMessageType
>>
();
drop
(
it
);
return
;
}
}
for
event
in
reader
.iter
()
{
match
event
{
SocketControlEvent
::
Create
(
url
)
=>
{
...
...
@@ -90,7 +119,7 @@ where
}
SocketControlEvent
::
Disconnect
=>
match
maybe_client
{
Some
(
ref
client
)
=>
{
log
::
warn!
(
"NOT IMPLEMENTED: Disconnect"
)
;
remove_client
=
true
;
}
None
=>
{
log
::
warn!
(
"There was no connection to disconnect from"
);
...
...
@@ -100,6 +129,13 @@ where
}
};
if
remove_client
{
#[rustfmt::skip]
// rustfmt breaks the ending "();" to put ");" on its own line...
let
it
=
world
.remove_non_send_resource
::
<
RemoteEventDispatcher
<
SentMessageType
,
ReceivedMessageType
>>
();
drop
(
it
);
}
if
let
Some
(
new_client
)
=
client_to_insert
{
world
.insert_non_send_resource
(
new_client
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment