File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
example/clock/backend/lib Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,9 @@ import 'package:spinify/spinify.dart';
99void runServer () => l.capture (
1010 () => runZonedGuarded <void >(
1111 () async {
12+ const url = 'ws://centrifugo:8000/connection/websocket' ;
1213 final spinify = Spinify .connect (
13- 'ws://centrifugo:8000/connection/websocket' ,
14+ url ,
1415 config: SpinifyConfig (
1516 client: (name: 'Server' , version: '1.0.0' ),
1617 logger: (level, event, message, context) => l.log (
@@ -36,11 +37,20 @@ void runServer() => l.capture(
3637 spinify.newSubscription ('clock' , subscribe: true );
3738 final encoder = const JsonEncoder ().fuse (const Utf8Encoder ());
3839 Timer .periodic (const Duration (seconds: 1 ), (timer) {
40+ // If not connected - try to reconnect
41+ if (spinify.state.isDisconnected) {
42+ spinify.connect (url);
43+ return ;
44+ }
45+
46+ // If the subscription is not active, do nothing
3947 if (! subscription.state.isSubscribed) return ;
48+
49+ // Publish the current time
4050 final now = DateTime .now ();
4151 subscription.publish (
4252 encoder.convert (
43- {
53+ < String , Object ? > {
4454 'hour' : now.hour,
4555 'minute' : now.minute,
4656 'second' : now.second,
You can’t perform that action at this time.
0 commit comments