Add Lobby #43

Merged
hamcha merged 18 commits from feature/lobby into master 2019-10-16 08:31:04 +00:00
6 changed files with 26 additions and 3 deletions
Showing only changes of commit ad4d654abd - Show all commits

View File

@ -12,7 +12,7 @@ const actions: ActionTree<NetworkState, AppState> = {
connect({ commit }, options: ConnectOptions) {
const client = new PeerClient(options.playerInfo, options._customPeer);
commit("becomeClient", { peer: client });
commit("becomeClient", { peer: client, id: options.serverID });
client.on("connected", () => {
commit("connectionStatusChanged", "connected");
});

View File

@ -13,6 +13,16 @@ const getters: GetterTree<NetworkState, AppState> = {
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" {
return state.peerType;
},

View File

@ -12,6 +12,9 @@ export const state: NetworkState = {
peerType: "none",
connectionStatus: null,
peer: null,
server: null,
local: null,
serverID: null,
chatLog: []
};

View File

@ -14,10 +14,11 @@ const mutations: MutationTree<NetworkState> = {
(state as ServerNetworkState).server = payload.server;
},
becomeClient(state, payload: { peer: PeerClient }) {
becomeClient(state, payload: { peer: PeerClient; id: string }) {
state.peerType = "client";
(state as ClientNetworkState).connectionStatus = "connecting";
(state as ClientNetworkState).peer = payload.peer;
(state as ClientNetworkState).serverID = payload.id;
},
connectionStatusChanged(state, status: ConnectionStatus) {

View File

@ -28,6 +28,9 @@ export interface NoNetworkState extends SharedNetworkState {
connectionStatus: null;
connectionError?: Error;
peer: null;
server: null;
local: null;
serverID: null;
}
export interface ClientNetworkState extends SharedNetworkState {
@ -35,6 +38,7 @@ export interface ClientNetworkState extends SharedNetworkState {
connectionStatus: ConnectionStatus;
connectionError?: Error;
peer: PeerClient;
serverID: string;
}
export interface ServerNetworkState extends SharedNetworkState {

View File

@ -79,7 +79,9 @@
</section>
</section>
<section class="room" v-else>
<section class="info"></section>
<section class="info">
Session ID: {{ sessionID }}
</section>
</section>
</section>
</template>
@ -209,6 +211,9 @@ export default class Lobby extends Vue {
@Getter("inRoom", { namespace: "network" })
private inRoom!: boolean;
@Getter("sessionID", { namespace: "network"} )
private sessionID!: string | null;
private data() {
return {
playerName: