WebsocketContainer.js 601 B

123456789101112131415161718192021222324252627282930313233
  1. import { Container } from 'unstated';
  2. import io from 'socket.io-client';
  3. /**
  4. * Service container related to options for WebSocket
  5. * @extends {Container} unstated Container
  6. */
  7. export default class WebsocketContainer extends Container {
  8. constructor(appContainer) {
  9. super();
  10. this.appContainer = appContainer;
  11. this.appContainer.registerContainer(this);
  12. this.socket = io();
  13. this.socketClientId = Math.floor(Math.random() * 100000);
  14. this.state = {
  15. };
  16. }
  17. getWebSocket() {
  18. return this.socket;
  19. }
  20. getCocketClientId() {
  21. return this.socketClientId;
  22. }
  23. }