Add Lobby #43
6 changed files with 26 additions and 3 deletions
|
@ -12,7 +12,7 @@ const actions: ActionTree<NetworkState, AppState> = {
|
||||||
|
|
||||||
connect({ commit }, options: ConnectOptions) {
|
connect({ commit }, options: ConnectOptions) {
|
||||||
const client = new PeerClient(options.playerInfo, options._customPeer);
|
const client = new PeerClient(options.playerInfo, options._customPeer);
|
||||||
commit("becomeClient", { peer: client });
|
commit("becomeClient", { peer: client, id: options.serverID });
|
||||||
client.on("connected", () => {
|
client.on("connected", () => {
|
||||||
commit("connectionStatusChanged", "connected");
|
commit("connectionStatusChanged", "connected");
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,6 +13,16 @@ const getters: GetterTree<NetworkState, AppState> = {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sessionID(state): string | null {
|
||||||
|
switch (state.peerType) {
|
||||||
|
case "server":
|
||||||
|
return state.server.id;
|
||||||
|
case "client":
|
||||||
|
return state.serverID;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
connectionType(state): "client" | "server" | "none" {
|
connectionType(state): "client" | "server" | "none" {
|
||||||
return state.peerType;
|
return state.peerType;
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,6 +12,9 @@ export const state: NetworkState = {
|
||||||
peerType: "none",
|
peerType: "none",
|
||||||
connectionStatus: null,
|
connectionStatus: null,
|
||||||
peer: null,
|
peer: null,
|
||||||
|
server: null,
|
||||||
|
local: null,
|
||||||
|
serverID: null,
|
||||||
chatLog: []
|
chatLog: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,11 @@ const mutations: MutationTree<NetworkState> = {
|
||||||
(state as ServerNetworkState).server = payload.server;
|
(state as ServerNetworkState).server = payload.server;
|
||||||
},
|
},
|
||||||
|
|
||||||
becomeClient(state, payload: { peer: PeerClient }) {
|
becomeClient(state, payload: { peer: PeerClient; id: string }) {
|
||||||
state.peerType = "client";
|
state.peerType = "client";
|
||||||
(state as ClientNetworkState).connectionStatus = "connecting";
|
(state as ClientNetworkState).connectionStatus = "connecting";
|
||||||
(state as ClientNetworkState).peer = payload.peer;
|
(state as ClientNetworkState).peer = payload.peer;
|
||||||
|
(state as ClientNetworkState).serverID = payload.id;
|
||||||
},
|
},
|
||||||
|
|
||||||
connectionStatusChanged(state, status: ConnectionStatus) {
|
connectionStatusChanged(state, status: ConnectionStatus) {
|
||||||
|
|
|
@ -28,6 +28,9 @@ export interface NoNetworkState extends SharedNetworkState {
|
||||||
connectionStatus: null;
|
connectionStatus: null;
|
||||||
connectionError?: Error;
|
connectionError?: Error;
|
||||||
peer: null;
|
peer: null;
|
||||||
|
server: null;
|
||||||
|
local: null;
|
||||||
|
serverID: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientNetworkState extends SharedNetworkState {
|
export interface ClientNetworkState extends SharedNetworkState {
|
||||||
|
@ -35,6 +38,7 @@ export interface ClientNetworkState extends SharedNetworkState {
|
||||||
connectionStatus: ConnectionStatus;
|
connectionStatus: ConnectionStatus;
|
||||||
connectionError?: Error;
|
connectionError?: Error;
|
||||||
peer: PeerClient;
|
peer: PeerClient;
|
||||||
|
serverID: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServerNetworkState extends SharedNetworkState {
|
export interface ServerNetworkState extends SharedNetworkState {
|
||||||
|
|
|
@ -79,7 +79,9 @@
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
<section class="room" v-else>
|
<section class="room" v-else>
|
||||||
<section class="info"></section>
|
<section class="info">
|
||||||
|
Session ID: {{ sessionID }}
|
||||||
|
</section>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
@ -209,6 +211,9 @@ export default class Lobby extends Vue {
|
||||||
@Getter("inRoom", { namespace: "network" })
|
@Getter("inRoom", { namespace: "network" })
|
||||||
private inRoom!: boolean;
|
private inRoom!: boolean;
|
||||||
|
|
||||||
|
@Getter("sessionID", { namespace: "network"} )
|
||||||
|
private sessionID!: string | null;
|
||||||
|
|
||||||
private data() {
|
private data() {
|
||||||
return {
|
return {
|
||||||
playerName:
|
playerName:
|
||||||
|
|
Loading…
Reference in a new issue