@@ -682,6 +682,12 @@ public Route.Err.Handler logError(final Route.Err.Handler err) {
682682 };
683683 }
684684
685+ public WebSocket .Definition ws (final String path , final WebSocket .Handler handler ) {
686+ WebSocket .Definition ws = new WebSocket .Definition (path , handler );
687+ bag .add (ws );
688+ return ws ;
689+ }
690+
685691 /**
686692 * <h1>Bootstrap</h1>
687693 * <p>
@@ -765,6 +771,10 @@ public void configure(final Binder binder) {
765771 Multibinder <Route .Definition > definitions = Multibinder
766772 .newSetBinder (binder , Route .Definition .class );
767773
774+ // Web Sockets
775+ Multibinder <WebSocket .Definition > sockets = Multibinder
776+ .newSetBinder (binder , WebSocket .Definition .class );
777+
768778 // Request Modules
769779 Multibinder <Request .Module > requestModule = Multibinder
770780 .newSetBinder (binder , Request .Module .class );
@@ -777,12 +787,14 @@ public void configure(final Binder binder) {
777787 binder .bind (File .class ).annotatedWith (Names .named ("java.io.tmpdir" ))
778788 .toInstance (new File (config .getString ("java.io.tmpdir" )));
779789
780- // modules and routes
790+ // modules, routes and websockets
781791 bag .forEach (candidate -> {
782792 if (candidate instanceof Jooby .Module ) {
783793 install ((Jooby .Module ) candidate , mode , config , binder );
784794 } else if (candidate instanceof Route .Definition ) {
785795 definitions .addBinding ().toInstance ((Route .Definition ) candidate );
796+ } else if (candidate instanceof WebSocket .Definition ) {
797+ sockets .addBinding ().toInstance ((WebSocket .Definition ) candidate );
786798 } else {
787799 Class <?> routeClass = (Class <?>) candidate ;
788800 Routes .routes (mode , routeClass )
0 commit comments