@ughuuu/game_server 1.0.382 → 1.0.790

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/README.md +109 -24
  2. package/dist/ApiClient.js +2 -2
  3. package/dist/api/AchievementsApi.js +224 -0
  4. package/dist/api/AdminAchievementsApi.js +356 -0
  5. package/dist/api/AdminChatApi.js +2 -2
  6. package/dist/api/AdminGroupsApi.js +2 -2
  7. package/dist/api/AdminKVApi.js +2 -2
  8. package/dist/api/AdminLeaderboardsApi.js +2 -2
  9. package/dist/api/AdminLobbiesApi.js +2 -2
  10. package/dist/api/AdminNotificationsApi.js +2 -2
  11. package/dist/api/AdminSessionsApi.js +2 -2
  12. package/dist/api/AdminUsersApi.js +2 -2
  13. package/dist/api/AuthenticationApi.js +2 -2
  14. package/dist/api/ChatApi.js +141 -12
  15. package/dist/api/FriendsApi.js +2 -2
  16. package/dist/api/GroupsApi.js +69 -27
  17. package/dist/api/HealthApi.js +2 -2
  18. package/dist/api/HooksApi.js +2 -2
  19. package/dist/api/KVApi.js +2 -2
  20. package/dist/api/LeaderboardsApi.js +43 -2
  21. package/dist/api/LobbiesApi.js +44 -2
  22. package/dist/api/NotificationsApi.js +2 -2
  23. package/dist/api/PartiesApi.js +206 -22
  24. package/dist/api/UsersApi.js +2 -2
  25. package/dist/index.js +183 -10
  26. package/dist/model/AcceptPartyInviteRequest.js +109 -0
  27. package/dist/model/AdminCreateAchievementRequest.js +182 -0
  28. package/dist/model/AdminCreateKvEntry200Response.js +2 -2
  29. package/dist/model/AdminCreateKvEntryRequest.js +2 -2
  30. package/dist/model/AdminCreateLeaderboardRequest.js +2 -2
  31. package/dist/model/AdminCreateNotification400Response.js +2 -2
  32. package/dist/model/AdminCreateNotificationRequest.js +2 -2
  33. package/dist/model/AdminDeleteChatConversation200Response.js +2 -2
  34. package/dist/model/AdminEndLeaderboard200Response.js +2 -2
  35. package/dist/model/AdminEndLeaderboard200ResponseData.js +2 -2
  36. package/dist/model/AdminIncrementAchievementRequest.js +130 -0
  37. package/dist/model/AdminListAchievements200Response.js +118 -0
  38. package/dist/model/AdminListChatMessages200Response.js +2 -2
  39. package/dist/model/AdminListChatMessages200ResponseDataInner.js +20 -3
  40. package/dist/model/AdminListGroups200Response.js +2 -2
  41. package/dist/model/AdminListKvEntries200Response.js +2 -2
  42. package/dist/model/AdminListKvEntries200ResponseDataInner.js +2 -2
  43. package/dist/model/AdminListLobbies200Response.js +2 -2
  44. package/dist/model/AdminListLobbies200ResponseDataInner.js +32 -2
  45. package/dist/model/AdminListNotifications200Response.js +2 -2
  46. package/dist/model/AdminListNotifications200ResponseDataInner.js +15 -2
  47. package/dist/model/AdminListNotifications200ResponseMeta.js +2 -2
  48. package/dist/model/AdminListSessions200Response.js +2 -2
  49. package/dist/model/AdminListSessions200ResponseDataInner.js +2 -2
  50. package/dist/model/AdminRevokeAchievementRequest.js +118 -0
  51. package/dist/model/AdminSubmitLeaderboardScore200Response.js +2 -2
  52. package/dist/model/AdminSubmitLeaderboardScore200ResponseData.js +14 -2
  53. package/dist/model/AdminSubmitLeaderboardScoreRequest.js +20 -8
  54. package/dist/model/AdminUnlockAchievementRequest.js +122 -0
  55. package/dist/model/AdminUpdateAchievement200Response.js +181 -0
  56. package/dist/model/AdminUpdateAchievementRequest.js +145 -0
  57. package/dist/model/AdminUpdateGroup200Response.js +23 -2
  58. package/dist/model/AdminUpdateGroupRequest.js +11 -2
  59. package/dist/model/AdminUpdateKvEntryRequest.js +2 -2
  60. package/dist/model/AdminUpdateLeaderboardRecordRequest.js +2 -2
  61. package/dist/model/AdminUpdateLeaderboardRequest.js +2 -2
  62. package/dist/model/AdminUpdateLobby200Response.js +2 -2
  63. package/dist/model/AdminUpdateLobbyRequest.js +11 -2
  64. package/dist/model/AdminUpdateUser200Response.js +2 -2
  65. package/dist/model/AdminUpdateUser200ResponseData.js +2 -2
  66. package/dist/model/AdminUpdateUserRequest.js +2 -2
  67. package/dist/model/CallHook200Response.js +2 -2
  68. package/dist/model/CallHookRequest.js +2 -2
  69. package/dist/model/CancelGroupInvite200Response.js +2 -2
  70. package/dist/model/CancelJoinRequest200Response.js +2 -2
  71. package/dist/model/CancelPartyInviteRequest.js +109 -0
  72. package/dist/model/ChatUnreadCount200Response.js +2 -2
  73. package/dist/model/CreateFriendRequestRequest.js +2 -2
  74. package/dist/model/CreateGroupRequest.js +11 -2
  75. package/dist/model/CreateLobbyRequest.js +11 -2
  76. package/dist/model/CreatePartyRequest.js +2 -2
  77. package/dist/model/DeclinePartyInviteRequest.js +109 -0
  78. package/dist/model/DeleteNotifications200Response.js +2 -2
  79. package/dist/model/DeleteNotificationsRequest.js +2 -2
  80. package/dist/model/DemoteGroupMemberRequest.js +2 -2
  81. package/dist/model/DeviceLoginRequest.js +2 -2
  82. package/dist/model/ErrorResponse.js +2 -2
  83. package/dist/model/GetChatMessage200Response.js +196 -0
  84. package/dist/model/GetCurrentUser200Response.js +2 -2
  85. package/dist/model/GetCurrentUser200ResponseLinkedProviders.js +2 -2
  86. package/dist/model/GetKv200Response.js +2 -2
  87. package/dist/model/GetLobby200Response.js +133 -0
  88. package/dist/model/GetLobby200ResponseMembersInner.js +146 -0
  89. package/dist/model/GetMyRecord200Response.js +2 -2
  90. package/dist/model/HealthResponse.js +2 -2
  91. package/dist/model/InviteToGroup200Response.js +90 -0
  92. package/dist/model/InviteToGroupRequest.js +2 -2
  93. package/dist/model/InviteToPartyRequest.js +109 -0
  94. package/dist/model/KickGroupMemberRequest.js +2 -2
  95. package/dist/model/KickUserRequest.js +2 -2
  96. package/dist/model/LinkDeviceRequest.js +2 -2
  97. package/dist/model/ListBlockedFriends200Response.js +2 -2
  98. package/dist/model/ListBlockedFriends200ResponseDataInner.js +2 -2
  99. package/dist/model/ListBlockedFriends200ResponseDataInnerRequester.js +2 -2
  100. package/dist/model/ListChatMessages200Response.js +6 -6
  101. package/dist/model/ListFriendRequests200Response.js +2 -2
  102. package/dist/model/ListFriendRequests200ResponseIncomingInner.js +2 -2
  103. package/dist/model/ListFriendRequests200ResponseIncomingInnerRequester.js +11 -2
  104. package/dist/model/ListFriendRequests200ResponseMeta.js +2 -2
  105. package/dist/model/ListFriends200Response.js +2 -2
  106. package/dist/model/ListFriends200ResponseDataInner.js +11 -2
  107. package/dist/model/ListGroupInvitations200Response.js +2 -2
  108. package/dist/model/ListGroupInvitations200ResponseDataInner.js +48 -3
  109. package/dist/model/ListGroupMembers200Response.js +2 -2
  110. package/dist/model/ListGroupMembers200ResponseDataInner.js +2 -2
  111. package/dist/model/ListJoinRequests200Response.js +2 -2
  112. package/dist/model/ListLeaderboardRecords200Response.js +2 -2
  113. package/dist/model/ListLeaderboardRecords200ResponseDataInner.js +4 -4
  114. package/dist/model/ListLeaderboards200Response.js +2 -2
  115. package/dist/model/ListLeaderboards200ResponseDataInner.js +2 -2
  116. package/dist/model/ListLobbies200Response.js +2 -2
  117. package/dist/model/ListLobbies200ResponseDataInner.js +24 -2
  118. package/dist/model/ListMyGroups200Response.js +2 -2
  119. package/dist/model/ListMyGroups200ResponseDataInner.js +24 -2
  120. package/dist/model/ListNotifications200Response.js +2 -2
  121. package/dist/model/ListNotifications200ResponseDataInner.js +15 -2
  122. package/dist/model/ListPartyInvitations200ResponseInner.js +155 -0
  123. package/dist/model/ListRecordsAroundUser200Response.js +2 -2
  124. package/dist/model/ListSentInvitations200Response.js +2 -2
  125. package/dist/model/ListSentInvitations200ResponseDataInner.js +26 -2
  126. package/dist/model/Login200Response.js +2 -2
  127. package/dist/model/Login200ResponseData.js +15 -2
  128. package/dist/model/LoginRequest.js +2 -2
  129. package/dist/model/MarkChatReadRequest.js +8 -3
  130. package/dist/model/NotifyGroup200Response.js +2 -2
  131. package/dist/model/NotifyGroupRequest.js +3 -3
  132. package/dist/model/OAuthSessionData.js +15 -2
  133. package/dist/model/OAuthSessionDataDetails.js +2 -2
  134. package/dist/model/OAuthSessionStatus.js +2 -2
  135. package/dist/model/OauthApiCallback200Response.js +2 -2
  136. package/dist/model/OauthApiCallbackRequest.js +2 -2
  137. package/dist/model/OauthCallbackApiAppleIosRequest.js +2 -2
  138. package/dist/model/OauthGoogleIdTokenRequest.js +2 -2
  139. package/dist/model/OauthRequest200Response.js +2 -2
  140. package/dist/model/OauthSessionStatus404Response.js +2 -2
  141. package/dist/model/PartyCreateLobbyRequest.js +2 -2
  142. package/dist/model/PartyJoinLobbyRequest.js +2 -2
  143. package/dist/model/PromoteGroupMemberRequest.js +2 -2
  144. package/dist/model/QuickJoinRequest.js +2 -2
  145. package/dist/model/RefreshToken200Response.js +2 -2
  146. package/dist/model/RefreshToken200ResponseData.js +15 -2
  147. package/dist/model/RefreshTokenRequest.js +2 -2
  148. package/dist/model/ResolveLeaderboardSlugs200Response.js +89 -0
  149. package/dist/model/ResolveLeaderboardSlugsRequest.js +113 -0
  150. package/dist/model/SearchUsers200Response.js +2 -2
  151. package/dist/model/SearchUsers200ResponseDataInner.js +11 -2
  152. package/dist/model/SendChatMessageRequest.js +10 -5
  153. package/dist/model/SendNotificationRequest.js +2 -2
  154. package/dist/model/ShowParty200Response.js +13 -13
  155. package/dist/model/ShowParty200ResponseMembersInner.js +11 -2
  156. package/dist/model/UpdateChatMessageRequest.js +99 -0
  157. package/dist/model/UpdateCurrentUserDisplayNameRequest.js +2 -2
  158. package/dist/model/UpdateCurrentUserPassword400Response.js +2 -2
  159. package/dist/model/UpdateCurrentUserPasswordRequest.js +2 -2
  160. package/dist/model/UpdateGroupRequest.js +11 -2
  161. package/dist/model/UpdateLobbyRequest.js +11 -2
  162. package/dist/model/UpdatePartyRequest.js +2 -2
  163. package/dist/model/UserAchievements200Response.js +124 -0
  164. package/dist/model/UserAchievements200ResponseDataInner.js +192 -0
  165. package/dist/realtime.js +247 -0
  166. package/dist/webrtc.js +375 -0
  167. package/package.json +16 -23
  168. package/dist/model/CreateLobby401Response.js +0 -89
  169. package/dist/model/JoinLobby200Response.js +0 -89
  170. package/dist/model/JoinLobbyRequest.js +0 -90
  171. package/dist/model/JoinPartyByCodeRequest.js +0 -113
  172. package/dist/model/KickUser200Response.js +0 -89
  173. package/dist/model/LeaveLobby200Response.js +0 -89
  174. package/dist/model/ListChatMessages200ResponseDataInner.js +0 -170
  175. package/dist/model/ListLeaderboardRecords200ResponseMeta.js +0 -125
  176. package/dist/model/ListLobbies200ResponseInner.js +0 -153
  177. package/dist/model/ListLobbies200ResponseMeta.js +0 -125
  178. package/dist/model/Login200ResponseDataUser.js +0 -97
  179. package/dist/model/RemoveFriendship401Response.js +0 -89
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _ApiClient = _interopRequireDefault(require("../ApiClient"));
8
+ var _AdminListNotifications200ResponseMeta = _interopRequireDefault(require("./AdminListNotifications200ResponseMeta"));
9
+ var _UserAchievements200ResponseDataInner = _interopRequireDefault(require("./UserAchievements200ResponseDataInner"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
13
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
15
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
16
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
17
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
20
+ * Game Server API
21
+ * API for the Gamend Game Server. Has authentication, users, lobbies, groups, parties, friends, chat, notifications, achievements, leaderboards, server scripting and admin portal. ## **1. Authentication** This API uses JWT (JSON Web Tokens) with access and refresh tokens: ### **1.1 Getting Tokens** - **Email/Password**: POST to `/api/v1/login` with email and password - **Device (SDK)**: POST to `/api/v1/login` with a `device_id` string (creates/returns a device user) - **Discord OAuth**: Use `/api/v1/auth/discord` flow - **Google OAuth**: Use `/api/v1/auth/google` flow - **Facebook OAuth**: Use `/api/v1/auth/facebook` flow - **Apple Sign In**: Use `/auth/apple` browser flow or apple sdk flow - **Steam (OpenID)**: Use `/api/v1/auth/steam` flow Both methods return: - `access_token` - Short-lived (15 min), use for API requests - `refresh_token` - Long-lived (30 days), use to get new access tokens ### **1.2 Using Tokens** Include the access token in the Authorization header: ``` Authorization: Bearer <access_token> ``` ### **1.3 Refreshing Tokens** When your access token expires, use POST `/api/v1/refresh` with your refresh token to get a new access token. ## **2. Users** Users endpoints cover the user lifecycle and profile features. Key highlights: - **Registration and login** (email/password, device token for SDKs, and OAuth providers) - **Profile metadata** (JSON blob per user) and editable profile fields - **Account lifecycle**: password reset, email confirmation, and account deletion - **Sessions & tokens**: both browser sessions and JWT-based API tokens are supported ## **3. Friends** The Friends domain offers lightweight social features: - **Friend requests** (send / accept / reject / block flows) - **Friend listing & pagination**, with basic privacy controls - **Domain helpers** to manage and query friend relationships from API or UI contexts ## **4. Lobbies** Lobbies provide matchmaking / room management primitives. Highlights: - **Create / list / update / delete** lobbies with rich metadata (mode, region, tags) - **Host-managed or hostless** modes (hostless allowed internally, not creatable via public API) - **Membership management**: join, leave, kick users, and automatic host transfer - **Controls & protection**: max users, hidden/locked states, and optional password protection - **Hidden lobbies** are excluded from public listings; public listing endpoints are paginated ## **5. Notifications** Persistent user-to-user notifications that survive across sessions: - **Send notifications** to accepted friends with a title, optional content, and optional metadata - **List own notifications** with pagination (ordered oldest-first) - **Delete notifications** by ID (single or batch) - **Real-time delivery** via the user WebSocket channel (`\"notification\"` events) - **Offline delivery**: undeleted notifications are replayed on WebSocket reconnect ## **6. Groups** Groups provide persistent community management for players: - **Three group types**: `public` (anyone joins directly), `private` (users request to join, admins approve), `hidden` (invite-only, never listed) - **Membership roles**: `admin` and `member`, with promote/demote capabilities - **Join requests**: for private groups, users submit requests that admins approve or reject - **Invitations**: admins can invite users directly (blocked users are rejected) - **CRUD operations**: create, update, delete groups with metadata support - **Group chat**: integrated via the Chat API with `chat_type: \"group\"` ## **7. Parties** Ephemeral groups of users for short-lived sessions (e.g., matchmaking squads): - **Invite-only joining**: the party leader sends invites by user ID to friends or shared-group members - **Invite flow**: `POST /parties/invite` → recipient accepts via `POST /parties/invite/accept` or declines via `POST /parties/invite/decline`; leader can cancel via `POST /parties/invite/cancel` - **Invite visibility**: leader can list sent invites (`GET /parties/invitations/sent`); recipient can list received invites (`GET /parties/invitations`) - **Connection requirement**: invites can only be sent to users who are friends or share at least one group with the leader - **One party at a time**: a user can only be in one party; accepting an invite while already in a party is rejected - **Leader management**: the creator is the leader; leadership can be transferred - **Lobby integration**: parties can create or join lobbies as a group - **Party chat**: integrated via the Chat API with `chat_type: \"party\"` - **Real-time events** via the party WebSocket channel ## **8. Chat** Real-time messaging across multiple conversation types: - **Chat types**: `lobby` (within a lobby), `group` (within a group), `party` (within a party), `friend` (DMs between friends) - **Send messages** with content, optional metadata, and automatic access validation - **List messages** with pagination (newest first) - **Read tracking**: mark messages as read and get unread counts per conversation - **Real-time delivery** via PubSub and WebSocket channels - **Moderation hooks**: `before_chat_message` pipeline hook for filtering/blocking ## **9. Leaderboards** Server-managed ranked scoreboards: - **Multiple leaderboards**: create named leaderboards with configurable sort order - **Score submission**: submit scores with optional metadata - **Rankings**: retrieve paginated rankings with user details - **Reset support**: leaderboards can be reset periodically ## **10. Key-Value Storage** Per-user persistent key-value storage for game state, preferences, and settings: - **Get/set/delete** key-value pairs scoped to the authenticated user - **List keys** with optional prefix filtering - **Metadata support**: values can include arbitrary JSON metadata
22
+ *
23
+ * The version of the OpenAPI document: 1.0.790
24
+ *
25
+ *
26
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
27
+ * https://openapi-generator.tech
28
+ * Do not edit the class manually.
29
+ *
30
+ */
31
+ /**
32
+ * The UserAchievements200Response model module.
33
+ * @module model/UserAchievements200Response
34
+ * @version 1.0.0
35
+ */
36
+ var UserAchievements200Response = /*#__PURE__*/function () {
37
+ /**
38
+ * Constructs a new <code>UserAchievements200Response</code>.
39
+ * @alias module:model/UserAchievements200Response
40
+ */
41
+ function UserAchievements200Response() {
42
+ _classCallCheck(this, UserAchievements200Response);
43
+ UserAchievements200Response.initialize(this);
44
+ }
45
+
46
+ /**
47
+ * Initializes the fields of this object.
48
+ * This method is used by the constructors of any subclasses, in order to implement multiple inheritance (mix-ins).
49
+ * Only for internal use.
50
+ */
51
+ return _createClass(UserAchievements200Response, null, [{
52
+ key: "initialize",
53
+ value: function initialize(obj) {}
54
+
55
+ /**
56
+ * Constructs a <code>UserAchievements200Response</code> from a plain JavaScript object, optionally creating a new instance.
57
+ * Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
58
+ * @param {Object} data The plain JavaScript object bearing properties of interest.
59
+ * @param {module:model/UserAchievements200Response} obj Optional instance to populate.
60
+ * @return {module:model/UserAchievements200Response} The populated <code>UserAchievements200Response</code> instance.
61
+ */
62
+ }, {
63
+ key: "constructFromObject",
64
+ value: function constructFromObject(data, obj) {
65
+ if (data) {
66
+ obj = obj || new UserAchievements200Response();
67
+ if (data.hasOwnProperty('data')) {
68
+ obj['data'] = _ApiClient["default"].convertToType(data['data'], [_UserAchievements200ResponseDataInner["default"]]);
69
+ }
70
+ if (data.hasOwnProperty('meta')) {
71
+ obj['meta'] = _AdminListNotifications200ResponseMeta["default"].constructFromObject(data['meta']);
72
+ }
73
+ }
74
+ return obj;
75
+ }
76
+
77
+ /**
78
+ * Validates the JSON data with respect to <code>UserAchievements200Response</code>.
79
+ * @param {Object} data The plain JavaScript object bearing properties of interest.
80
+ * @return {boolean} to indicate whether the JSON data is valid with respect to <code>UserAchievements200Response</code>.
81
+ */
82
+ }, {
83
+ key: "validateJSON",
84
+ value: function validateJSON(data) {
85
+ if (data['data']) {
86
+ // data not null
87
+ // ensure the json data is an array
88
+ if (!Array.isArray(data['data'])) {
89
+ throw new Error("Expected the field `data` to be an array in the JSON data but got " + data['data']);
90
+ }
91
+ // validate the optional field `data` (array)
92
+ var _iterator = _createForOfIteratorHelper(data['data']),
93
+ _step;
94
+ try {
95
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
96
+ var item = _step.value;
97
+ _UserAchievements200ResponseDataInner["default"].validateJSON(item);
98
+ }
99
+ } catch (err) {
100
+ _iterator.e(err);
101
+ } finally {
102
+ _iterator.f();
103
+ }
104
+ ;
105
+ }
106
+ // validate the optional field `meta`
107
+ if (data['meta']) {
108
+ // data not null
109
+ _AdminListNotifications200ResponseMeta["default"].validateJSON(data['meta']);
110
+ }
111
+ return true;
112
+ }
113
+ }]);
114
+ }();
115
+ /**
116
+ * @member {Array.<module:model/UserAchievements200ResponseDataInner>} data
117
+ */
118
+ UserAchievements200Response.prototype['data'] = undefined;
119
+
120
+ /**
121
+ * @member {module:model/AdminListNotifications200ResponseMeta} meta
122
+ */
123
+ UserAchievements200Response.prototype['meta'] = undefined;
124
+ var _default = exports["default"] = UserAchievements200Response;
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _ApiClient = _interopRequireDefault(require("../ApiClient"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
11
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
12
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
15
+ * Game Server API
16
+ * API for the Gamend Game Server. Has authentication, users, lobbies, groups, parties, friends, chat, notifications, achievements, leaderboards, server scripting and admin portal. ## **1. Authentication** This API uses JWT (JSON Web Tokens) with access and refresh tokens: ### **1.1 Getting Tokens** - **Email/Password**: POST to `/api/v1/login` with email and password - **Device (SDK)**: POST to `/api/v1/login` with a `device_id` string (creates/returns a device user) - **Discord OAuth**: Use `/api/v1/auth/discord` flow - **Google OAuth**: Use `/api/v1/auth/google` flow - **Facebook OAuth**: Use `/api/v1/auth/facebook` flow - **Apple Sign In**: Use `/auth/apple` browser flow or apple sdk flow - **Steam (OpenID)**: Use `/api/v1/auth/steam` flow Both methods return: - `access_token` - Short-lived (15 min), use for API requests - `refresh_token` - Long-lived (30 days), use to get new access tokens ### **1.2 Using Tokens** Include the access token in the Authorization header: ``` Authorization: Bearer <access_token> ``` ### **1.3 Refreshing Tokens** When your access token expires, use POST `/api/v1/refresh` with your refresh token to get a new access token. ## **2. Users** Users endpoints cover the user lifecycle and profile features. Key highlights: - **Registration and login** (email/password, device token for SDKs, and OAuth providers) - **Profile metadata** (JSON blob per user) and editable profile fields - **Account lifecycle**: password reset, email confirmation, and account deletion - **Sessions & tokens**: both browser sessions and JWT-based API tokens are supported ## **3. Friends** The Friends domain offers lightweight social features: - **Friend requests** (send / accept / reject / block flows) - **Friend listing & pagination**, with basic privacy controls - **Domain helpers** to manage and query friend relationships from API or UI contexts ## **4. Lobbies** Lobbies provide matchmaking / room management primitives. Highlights: - **Create / list / update / delete** lobbies with rich metadata (mode, region, tags) - **Host-managed or hostless** modes (hostless allowed internally, not creatable via public API) - **Membership management**: join, leave, kick users, and automatic host transfer - **Controls & protection**: max users, hidden/locked states, and optional password protection - **Hidden lobbies** are excluded from public listings; public listing endpoints are paginated ## **5. Notifications** Persistent user-to-user notifications that survive across sessions: - **Send notifications** to accepted friends with a title, optional content, and optional metadata - **List own notifications** with pagination (ordered oldest-first) - **Delete notifications** by ID (single or batch) - **Real-time delivery** via the user WebSocket channel (`\"notification\"` events) - **Offline delivery**: undeleted notifications are replayed on WebSocket reconnect ## **6. Groups** Groups provide persistent community management for players: - **Three group types**: `public` (anyone joins directly), `private` (users request to join, admins approve), `hidden` (invite-only, never listed) - **Membership roles**: `admin` and `member`, with promote/demote capabilities - **Join requests**: for private groups, users submit requests that admins approve or reject - **Invitations**: admins can invite users directly (blocked users are rejected) - **CRUD operations**: create, update, delete groups with metadata support - **Group chat**: integrated via the Chat API with `chat_type: \"group\"` ## **7. Parties** Ephemeral groups of users for short-lived sessions (e.g., matchmaking squads): - **Invite-only joining**: the party leader sends invites by user ID to friends or shared-group members - **Invite flow**: `POST /parties/invite` → recipient accepts via `POST /parties/invite/accept` or declines via `POST /parties/invite/decline`; leader can cancel via `POST /parties/invite/cancel` - **Invite visibility**: leader can list sent invites (`GET /parties/invitations/sent`); recipient can list received invites (`GET /parties/invitations`) - **Connection requirement**: invites can only be sent to users who are friends or share at least one group with the leader - **One party at a time**: a user can only be in one party; accepting an invite while already in a party is rejected - **Leader management**: the creator is the leader; leadership can be transferred - **Lobby integration**: parties can create or join lobbies as a group - **Party chat**: integrated via the Chat API with `chat_type: \"party\"` - **Real-time events** via the party WebSocket channel ## **8. Chat** Real-time messaging across multiple conversation types: - **Chat types**: `lobby` (within a lobby), `group` (within a group), `party` (within a party), `friend` (DMs between friends) - **Send messages** with content, optional metadata, and automatic access validation - **List messages** with pagination (newest first) - **Read tracking**: mark messages as read and get unread counts per conversation - **Real-time delivery** via PubSub and WebSocket channels - **Moderation hooks**: `before_chat_message` pipeline hook for filtering/blocking ## **9. Leaderboards** Server-managed ranked scoreboards: - **Multiple leaderboards**: create named leaderboards with configurable sort order - **Score submission**: submit scores with optional metadata - **Rankings**: retrieve paginated rankings with user details - **Reset support**: leaderboards can be reset periodically ## **10. Key-Value Storage** Per-user persistent key-value storage for game state, preferences, and settings: - **Get/set/delete** key-value pairs scoped to the authenticated user - **List keys** with optional prefix filtering - **Metadata support**: values can include arbitrary JSON metadata
17
+ *
18
+ * The version of the OpenAPI document: 1.0.790
19
+ *
20
+ *
21
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
22
+ * https://openapi-generator.tech
23
+ * Do not edit the class manually.
24
+ *
25
+ */
26
+ /**
27
+ * The UserAchievements200ResponseDataInner model module.
28
+ * @module model/UserAchievements200ResponseDataInner
29
+ * @version 1.0.0
30
+ */
31
+ var UserAchievements200ResponseDataInner = /*#__PURE__*/function () {
32
+ /**
33
+ * Constructs a new <code>UserAchievements200ResponseDataInner</code>.
34
+ * @alias module:model/UserAchievements200ResponseDataInner
35
+ */
36
+ function UserAchievements200ResponseDataInner() {
37
+ _classCallCheck(this, UserAchievements200ResponseDataInner);
38
+ UserAchievements200ResponseDataInner.initialize(this);
39
+ }
40
+
41
+ /**
42
+ * Initializes the fields of this object.
43
+ * This method is used by the constructors of any subclasses, in order to implement multiple inheritance (mix-ins).
44
+ * Only for internal use.
45
+ */
46
+ return _createClass(UserAchievements200ResponseDataInner, null, [{
47
+ key: "initialize",
48
+ value: function initialize(obj) {}
49
+
50
+ /**
51
+ * Constructs a <code>UserAchievements200ResponseDataInner</code> from a plain JavaScript object, optionally creating a new instance.
52
+ * Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
53
+ * @param {Object} data The plain JavaScript object bearing properties of interest.
54
+ * @param {module:model/UserAchievements200ResponseDataInner} obj Optional instance to populate.
55
+ * @return {module:model/UserAchievements200ResponseDataInner} The populated <code>UserAchievements200ResponseDataInner</code> instance.
56
+ */
57
+ }, {
58
+ key: "constructFromObject",
59
+ value: function constructFromObject(data, obj) {
60
+ if (data) {
61
+ obj = obj || new UserAchievements200ResponseDataInner();
62
+ if (data.hasOwnProperty('description')) {
63
+ obj['description'] = _ApiClient["default"].convertToType(data['description'], 'String');
64
+ }
65
+ if (data.hasOwnProperty('hidden')) {
66
+ obj['hidden'] = _ApiClient["default"].convertToType(data['hidden'], 'Boolean');
67
+ }
68
+ if (data.hasOwnProperty('icon_url')) {
69
+ obj['icon_url'] = _ApiClient["default"].convertToType(data['icon_url'], 'String');
70
+ }
71
+ if (data.hasOwnProperty('id')) {
72
+ obj['id'] = _ApiClient["default"].convertToType(data['id'], 'Number');
73
+ }
74
+ if (data.hasOwnProperty('metadata')) {
75
+ obj['metadata'] = _ApiClient["default"].convertToType(data['metadata'], Object);
76
+ }
77
+ if (data.hasOwnProperty('progress')) {
78
+ obj['progress'] = _ApiClient["default"].convertToType(data['progress'], 'Number');
79
+ }
80
+ if (data.hasOwnProperty('progress_target')) {
81
+ obj['progress_target'] = _ApiClient["default"].convertToType(data['progress_target'], 'Number');
82
+ }
83
+ if (data.hasOwnProperty('slug')) {
84
+ obj['slug'] = _ApiClient["default"].convertToType(data['slug'], 'String');
85
+ }
86
+ if (data.hasOwnProperty('sort_order')) {
87
+ obj['sort_order'] = _ApiClient["default"].convertToType(data['sort_order'], 'Number');
88
+ }
89
+ if (data.hasOwnProperty('title')) {
90
+ obj['title'] = _ApiClient["default"].convertToType(data['title'], 'String');
91
+ }
92
+ if (data.hasOwnProperty('unlocked_at')) {
93
+ obj['unlocked_at'] = _ApiClient["default"].convertToType(data['unlocked_at'], 'Date');
94
+ }
95
+ }
96
+ return obj;
97
+ }
98
+
99
+ /**
100
+ * Validates the JSON data with respect to <code>UserAchievements200ResponseDataInner</code>.
101
+ * @param {Object} data The plain JavaScript object bearing properties of interest.
102
+ * @return {boolean} to indicate whether the JSON data is valid with respect to <code>UserAchievements200ResponseDataInner</code>.
103
+ */
104
+ }, {
105
+ key: "validateJSON",
106
+ value: function validateJSON(data) {
107
+ // ensure the json data is a string
108
+ if (data['description'] && !(typeof data['description'] === 'string' || data['description'] instanceof String)) {
109
+ throw new Error("Expected the field `description` to be a primitive type in the JSON string but got " + data['description']);
110
+ }
111
+ // ensure the json data is a string
112
+ if (data['icon_url'] && !(typeof data['icon_url'] === 'string' || data['icon_url'] instanceof String)) {
113
+ throw new Error("Expected the field `icon_url` to be a primitive type in the JSON string but got " + data['icon_url']);
114
+ }
115
+ // ensure the json data is a string
116
+ if (data['slug'] && !(typeof data['slug'] === 'string' || data['slug'] instanceof String)) {
117
+ throw new Error("Expected the field `slug` to be a primitive type in the JSON string but got " + data['slug']);
118
+ }
119
+ // ensure the json data is a string
120
+ if (data['title'] && !(typeof data['title'] === 'string' || data['title'] instanceof String)) {
121
+ throw new Error("Expected the field `title` to be a primitive type in the JSON string but got " + data['title']);
122
+ }
123
+ return true;
124
+ }
125
+ }]);
126
+ }();
127
+ /**
128
+ * Description
129
+ * @member {String} description
130
+ */
131
+ UserAchievements200ResponseDataInner.prototype['description'] = undefined;
132
+
133
+ /**
134
+ * Whether hidden until unlocked
135
+ * @member {Boolean} hidden
136
+ */
137
+ UserAchievements200ResponseDataInner.prototype['hidden'] = undefined;
138
+
139
+ /**
140
+ * Icon URL
141
+ * @member {String} icon_url
142
+ */
143
+ UserAchievements200ResponseDataInner.prototype['icon_url'] = undefined;
144
+
145
+ /**
146
+ * Achievement ID
147
+ * @member {Number} id
148
+ */
149
+ UserAchievements200ResponseDataInner.prototype['id'] = undefined;
150
+
151
+ /**
152
+ * Arbitrary metadata
153
+ * @member {Object} metadata
154
+ */
155
+ UserAchievements200ResponseDataInner.prototype['metadata'] = undefined;
156
+
157
+ /**
158
+ * Current user progress (0 if unauthenticated)
159
+ * @member {Number} progress
160
+ */
161
+ UserAchievements200ResponseDataInner.prototype['progress'] = undefined;
162
+
163
+ /**
164
+ * Steps to complete (1 = one-shot)
165
+ * @member {Number} progress_target
166
+ */
167
+ UserAchievements200ResponseDataInner.prototype['progress_target'] = undefined;
168
+
169
+ /**
170
+ * Unique identifier
171
+ * @member {String} slug
172
+ */
173
+ UserAchievements200ResponseDataInner.prototype['slug'] = undefined;
174
+
175
+ /**
176
+ * Display order
177
+ * @member {Number} sort_order
178
+ */
179
+ UserAchievements200ResponseDataInner.prototype['sort_order'] = undefined;
180
+
181
+ /**
182
+ * Display title
183
+ * @member {String} title
184
+ */
185
+ UserAchievements200ResponseDataInner.prototype['title'] = undefined;
186
+
187
+ /**
188
+ * When the user unlocked this (null if not unlocked)
189
+ * @member {Date} unlocked_at
190
+ */
191
+ UserAchievements200ResponseDataInner.prototype['unlocked_at'] = undefined;
192
+ var _default = exports["default"] = UserAchievements200ResponseDataInner;
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = exports.GameRealtime = void 0;
7
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
11
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
12
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
13
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
15
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
+ /**
17
+ * GameRealtime — Phoenix WebSocket client for game_server.
18
+ *
19
+ * Wraps Phoenix.Socket to provide helpers for common game_server channel topics.
20
+ * Requires the `phoenix` npm package (peer dependency).
21
+ *
22
+ * Usage (browser / Node.js with bundler):
23
+ *
24
+ * import { GameRealtime } from '@ughuuu/game_server'
25
+ *
26
+ * const realtime = new GameRealtime('https://your-server.com', accessToken)
27
+ *
28
+ * // Join the authenticated user channel
29
+ * const userChannel = realtime.joinUserChannel(userId)
30
+ * userChannel.on('notification', (payload) => console.log('notification:', payload))
31
+ * userChannel.on('updated', (payload) => console.log('user updated:', payload))
32
+ *
33
+ * // Join a lobby channel
34
+ * const lobbyChannel = realtime.joinLobbyChannel(lobbyId)
35
+ * lobbyChannel.on('updated', (payload) => console.log('lobby event:', payload))
36
+ *
37
+ * realtime.disconnect()
38
+ *
39
+ * Peer dependency:
40
+ *
41
+ * npm install phoenix
42
+ */
43
+
44
+ var _Socket = null;
45
+ try {
46
+ // Works in Node (bundled) and browser environments
47
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
48
+ _Socket = require('phoenix').Socket;
49
+ } catch (_) {
50
+ // Swallow — will throw a descriptive error at instantiation time
51
+ }
52
+ var GameRealtime = exports.GameRealtime = /*#__PURE__*/function () {
53
+ /**
54
+ * @param {string} serverUrl - Base HTTP(S) or WS(S) server URL,
55
+ * e.g. "https://game.example.com" or "wss://game.example.com"
56
+ * @param {string} token - JWT access token from the REST login endpoints
57
+ * @param {Object} socketOpts - Optional Phoenix.Socket constructor options
58
+ */
59
+ function GameRealtime(serverUrl, token) {
60
+ var socketOpts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
61
+ _classCallCheck(this, GameRealtime);
62
+ if (!_Socket) {
63
+ throw new Error('GameRealtime requires the "phoenix" npm package. Install it: npm install phoenix');
64
+ }
65
+
66
+ // Normalise URL: strip trailing slash, ensure ws(s):// scheme, append /socket
67
+ var wsUrl = serverUrl.replace(/\/$/, '').replace(/^http(s?):\/\//, function (_m, s) {
68
+ return "ws".concat(s, "://");
69
+ }) + '/socket';
70
+ this._token = token;
71
+ this._socket = new _Socket(wsUrl, _objectSpread({
72
+ params: {
73
+ token: token
74
+ }
75
+ }, socketOpts));
76
+ this._socket.connect();
77
+ /** @type {Map<string, Object>} topic → Phoenix Channel */
78
+ this._channels = new Map();
79
+ }
80
+
81
+ // ── Channel helpers ──────────────────────────────────────────────────────
82
+
83
+ /**
84
+ * Join the user channel for notifications, presence, and real-time events.
85
+ * Topic: `"user:<userId>"`
86
+ * @param {string|number} userId
87
+ * @param {Object} params - Extra join params merged with the auth token
88
+ * @returns {Object} Phoenix Channel
89
+ */
90
+ return _createClass(GameRealtime, [{
91
+ key: "joinUserChannel",
92
+ value: function joinUserChannel(userId) {
93
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
94
+ return this._join("user:".concat(userId), params);
95
+ }
96
+
97
+ /**
98
+ * Join a lobby channel for in-lobby events (member joins/leaves, updates).
99
+ * Topic: `"lobby:<lobbyId>"`
100
+ * @param {string|number} lobbyId
101
+ * @param {Object} params
102
+ * @returns {Object} Phoenix Channel
103
+ */
104
+ }, {
105
+ key: "joinLobbyChannel",
106
+ value: function joinLobbyChannel(lobbyId) {
107
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
108
+ return this._join("lobby:".concat(lobbyId), params);
109
+ }
110
+
111
+ /**
112
+ * Join the global lobbies feed (lobby list changes).
113
+ * Topic: `"lobbies"`
114
+ * @param {Object} params
115
+ * @returns {Object} Phoenix Channel
116
+ */
117
+ }, {
118
+ key: "joinLobbiesChannel",
119
+ value: function joinLobbiesChannel() {
120
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
121
+ return this._join('lobbies', params);
122
+ }
123
+
124
+ /**
125
+ * Join a group channel for group events.
126
+ * Topic: `"group:<groupId>"`
127
+ * @param {string|number} groupId
128
+ * @param {Object} params
129
+ * @returns {Object} Phoenix Channel
130
+ */
131
+ }, {
132
+ key: "joinGroupChannel",
133
+ value: function joinGroupChannel(groupId) {
134
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
135
+ return this._join("group:".concat(groupId), params);
136
+ }
137
+
138
+ /**
139
+ * Join the global groups feed.
140
+ * Topic: `"groups"`
141
+ * @param {Object} params
142
+ * @returns {Object} Phoenix Channel
143
+ */
144
+ }, {
145
+ key: "joinGroupsChannel",
146
+ value: function joinGroupsChannel() {
147
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
148
+ return this._join('groups', params);
149
+ }
150
+
151
+ /**
152
+ * Join a party channel for party events.
153
+ * Topic: `"party:<partyId>"`
154
+ * @param {string|number} partyId
155
+ * @param {Object} params
156
+ * @returns {Object} Phoenix Channel
157
+ */
158
+ }, {
159
+ key: "joinPartyChannel",
160
+ value: function joinPartyChannel(partyId) {
161
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
162
+ return this._join("party:".concat(partyId), params);
163
+ }
164
+
165
+ /**
166
+ * Join an arbitrary channel topic.
167
+ * @param {string} topic - Full Phoenix channel topic string
168
+ * @param {Object} params - Join params merged with the auth token
169
+ * @returns {Object} Phoenix Channel
170
+ */
171
+ }, {
172
+ key: "joinChannel",
173
+ value: function joinChannel(topic) {
174
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
175
+ return this._join(topic, params);
176
+ }
177
+
178
+ /**
179
+ * Leave and remove a channel by topic.
180
+ * @param {string} topic
181
+ */
182
+ }, {
183
+ key: "leaveChannel",
184
+ value: function leaveChannel(topic) {
185
+ var ch = this._channels.get(topic);
186
+ if (ch) {
187
+ ch.leave();
188
+ this._channels["delete"](topic);
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Retrieve an already-joined channel by topic.
194
+ * @param {string} topic
195
+ * @returns {Object|undefined} Phoenix Channel or undefined if not joined
196
+ */
197
+ }, {
198
+ key: "channel",
199
+ value: function channel(topic) {
200
+ return this._channels.get(topic);
201
+ }
202
+
203
+ /**
204
+ * Access the underlying Phoenix.Socket instance.
205
+ * @returns {Object}
206
+ */
207
+ }, {
208
+ key: "socket",
209
+ get: function get() {
210
+ return this._socket;
211
+ }
212
+
213
+ /**
214
+ * Disconnect the socket and leave all channels.
215
+ */
216
+ }, {
217
+ key: "disconnect",
218
+ value: function disconnect() {
219
+ this._channels.forEach(function (ch) {
220
+ try {
221
+ ch.leave();
222
+ } catch (_) {}
223
+ });
224
+ this._channels.clear();
225
+ this._socket.disconnect();
226
+ }
227
+
228
+ // ── Private ────────────────────────────────────────────────────────────────
229
+ }, {
230
+ key: "_join",
231
+ value: function _join(topic) {
232
+ var extraParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
233
+ if (this._channels.has(topic)) {
234
+ return this._channels.get(topic);
235
+ }
236
+ var ch = this._socket.channel(topic, _objectSpread({
237
+ token: this._token
238
+ }, extraParams));
239
+ ch.join().receive('error', function (err) {
240
+ return console.error("GameRealtime: failed to join channel \"".concat(topic, "\""), err);
241
+ });
242
+ this._channels.set(topic, ch);
243
+ return ch;
244
+ }
245
+ }]);
246
+ }();
247
+ var _default = exports["default"] = GameRealtime;