fix: clean up session and party presence

This commit is contained in:
iCrawl 2019-04-28 10:46:22 +02:00
parent 255c57e2ac
commit 039cb4bfbe
No known key found for this signature in database
GPG key ID: E41A6DB922EC2CFE
3 changed files with 24 additions and 31 deletions

3
.vscode/launch.json vendored
View file

@ -9,8 +9,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/dist/**/*.js" ],
"preLaunchTask": "build"
"outFiles": [ "${workspaceRoot}/dist/**/*.js" ]
}
]
}

15
.vscode/tasks.json vendored
View file

@ -1,15 +0,0 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "gulp",
"task": "build",
"problemMatcher": [
"$gulp-tsc"
]
}
]
}

View file

@ -96,6 +96,7 @@ export default class Activity implements Disposable {
}
public async allowSpectate(): Promise<State | void> {
if (!this._state) return;
const liveshare = await vsls.getApi();
if (!liveshare) return;
const join = await liveshare.share({ suppressNotification: true, access: vsls.Access.ReadOnly });
@ -109,19 +110,19 @@ export default class Activity implements Disposable {
}
public async disableSpectate(): Promise<State | void> {
if (!this._state) return;
const liveshare = await vsls.getApi();
if (!liveshare) return;
await liveshare.end();
this._state = {
...this._state,
spectateSecret: undefined,
instance: false
};
delete this._state.spectateSecret;
this._state.instance = false;
return this._state;
}
public async allowJoinRequests(): Promise<State | void> {
if (!this._state) return;
const liveshare = await vsls.getApi();
if (!liveshare) return;
const join = await liveshare.share({ suppressNotification: true });
@ -138,28 +139,36 @@ export default class Activity implements Disposable {
}
public async disableJoinRequests(): Promise<State | void> {
if (!this._state) return;
const liveshare = await vsls.getApi();
if (!liveshare) return;
await liveshare.end();
this._state = {
...this._state,
partyId: undefined,
partySize: undefined,
partyMax: undefined,
joinSecret: undefined,
instance: false
};
delete this._state.partyId;
delete this._state.partySize;
delete this._state.partyMax;
delete this._state.joinSecret;
this._state.instance = false;
return this._state;
}
public changePartyId(id?: string): State | void {
if (!this._state) return;
if (!id) {
delete this._state.partyId;
delete this._state.partySize;
delete this._state.partyMax;
this._state.instance = false;
return this._state;
}
this._state = {
...this._state,
partyId: id,
partySize: this._state.partySize ? this._state.partySize + 1 : 1,
partyMax: id ? 5 : undefined
partyMax: 5,
instance: true
};
return this._state;