diff --git a/build.gradle b/build.gradle index d511c0b..4f4082f 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,7 @@ repositories { dependencies { compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final' + compile "org.springframework.boot:spring-boot-starter-websocket" implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java new file mode 100644 index 0000000..2e6de11 --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/HouseEndpoint.java @@ -0,0 +1,24 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.websocket; + +import java.io.IOException; +import javax.websocket.*; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint( + value = + "theEndpointMustHaveAShotNameBecauseAndreaBritesMartesMaronesIsAVeryNiceProgrammerThatMustTypeThisByHand.exe") // DONE: choose path +public class HouseEndpoint { + private Session session; + + @OnOpen + public void onOpen(Session session) throws IOException {} + + @OnMessage + public void onMessage() throws IOException {} + + @OnClose + public void onClose() {} + + @OnError + public void onError() {} +} diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java new file mode 100644 index 0000000..d5ea39a --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/websocket/WebSocketConfig.java @@ -0,0 +1,26 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.websocket; + +import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.simp.config.MessageBrokerRegistry; +import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; +import org.springframework.web.socket.config.annotation.StompEndpointRegistry; +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; + +@Configuration +@EnableWebSocketMessageBroker +public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { + + @Override + public void registerStompEndpoints(StompEndpointRegistry registry) { + registry.addEndpoint("/house") + .setAllowedOrigins("domainURL") + .withSockJS(); // TODO: set domain URL + } + + /** Creates message brokers in-memory to send and receive messages for topic and queue route */ + @Override + public void configureMessageBroker(MessageBrokerRegistry config) { + config.enableSimpleBroker("/topic/", "/queue/"); + config.setApplicationDestinationPrefixes("/app"); + } +}