Add Session ID
This commit is contained in:
parent
c30b4c46e0
commit
ad4d654abd
6 changed files with 26 additions and 3 deletions
|
@ -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");
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -12,6 +12,9 @@ export const state: NetworkState = {
|
|||
peerType: "none",
|
||||
connectionStatus: null,
|
||||
peer: null,
|
||||
server: null,
|
||||
local: null,
|
||||
serverID: null,
|
||||
chatLog: []
|
||||
};
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue