UNPKG

friend-connect

Version:

**BEFORE YOU USE THIS TOOL, PLEASE READ THE FOLLOWING: WE _AS CONTRIBUTORS_ ARE NOT RESPONSIBLE FOR ANY DAMAGE OR LOSS CAUSED BY THIS APP. USE AN ALT ACCOUNT, JUST IN CASE THERE IS AN ISSUE WITH THIS METHOD.**

164 lines (163 loc) 6.73 kB
export default class SessionDirectory { constructor(xboxLiveClient) { this.xbox = xboxLiveClient; } /** * Creates queries for session handles that include related session information. */ async queryHandles(xuid, moniker, serviceConfigId, includeRelatedInfo) { const res = await fetch(`${SessionDirectory.uri}/handles/query${includeRelatedInfo ? "?include=relatedInfo" : ""}`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, body: JSON.stringify({ owners: { people: { moniker: moniker ?? "people", monikerXuid: xuid, }, }, scid: serviceConfigId, type: "activity", }), }); //@ts-ignore let data = res.json(); return data.results; } setActivity(sessionReference) { return fetch(`${SessionDirectory.uri}/handles`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, body: JSON.stringify({ version: 1, type: "activity", sessionRef: sessionReference, }), }); } invite(sessionReference, inviteAttributes) { return fetch(`${SessionDirectory.uri}/handles`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, body: JSON.stringify({ version: 1, type: "invite", sessionRef: sessionReference, inviteAttributes, }), }); } /** * This method creates, joins, or updates a session, depending on what subset of the same JSON request body template is sent. On success, it returns a MultiplayerSession object containing the response returned from the server. The attributes in it might be different from the attributes in the passed-in MultiplayerSession object. */ session(multiplayerSessionRequest, serviceConfigId, sessionTemplateName, sessionName) { return fetch(`${SessionDirectory.uri}/serviceconfigs/${serviceConfigId}/sessionTemplates/${sessionTemplateName}/sessions/${sessionName}`, { method: "PUT", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, body: JSON.stringify(multiplayerSessionRequest), }); } getSession(serviceConfigId, queries) { return fetch(`${SessionDirectory.uri}/serviceconfigs/${serviceConfigId}/batch${new URLSearchParams( //@ts-ignore queries)})}`, { method: "GET", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, }); } sessionKeepAlivePacket(serviceConfigId, sessionTemplateName, sessionName) { return fetch(`${SessionDirectory.uri}/serviceconfigs/${serviceConfigId}/sessionTemplates/${sessionTemplateName}/sessions/${sessionName}`, { method: "GET", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, }); } removeMember(serviceConfigId, sessionTemplateName, sessionName, index) { return fetch(`${SessionDirectory.uri}/serviceconfigs/${serviceConfigId}/sessionTemplates/${sessionTemplateName}/sessions/${sessionName}/members/${index}`, { method: "DELETE", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, }); } getTemplates(serviceConfigId) { return fetch(`${SessionDirectory.uri}/serviceconfigs/${serviceConfigId}/sessiontemplates`, { method: "DELETE", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, }); } //Return removeServer(serviceConfigId, sessionTemplateName, sessionName, serverName) { return fetch(`${SessionDirectory.uri}/serviceconfigs/${serviceConfigId}/sessionTemplates/${sessionTemplateName}/sessions/${sessionName}/servers/${serverName}`, { method: "DELETE", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, }); } batchQuery(serviceConfigId, xuids, queries) { return fetch(`${SessionDirectory.uri}/serviceconfigs/${serviceConfigId}/batch${new URLSearchParams( //@ts-ignore queries)}`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, body: JSON.stringify({ xuids }), }); } deleteHandle(handleId) { return fetch(`${SessionDirectory.uri}/handles/${handleId}`, { method: "DELETE", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, }); } getHandle(handleId) { return fetch(`${SessionDirectory.uri}/handles/${handleId}`, { method: "GET", headers: { "Content-Type": "application/json", Authorization: this.xbox.authorizationHeader, "x-xbl-contract-version": "107", }, }); } } SessionDirectory.uri = "https://sessiondirectory.xboxlive.com";