Add Session ID
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Hamcha 2019-09-24 09:53:49 +02:00
parent c30b4c46e0
commit ad4d654abd
Signed by: hamcha
GPG key ID: 44AD3571EB09A39E
6 changed files with 26 additions and 3 deletions

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: