added skeleton for websockets
This commit is contained in:
parent
7cd2b44a44
commit
749d79d51e
3 changed files with 51 additions and 0 deletions
|
@ -15,6 +15,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
|
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'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||||
|
|
|
@ -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() {}
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue