Add Lobby #43
3 changed files with 17 additions and 10 deletions
|
@ -14,10 +14,10 @@ const actions: ActionTree<NetworkState, AppState> = {
|
||||||
const client = new PeerClient(options.playerInfo, options._customPeer);
|
const client = new PeerClient(options.playerInfo, options._customPeer);
|
||||||
commit("becomeClient", { peer: client });
|
commit("becomeClient", { peer: client });
|
||||||
client.on("connected", () => {
|
client.on("connected", () => {
|
||||||
commit("connected");
|
commit("connectionStatusChanged", "connected");
|
||||||
});
|
});
|
||||||
client.on("disconnected", () => {
|
client.on("disconnected", () => {
|
||||||
commit("disconnected");
|
commit("connectionStatusChanged", "disconnected");
|
||||||
});
|
});
|
||||||
client.on("error", err => {
|
client.on("error", err => {
|
||||||
commit("connectionError", err);
|
commit("connectionError", err);
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
import { MutationTree } from "vuex";
|
import { MutationTree } from "vuex";
|
||||||
import { NetworkState, ServerNetworkState, ClientNetworkState } from "./types";
|
import {
|
||||||
|
NetworkState,
|
||||||
|
ServerNetworkState,
|
||||||
|
ClientNetworkState,
|
||||||
|
ConnectionStatus
|
||||||
|
} from "./types";
|
||||||
import { LocalClient, PeerServer, PeerClient } from "@/network";
|
import { LocalClient, PeerServer, PeerClient } from "@/network";
|
||||||
|
|
||||||
const mutations: MutationTree<NetworkState> = {
|
const mutations: MutationTree<NetworkState> = {
|
||||||
|
@ -15,12 +20,8 @@ const mutations: MutationTree<NetworkState> = {
|
||||||
(state as ClientNetworkState).peer = payload.peer;
|
(state as ClientNetworkState).peer = payload.peer;
|
||||||
},
|
},
|
||||||
|
|
||||||
connected(state) {
|
connectionStatusChanged(state, status: ConnectionStatus) {
|
||||||
(state as ClientNetworkState).connectionStatus = "connected";
|
(state as ClientNetworkState).connectionStatus = status;
|
||||||
},
|
|
||||||
|
|
||||||
disconnected(state) {
|
|
||||||
(state as ClientNetworkState).connectionStatus = "disconnected";
|
|
||||||
},
|
},
|
||||||
|
|
||||||
connectionError(state, error) {
|
connectionError(state, error) {
|
||||||
|
|
|
@ -7,6 +7,12 @@ import {
|
||||||
} from "@/network";
|
} from "@/network";
|
||||||
import Peer from "peerjs";
|
import Peer from "peerjs";
|
||||||
|
|
||||||
|
export type ConnectionStatus =
|
||||||
|
| "connecting"
|
||||||
|
| "connected"
|
||||||
|
| "disconnected"
|
||||||
|
| "error";
|
||||||
|
|
||||||
export interface ChatMessage {
|
export interface ChatMessage {
|
||||||
who: string;
|
who: string;
|
||||||
to: string;
|
to: string;
|
||||||
|
@ -23,7 +29,7 @@ export interface NoNetworkState extends SharedNetworkState {
|
||||||
|
|
||||||
export interface ClientNetworkState extends SharedNetworkState {
|
export interface ClientNetworkState extends SharedNetworkState {
|
||||||
peerType: "client";
|
peerType: "client";
|
||||||
connectionStatus: "connecting" | "connected" | "disconnected" | "error";
|
connectionStatus: ConnectionStatus;
|
||||||
connectionError?: Error;
|
connectionError?: Error;
|
||||||
peer: PeerClient;
|
peer: PeerClient;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue