Created
June 23, 2022 05:29
-
-
Save sombochea/eb5dc78b467a6510951aa775794b6134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cubetiqs.rps.example; | |
import com.cubetiqs.sdk.rps.RpsClient; | |
import com.cubetiqs.sdk.shared.util.JsonUtil; | |
import com.cubetiqs.sdk.socketio.Utils; | |
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* @author sombochea | |
*/ | |
public class CheckInMain { | |
@JsonIgnoreProperties(ignoreUnknown = true) | |
public static class CheckInPayload { | |
private String room; | |
public void setRoom(String room) { | |
this.room = room; | |
} | |
public String getRoom() { | |
return room; | |
} | |
public static CheckInPayload fromObject(Object payload) { | |
String json = Utils.toJson(payload); | |
return JsonUtil.fromJson(json, CheckInPayload.class); | |
} | |
@Override | |
public String toString() { | |
return Utils.toJson(this); | |
} | |
} | |
public static class CheckInStatus { | |
private String status; | |
private String message; | |
public void setStatus(String status) { | |
this.status = status; | |
} | |
public String getStatus() { | |
return status; | |
} | |
public void setMessage(String message) { | |
this.message = message; | |
} | |
public String getMessage() { | |
return message; | |
} | |
} | |
public static void main(String[] args) throws InterruptedException { | |
RpsClient.initialize(); | |
RpsClient.listenAsync("checkin", (payload) -> { | |
try { | |
CheckInPayload model = CheckInPayload.fromObject(payload); | |
System.out.println("CheckIn Payload = " + model); | |
// Delay for testing mode ( seconds) | |
TimeUnit.SECONDS.sleep(2); | |
// Validation and submit data to database... | |
// ... | |
// Broadcast checkin sttatus back to client | |
CheckInStatus status = new CheckInStatus(); | |
if (model != null && model.getRoom() != null) { | |
status.setStatus("SUCCEED"); | |
status.setMessage("Checkin was successfully!"); | |
} else { | |
status.setStatus("FAILED"); | |
status.setMessage("Checkin was failed!"); | |
} | |
RpsClient.broadcastAsync("checkin_status", status); | |
} catch (InterruptedException ex) { | |
} | |
}); | |
// Just await it with 5 minutes | |
TimeUnit.MINUTES.sleep(5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment