Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@heroiclabs/nakama-js

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@heroiclabs/nakama-js - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [0.4.0] - 2018-02-02
### Changed
- Re-structure project for wider browser compatibility.
- Use a polyfill for window.fetch support.
### Fixed
- Fix bug in MatchDataSendRequest message.
## [0.3.0] - 2017-11-27

@@ -8,0 +16,0 @@ ### Added

3164

dist/nakama-js.cjs.js

@@ -5,2 +5,475 @@ 'use strict';

(function(self) {
'use strict';
if (self.fetch) {
return
}
var support = {
searchParams: 'URLSearchParams' in self,
iterable: 'Symbol' in self && 'iterator' in Symbol,
blob: 'FileReader' in self && 'Blob' in self && (function() {
try {
new Blob();
return true
} catch(e) {
return false
}
})(),
formData: 'FormData' in self,
arrayBuffer: 'ArrayBuffer' in self
};
if (support.arrayBuffer) {
var viewClasses = [
'[object Int8Array]',
'[object Uint8Array]',
'[object Uint8ClampedArray]',
'[object Int16Array]',
'[object Uint16Array]',
'[object Int32Array]',
'[object Uint32Array]',
'[object Float32Array]',
'[object Float64Array]'
];
var isDataView = function(obj) {
return obj && DataView.prototype.isPrototypeOf(obj)
};
var isArrayBufferView = ArrayBuffer.isView || function(obj) {
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
};
}
function normalizeName(name) {
if (typeof name !== 'string') {
name = String(name);
}
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
throw new TypeError('Invalid character in header field name')
}
return name.toLowerCase()
}
function normalizeValue(value) {
if (typeof value !== 'string') {
value = String(value);
}
return value
}
// Build a destructive iterator for the value list
function iteratorFor(items) {
var iterator = {
next: function() {
var value = items.shift();
return {done: value === undefined, value: value}
}
};
if (support.iterable) {
iterator[Symbol.iterator] = function() {
return iterator
};
}
return iterator
}
function Headers(headers) {
this.map = {};
if (headers instanceof Headers) {
headers.forEach(function(value, name) {
this.append(name, value);
}, this);
} else if (Array.isArray(headers)) {
headers.forEach(function(header) {
this.append(header[0], header[1]);
}, this);
} else if (headers) {
Object.getOwnPropertyNames(headers).forEach(function(name) {
this.append(name, headers[name]);
}, this);
}
}
Headers.prototype.append = function(name, value) {
name = normalizeName(name);
value = normalizeValue(value);
var oldValue = this.map[name];
this.map[name] = oldValue ? oldValue+','+value : value;
};
Headers.prototype['delete'] = function(name) {
delete this.map[normalizeName(name)];
};
Headers.prototype.get = function(name) {
name = normalizeName(name);
return this.has(name) ? this.map[name] : null
};
Headers.prototype.has = function(name) {
return this.map.hasOwnProperty(normalizeName(name))
};
Headers.prototype.set = function(name, value) {
this.map[normalizeName(name)] = normalizeValue(value);
};
Headers.prototype.forEach = function(callback, thisArg) {
for (var name in this.map) {
if (this.map.hasOwnProperty(name)) {
callback.call(thisArg, this.map[name], name, this);
}
}
};
Headers.prototype.keys = function() {
var items = [];
this.forEach(function(value, name) { items.push(name); });
return iteratorFor(items)
};
Headers.prototype.values = function() {
var items = [];
this.forEach(function(value) { items.push(value); });
return iteratorFor(items)
};
Headers.prototype.entries = function() {
var items = [];
this.forEach(function(value, name) { items.push([name, value]); });
return iteratorFor(items)
};
if (support.iterable) {
Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
}
function consumed(body) {
if (body.bodyUsed) {
return Promise.reject(new TypeError('Already read'))
}
body.bodyUsed = true;
}
function fileReaderReady(reader) {
return new Promise(function(resolve, reject) {
reader.onload = function() {
resolve(reader.result);
};
reader.onerror = function() {
reject(reader.error);
};
})
}
function readBlobAsArrayBuffer(blob) {
var reader = new FileReader();
var promise = fileReaderReady(reader);
reader.readAsArrayBuffer(blob);
return promise
}
function readBlobAsText(blob) {
var reader = new FileReader();
var promise = fileReaderReady(reader);
reader.readAsText(blob);
return promise
}
function readArrayBufferAsText(buf) {
var view = new Uint8Array(buf);
var chars = new Array(view.length);
for (var i = 0; i < view.length; i++) {
chars[i] = String.fromCharCode(view[i]);
}
return chars.join('')
}
function bufferClone(buf) {
if (buf.slice) {
return buf.slice(0)
} else {
var view = new Uint8Array(buf.byteLength);
view.set(new Uint8Array(buf));
return view.buffer
}
}
function Body() {
this.bodyUsed = false;
this._initBody = function(body) {
this._bodyInit = body;
if (!body) {
this._bodyText = '';
} else if (typeof body === 'string') {
this._bodyText = body;
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body;
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body;
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this._bodyText = body.toString();
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
this._bodyArrayBuffer = bufferClone(body.buffer);
// IE 10-11 can't handle a DataView body.
this._bodyInit = new Blob([this._bodyArrayBuffer]);
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
this._bodyArrayBuffer = bufferClone(body);
} else {
throw new Error('unsupported BodyInit type')
}
if (!this.headers.get('content-type')) {
if (typeof body === 'string') {
this.headers.set('content-type', 'text/plain;charset=UTF-8');
} else if (this._bodyBlob && this._bodyBlob.type) {
this.headers.set('content-type', this._bodyBlob.type);
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
}
}
};
if (support.blob) {
this.blob = function() {
var rejected = consumed(this);
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return Promise.resolve(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
return Promise.resolve(new Blob([this._bodyArrayBuffer]))
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as blob')
} else {
return Promise.resolve(new Blob([this._bodyText]))
}
};
this.arrayBuffer = function() {
if (this._bodyArrayBuffer) {
return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
} else {
return this.blob().then(readBlobAsArrayBuffer)
}
};
}
this.text = function() {
var rejected = consumed(this);
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return readBlobAsText(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as text')
} else {
return Promise.resolve(this._bodyText)
}
};
if (support.formData) {
this.formData = function() {
return this.text().then(decode)
};
}
this.json = function() {
return this.text().then(JSON.parse)
};
return this
}
// HTTP methods whose capitalization should be normalized
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
function normalizeMethod(method) {
var upcased = method.toUpperCase();
return (methods.indexOf(upcased) > -1) ? upcased : method
}
function Request(input, options) {
options = options || {};
var body = options.body;
if (input instanceof Request) {
if (input.bodyUsed) {
throw new TypeError('Already read')
}
this.url = input.url;
this.credentials = input.credentials;
if (!options.headers) {
this.headers = new Headers(input.headers);
}
this.method = input.method;
this.mode = input.mode;
if (!body && input._bodyInit != null) {
body = input._bodyInit;
input.bodyUsed = true;
}
} else {
this.url = String(input);
}
this.credentials = options.credentials || this.credentials || 'omit';
if (options.headers || !this.headers) {
this.headers = new Headers(options.headers);
}
this.method = normalizeMethod(options.method || this.method || 'GET');
this.mode = options.mode || this.mode || null;
this.referrer = null;
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
throw new TypeError('Body not allowed for GET or HEAD requests')
}
this._initBody(body);
}
Request.prototype.clone = function() {
return new Request(this, { body: this._bodyInit })
};
function decode(body) {
var form = new FormData();
body.trim().split('&').forEach(function(bytes) {
if (bytes) {
var split = bytes.split('=');
var name = split.shift().replace(/\+/g, ' ');
var value = split.join('=').replace(/\+/g, ' ');
form.append(decodeURIComponent(name), decodeURIComponent(value));
}
});
return form
}
function parseHeaders(rawHeaders) {
var headers = new Headers();
rawHeaders.split(/\r?\n/).forEach(function(line) {
var parts = line.split(':');
var key = parts.shift().trim();
if (key) {
var value = parts.join(':').trim();
headers.append(key, value);
}
});
return headers
}
Body.call(Request.prototype);
function Response(bodyInit, options) {
if (!options) {
options = {};
}
this.type = 'default';
this.status = 'status' in options ? options.status : 200;
this.ok = this.status >= 200 && this.status < 300;
this.statusText = 'statusText' in options ? options.statusText : 'OK';
this.headers = new Headers(options.headers);
this.url = options.url || '';
this._initBody(bodyInit);
}
Body.call(Response.prototype);
Response.prototype.clone = function() {
return new Response(this._bodyInit, {
status: this.status,
statusText: this.statusText,
headers: new Headers(this.headers),
url: this.url
})
};
Response.error = function() {
var response = new Response(null, {status: 0, statusText: ''});
response.type = 'error';
return response
};
var redirectStatuses = [301, 302, 303, 307, 308];
Response.redirect = function(url, status) {
if (redirectStatuses.indexOf(status) === -1) {
throw new RangeError('Invalid status code')
}
return new Response(null, {status: status, headers: {location: url}})
};
self.Headers = Headers;
self.Request = Request;
self.Response = Response;
self.fetch = function(input, init) {
return new Promise(function(resolve, reject) {
var request = new Request(input, init);
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var options = {
status: xhr.status,
statusText: xhr.statusText,
headers: parseHeaders(xhr.getAllResponseHeaders() || '')
};
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
var body = 'response' in xhr ? xhr.response : xhr.responseText;
resolve(new Response(body, options));
};
xhr.onerror = function() {
reject(new TypeError('Network request failed'));
};
xhr.ontimeout = function() {
reject(new TypeError('Network request failed'));
};
xhr.open(request.method, request.url, true);
if (request.credentials === 'include') {
xhr.withCredentials = true;
}
if ('responseType' in xhr && support.blob) {
xhr.responseType = 'blob';
}
request.headers.forEach(function(value, name) {
xhr.setRequestHeader(name, value);
});
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
})
};
self.fetch.polyfill = true;
})(typeof self !== 'undefined' ? self : window);
/**
* Build a string which looks like a UUIDv4 type.
*/
const uuidv4 = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, character => {
const randomNumber = Math.random() * 16 | 0,
result = character === 'x' ? randomNumber : randomNumber & 0x3 | 0x8;
return result.toString(16);
});
};
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

@@ -183,73 +656,37 @@

/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class Session {
constructor(createdAt, expiresAt, handle, id, token) {
this.token_ = token;
const VERSION = '0.1.0';
const DEFAULT_SERVER_KEY = 'defaultkey';
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = '7350';
/**
* Build a string which looks like a UUIDv4 type.
*/
const uuidv4 = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, character => {
const randomNumber = Math.random() * 16 | 0,
result = character === 'x' ? randomNumber : randomNumber & 0x3 | 0x8;
return result.toString(16);
});
};
class AuthenticateRequest {
constructor(message) {
this.message_ = message;
this.createdAt = createdAt;
this.expiresAt = expiresAt;
this.handle = handle;
this.id = id;
}
static custom(id) {
return new AuthenticateRequest({
custom: id
});
/**
* @param {number} currentime The current system time in milliseconds.
* @returns {bool} True if the session has expired.
*/
isexpired(currenttime) {
return this.expiresAt - currenttime < 0;
}
static device(id) {
return new AuthenticateRequest({
device: id
});
}
static restore(jwt) {
const parts = jwt.split('.');
if (parts.length != 3) {
throw 'jwt is not valid.';
}
const decoded = JSON.parse(base64.decode(parts[1]));
const expiresAt = Math.floor(parseInt(decoded['exp']) * 1000);
static email(email, password) {
return new AuthenticateRequest({
email: {
email: email,
password: password
}
});
return new Session(Date.now(), expiresAt, decoded['han'], decoded['uid'], jwt);
}
}
static facebook(oauthToken) {
return new AuthenticateRequest({
facebook: oauthToken
});
}
const VERSION = '0.1.0';
const DEFAULT_SERVER_KEY = 'defaultkey';
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = '7350';
static google(oauthToken) {
return new AuthenticateRequest({
google: oauthToken
});
}
}
class Client {

@@ -359,74 +796,4 @@ constructor(serverkey = DEFAULT_SERVER_KEY, host = DEFAULT_HOST, port = DEFAULT_PORT, lang = 'en', ssl = false, verbose = false) {

p.reject(message.error);
} else if (message.self) {
p.resolve(message.self);
} else if (message.users) {
message.users.users.forEach(function (user) {
user.metadata = JSON.parse(user.metadata);
});
p.resolve(message.users.users);
} else if (message.storageData) {
p.resolve(message.storageData);
} else if (message.storageKeys) {
p.resolve(message.storageKeys);
} else if (message.friends) {
message.friends.friends.forEach(function (friend) {
friend.user.metadata = JSON.parse(friend.user.metadata);
});
p.resolve(message.friends);
} else if (message.topics) {
p.resolve(message.topics);
} else if (message.topicMessageAck) {
p.resolve(message.topicMessageAck);
} else if (message.topicMessages) {
message.topicMessages.messages.forEach(function (message) {
message.data = JSON.parse(message.data);
});
p.resolve(message.topicMessages);
} else if (message.groups) {
message.groups.groups.forEach(function (group) {
group.metadata = JSON.parse(group.metadata);
});
p.resolve(message.groups);
} else if (message.groupsSelf) {
message.groupsSelf.groupsSelf.forEach(function (groupSelf) {
groupSelf.group.metadata = JSON.parse(groupSelf.group.metadata);
});
p.resolve(message.groupsSelf);
} else if (message.groupUsers) {
message.groupUsers.users.forEach(function (groupUser) {
groupUser.user.metadata = JSON.parse(groupUser.user.metadata);
});
p.resolve(message.groupUsers);
} else if (message.rpc) {
message.rpc.payload = message.rpc.payload ? JSON.parse(message.rpc.payload) : null;
p.resolve({ id: message.rpc.id, payload: message.rpc.payload });
} else if (message.notifications) {
message.notifications.notifications.forEach(function (notification) {
notification.content = JSON.parse(notification.content);
});
p.resolve(message.notifications);
} else if (message.matchmakeTicket) {
p.resolve(message.matchmakeTicket);
} else if (message.match) {
p.resolve(message.match);
} else if (message.matches) {
p.resolve(message.matches);
} else if (message.leaderboards) {
message.leaderboards.leaderboards.forEach(function (leaderboard) {
leaderboard.metadata = JSON.parse(leaderboard.metadata);
});
p.resolve(message.leaderboards);
} else if (message.leaderboardRecords) {
message.leaderboardRecords.records.forEach(function (record) {
record.metadata = JSON.parse(record.metadata);
});
p.resolve(message.leaderboardRecords);
} else {
// if the object has properties, other than the collationId, log a warning
if (window.console && Object.keys(message).length > 1) {
console.error("Unrecognized message received: %o", message);
p.resolve(message);
} else {
p.resolve();
}
p.resolve(message);
}

@@ -453,6 +820,8 @@ }

message.collationId = collationId;
return this.send_(message, collationId, request.constructor.name);
return this.send_(message, collationId).then(message => {
if (request.processResponse_) return request.processResponse_(message);
});
}
send_(message, collationId, requestName) {
send_(message, collationId) {
if (this.socket_ == null) {

@@ -473,3 +842,3 @@ return new Promise((resolve, reject) => {

if (this.verbose && window.console) {
console.log("%s: %o", requestName, message);
console.log("%o", message);
}

@@ -523,494 +892,655 @@

class Session {
constructor(createdAt, expiresAt, handle, id, token) {
this.token_ = token;
function AuthenticateRequest(message) {
return {
message_: message
};
}
this.createdAt = createdAt;
this.expiresAt = expiresAt;
this.handle = handle;
this.id = id;
}
Object.assign(AuthenticateRequest, {
custom,
device,
email,
facebook,
google
});
/**
* @param {number} currentime The current system time in milliseconds.
* @returns {bool} True if the session has expired.
*/
isexpired(currenttime) {
return this.expiresAt - currenttime < 0;
}
function custom(id) {
return new AuthenticateRequest({
custom: id
});
}
static restore(jwt) {
const parts = jwt.split('.');
if (parts.length != 3) {
throw 'jwt is not valid.';
function device(id) {
return new AuthenticateRequest({
device: id
});
}
function email(email, password) {
return new AuthenticateRequest({
email: {
email,
password
}
const decoded = JSON.parse(base64.decode(parts[1]));
const expiresAt = Math.floor(parseInt(decoded['exp']) * 1000);
});
}
return new Session(Date.now(), expiresAt, decoded['han'], decoded['uid'], jwt);
}
function facebook(oauthToken) {
return new AuthenticateRequest({
facebook: oauthToken
});
}
class LinkRequest {
constructor() {
// only set one of these fields
this.custom = null;
this.device = null;
this.facebook = null;
this.google = null;
this.email = {
email: "",
password: ""
function google(oauthToken) {
return new AuthenticateRequest({
google: oauthToken
});
}
function FriendsAddRequest({
userIds = [],
handles = []
} = {}) {
function build_() {
return {
friendsAdd: {
friends: [...userIds.map(userId => ({ userId })), ...handles.map(handle => ({ handle }))]
}
};
}
build_() {
if (this.custom) {
return { link: { custom: this.custom } };
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
if (this.device) {
return { link: { device: this.device } };
}
get handles() {
return handles;
},
set handles(val) {
handles = val;
},
if (this.facebook) {
return { link: { facebook: this.facebook } };
}
if (this.google) {
return { link: { google: this.google } };
}
if (this.email.email != "") {
return { link: { email: this.email } };
}
}
build_
};
}
class UnlinkRequest {
constructor() {
// only set one of these fields
this.custom = null;
this.device = null;
this.facebook = null;
this.google = null;
this.email = null;
function FriendsBlockRequest({
userIds = []
} = {}) {
function build_() {
return {
friendsBlock: {
userIds: userIds.map(userId => ({ userId }))
}
};
}
build_() {
if (this.custom) {
return { unlink: { custom: this.custom } };
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
if (this.device) {
return { unlink: { device: this.device } };
}
build_
};
}
if (this.facebook) {
return { unlink: { facebook: this.facebook } };
}
function FriendsResponse(message) {
const {
friends: {
friends = []
} = {}
} = message;
if (this.google) {
return { unlink: { google: this.google } };
}
friends.forEach(friend => {
friend.user.metadata = JSON.parse(friend.user.metadata);
});
if (this.email) {
return { unlink: { email: this.email } };
}
}
return message.friends;
}
class SelfFetchRequest {
constructor() {}
build_() {
function FriendsListRequest() {
function build_() {
return {
selfFetch: {}
friendsList: {}
};
}
return {
build_,
processResponse_: FriendsResponse
};
}
class SelfUpdateRequest {
constructor() {
this.handle = null;
this.fullname = null;
this.timezone = null;
this.location = null;
this.lang = null;
this.metadata = null;
this.avatarUrl = null;
}
build_() {
function FriendsRemoveRequest({
userIds = []
} = {}) {
function build_() {
return {
selfUpdate: {
handle: this.handle,
fullname: this.fullname,
timezone: this.timezone,
location: this.location,
lang: this.lang,
avatarUrl: this.avatarUrl,
metadata: this.metadata ? JSON.stringify(this.metadata) : "{}"
friendsRemove: {
userIds: userIds.map(userId => ({ userId }))
}
};
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
build_
};
}
class UsersFetchRequest {
constructor() {
// base64 user IDs
this.userIds = [];
this.handles = [];
}
function GroupsResponse(message) {
const {
groups: {
groups = []
} = {}
} = message;
build_() {
var msg = { usersFetch: { users: [] } };
this.userIds.forEach(function (id) {
msg.usersFetch.users.push({ userId: id });
});
this.handles.forEach(function (handle) {
msg.usersFetch.users.push({ handle: handle });
});
return msg;
}
groups.forEach(group => {
group.metadata = JSON.parse(group.metadata);
});
return message.groups;
}
class StorageListRequest {
constructor() {
// base64 user ID
this.userId = null;
this.bucket = null;
this.collection = null;
this.limit = null;
this.cursor = null;
function GroupsCreateRequest({
groups = []
} = {}) {
function create(name, description, avatarUrl, lang, metadata = {}, privateGroup) {
groups.push({
name,
description,
avatarUrl,
lang,
private: privateGroup,
metadata: JSON.stringify(metadata)
});
}
build_() {
function build_() {
return {
storageList: {
userId: this.userId,
bucket: this.bucket,
collection: this.collection,
limit: this.limit,
cursor: this.cursor
groupsCreate: {
groups
}
};
}
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
create,
build_,
processResponse_: GroupsResponse
};
}
class StorageFetchRequest {
constructor() {
this.keys = [];
function GroupsFetchRequest({
groupIds = [],
names = []
} = {}) {
function build_() {
return {
groupsFetch: {
groups: [...groupIds.map(groupId => ({ groupId })), ...names.map(name => ({ name }))]
}
};
}
fetch(bucket, collection, record, userId) {
this.keys.push({
bucket: bucket,
collection: collection,
record: record,
userId: userId
});
return this;
}
return {
get groupIds() {
return groupIds;
},
set groupIds(val) {
groupIds = val;
},
build_() {
return { storageFetch: { keys: this.keys } };
}
get names() {
return names;
},
set names(val) {
names = val;
},
build_,
processResponse_: GroupsResponse
};
}
class StorageWriteRequest {
constructor() {
this.data = [];
function GroupsJoinRequest({
groups = []
} = {}) {
function build_() {
return {
groupsJoin: {
groupIds: groups
}
};
}
write(bucket, collection, record, value, permissionRead = 1, permissionWrite = 1, version) {
this.data.push({
bucket: bucket,
collection: collection,
record: record,
value: value ? JSON.stringify(value) : "{}",
version: version ? version : null,
permissionRead: permissionRead,
permissionWrite: permissionWrite
});
return this;
}
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
build_() {
return { storageWrite: { data: this.data } };
}
build_
};
}
class StorageRemoveRequest {
constructor() {
this.keys = [];
function GroupsLeaveRequest({
groups = []
} = {}) {
function build_() {
return {
groupsLeave: {
groupIds: groups
}
};
}
remove(bucket, collection, record, userId) {
this.keys.push({
bucket: bucket,
collection: collection,
record: record,
userId: userId
});
return this;
}
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
build_() {
return { storageRemove: { keys: this.keys } };
}
build_
};
}
class StorageUpdateRequest {
constructor() {
this.updates = [];
}
function GroupsListRequest({
pageLimit,
orderByAsc,
cursor,
build_() {
return { storageUpdate: { updates: this.updates } };
}
// only set one of the followings
lang,
createdAt,
count
} = {}) {
function build_() {
const msg = {
groupsList: {
pageLimit,
orderByAsc,
cursor
}
};
/**
storageOps variable must be an array
*/
update(bucket, collection, record, storageOps = [], permissionRead = 1, permissionWrite = 1, version) {
this.updates.push({
key: {
bucket: bucket,
collection: collection,
record: record,
version: version ? version : null
},
permissionRead: permissionRead,
permissionWrite: permissionWrite,
ops: storageOps
});
return this;
}
if (lang) {
msg.groupsList.lang = lang;
} else if (createdAt) {
msg.groupsList.createdAt = createdAt;
} else if (count) {
msg.groupsList.count = count;
}
static add(path, value) {
return {
op: 0,
path: path,
value: JSON.stringify(value)
};
return msg;
}
static append(path, value) {
return {
op: 1,
path: path,
value: JSON.stringify(value)
};
}
return {
get pageLimit() {
return pageLimit;
},
set pageLimit(val) {
pageLimit = val;
},
static copy(path, from) {
return {
op: 2,
path: path,
from: from
};
}
get orderByAsc() {
return orderByAsc;
},
set orderByAsc(val) {
orderByAsc = val;
},
static incr(path, value) {
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
get lang() {
return lang;
},
set lang(val) {
lang = val;
},
get createdAt() {
return createdAt;
},
set createdAt(val) {
createdAt = val;
},
get count() {
return count;
},
set count(val) {
count = val;
},
build_,
processResponse_: GroupsResponse
};
}
function GroupsRemoveRequest({
groups = []
} = {}) {
function build_() {
return {
op: 3,
path: path,
value: JSON.stringify(value)
groupsRemove: {
groupIds: groups
}
};
}
static init(path, value) {
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
build_
};
}
function GroupsSelfResponse(message) {
const {
groupsSelf: {
groupsSelf = []
} = {}
} = message;
groupsSelf.forEach(groupSelf => {
groupSelf.group.metadata = JSON.parse(groupSelf.group.metadata);
});
return message.groupsSelf;
}
function GroupsSelfListRequest() {
function build_() {
return {
op: 4,
path: path,
value: JSON.stringify(value)
groupsSelfList: {}
};
}
static merge(path, from) {
return {
op: 5,
path: path,
from: from
};
return {
build_,
processResponse_: GroupsSelfResponse
};
}
function GroupsUpdateRequest({
groups = []
} = {}) {
function update(groupId, name, description, avatarUrl, lang, metadata = {}, privateGroup) {
groups.push({
groupId,
name,
description,
avatarUrl,
lang,
private: privateGroup,
metadata: JSON.string(metadata)
});
}
static move(path, from) {
function build_() {
return {
op: 6,
path: path,
from: from
groupsUpdate: {
groups
}
};
}
static remove(path) {
return {
op: 8,
path: path
};
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
update,
build_
};
}
function GroupUsersAddRequest({
adds = []
} = {}) {
function add(groupId, userId) {
adds.push({
groupId,
userID
});
}
static replace(path, value) {
function build_() {
return {
op: 9,
path: path,
value: JSON.stringify(value)
groupUsersAdd: {
groupUsers: adds
}
};
}
static test(path, value) {
return {
op: 10,
path: path,
value: JSON.stringify(value)
};
return {
get adds() {
return adds;
},
set add(val) {
adds = val;
},
add,
build_
};
}
function GroupUsersKickRequest({
kicks = []
} = {}) {
function kick(groupId, userId) {
kicks.push({ groupId, userID });
}
static compare(path, value, assertValue) {
function build_() {
return {
op: 11,
path: path,
value: JSON.stringify(value),
assert: assertValue
groupUsersKick: {
groupUsers: kicks
}
};
}
}
class FriendsAddRequest {
constructor() {
// base64 user IDs
this.userIds = [];
this.handles = [];
}
return {
get kicks() {
return kicks;
},
set kicks(val) {
kicks = val;
},
build_() {
var msg = { friendsAdd: { friends: [] } };
this.userIds.forEach(function (id) {
msg.friendsAdd.friends.push({ userId: id });
});
this.handles.forEach(function (handle) {
msg.friendsAdd.friends.push({ handle: handle });
});
return msg;
}
kick,
build_
};
}
class FriendsRemoveRequest {
constructor() {
// base64 user IDs
this.userIds = [];
}
function GroupUsersResponse(message) {
const {
groupUsers: {
users = []
}
} = message;
build_() {
var msg = { friendsRemove: { userIds: [] } };
this.userIds.forEach(function (id) {
msg.friendsRemove.userIds.push({ userId: id });
});
return msg;
}
users.forEach(groupUser => {
groupUser.user.metadata = JSON.parse(groupUser.user.metadata);
});
return message.groupUsers;
}
class FriendsBlockRequest {
constructor() {
// base64 user IDs
this.userIds = [];
function GroupUsersListRequest(groupId) {
function build_() {
return {
groupUsersList: {
groupId
}
};
}
build_() {
var msg = { friendsBlock: { userIds: [] } };
this.userIds.forEach(function (id) {
msg.friendsBlock.userIds.push({ userId: id });
});
return msg;
}
return {
get groupId() {
return groupId;
},
set groupId(val) {
groupId = val;
},
build_,
processResponse_: GroupUsersResponse
};
}
class FriendsListRequest {
constructor() {}
function GroupUsersPromoteRequest({
promotes = []
} = {}) {
function promote(groupId, userID) {
promotes.push({ groupId, userId });
}
build_() {
function build_() {
return {
friendsList: {}
groupUsersPromote: {
groupUsers: promote
}
};
}
}
class TopicsJoinRequest {
constructor() {
// NOTE: The server only processes the first item of the list, and will ignore and logs a warning message for other items.
this.topics = [];
}
return {
get promotes() {
return promotes;
},
set promotes(val) {
promotes = val;
},
dm(userId) {
this.topics.push({ userId: userId });
return this;
}
promote,
build_
};
}
group(groupId) {
this.topics.push({ groupId: groupId });
return this;
}
function LeaderboardRecordsResponse(message) {
const {
leaderboardRecords: {
records = []
}
} = message;
room(room) {
this.topics.push({ room: room });
return this;
}
records.forEach(record => {
record.metadata = JSON.parse(record.metadata);
});
build_() {
return { topicsJoin: { joins: this.topics } };
}
return message.leaderboardRecords;
}
class TopicsLeaveRequest {
constructor() {
// NOTE: The server only processes the first item of the list, and will ignore and logs a warning message for other items.
this.topics = []; // this is a list of topicIds.
function LeaderboardRecordsFetchRequest({
leaderboardIds = [],
limit,
cursor
} = {}) {
function build_() {
return {
leaderboardRecordsFetch: {
leaderboardIds,
limit,
cursor
}
};
}
build_() {
return { topicsLeave: { topics: this.topics } };
}
}
return {
get leaderboardIds() {
return leaderboardIds;
},
set leaderboardIds(val) {
leaderboardIds = val;
},
class TopicMessageSendRequest {
constructor() {
// this is the topicId.
this.topic = null;
this.data = null;
}
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
build_() {
return { topicMessageSend: {
topic: this.topic,
data: JSON.stringify(this.data)
} };
}
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
build_,
processResponse_: LeaderboardRecordsResponse
};
}
class TopicMessagesListRequest {
constructor() {
this.cursor = null;
this.forward = null; // boolean
this.limit = null; // number <= 100
function LeaderboardRecordsListRequest({
leaderboardId,
limit,
cursor,
// set only one of the followings
this.userId = null;
this.room = null;
this.groupId = null;
}
// only set one the following
lang,
location,
timezone,
ownerId,
ownerIds = []
} = {}) {
function build_() {
const msg = {
leaderboardRecordsList: {
leaderboardId,
limit,
cursor
}
};
build_() {
var msg = { topicMessagesList: {
cursor: this.cursor,
forward: this.forward,
limit: this.limit
} };
if (this.userId) {
msg.topicMessagesList.userId = this.userId;
} else if (this.room) {
msg.topicMessagesList.room = this.room;
} else if (this.groupId) {
msg.topicMessagesList.groupId = this.groupId;
if (lang) {
msg.leaderboardRecordsList.lang = lang;
} else if (location) {
msg.leaderboardRecordsList.location = location;
} else if (timezone) {
msg.leaderboardRecordsList.timezone = timezone;
} else if (ownerId) {
msg.leaderboardRecordsList.ownerId = ownerId;
} else if (ownerIds.length > 0) {
msg.leaderboardRecordsList.ownerIds = { ownerIds: ownerIds };
}

@@ -1020,317 +1550,486 @@

}
return {
get leaderboardId() {
return leaderboardId;
},
set leaderboardId(val) {
leaderboardId = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
get lang() {
return lang;
},
set lang(val) {
lang = val;
},
get location() {
return location;
},
set location(val) {
location = val;
},
get timezone() {
return timezone;
},
set timezone(val) {
timezone = val;
},
get ownerId() {
return ownerId;
},
set ownerId(val) {
ownerId = val;
},
get ownerIds() {
return ownerIds;
},
set ownerIds(val) {
ownerIds = val;
},
build_,
processResponse_: LeaderboardRecordsResponse
};
}
class GroupsCreateRequest {
constructor() {
this.groups = [];
function LeaderboardRecordWriteRequest({
records = []
} = {}) {
function set(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
set: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
});
}
create(name, description, avatarUrl, lang, metadata, privateGroup) {
this.groups.push({
name: name,
description: description,
avatarUrl: avatarUrl,
lang: lang,
"private": privateGroup,
metadata: metadata ? JSON.stringify(metadata) : "{}"
function best(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
best: value,
metadata: JSON.stringify(metadata),
location,
timezone
});
}
build_() {
return { groupsCreate: { groups: this.groups } };
function decrement(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
decr: value,
metadata: JSON.stringify(metadata),
location,
timezone
});
}
}
class GroupsUpdateRequest {
constructor() {
this.groups = [];
function increment(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
incr: value,
metadata: JSON.stringify(metadata),
location,
timezone
});
}
update(groupId, name, description, avatarUrl, lang, metadata, privateGroup) {
this.groups.push({
groupId: groupId,
name: name,
description: description,
avatarUrl: avatarUrl,
lang: lang,
"private": privateGroup,
metadata: metadata ? JSON.stringify(metadata) : "{}"
});
function build_() {
return {
leaderboardRecordsWrite: {
records
}
};
}
build_() {
return { groupsUpdate: { groups: this.groups } };
}
return {
get records() {
return records;
},
set records(val) {
records = val;
},
set,
best,
decrement,
increment,
build_,
processResponse_: LeaderboardRecordsResponse
};
}
class GroupsRemoveRequest {
constructor() {
// this is a list of groupIds.
this.groups = [];
}
function LeaderboardsResponse(message) {
const {
leaderboards: {
leaderboards = []
}
} = message;
build_() {
return { groupsRemove: { groupIds: this.groups } };
}
leaderboards.forEach(leaderboard => {
leaderboard.metadata = JSON.parse(leaderboard.metadata);
});
return message.leaderboards;
}
class GroupsFetchRequest {
constructor() {
// this is a list of groupIds.
this.groupIds = [];
this.names = [];
function LeaderboardsListRequest({
filterLeaderboardIds = [],
limit,
cursor
} = {}) {
function build_() {
return {
leaderboardsList: {
filterLeaderboardId: filterLeaderboardIds,
limit,
cursor
}
};
}
build_() {
var msg = { groupsFetch: { groups: [] } };
this.groupIds.forEach(function (id) {
msg.groupsFetch.groups.push({ groupId: id });
});
this.names.forEach(function (name) {
msg.groupsFetch.groups.push({ name: name });
});
return msg;
}
return {
get filterLeaderboardIds() {
return filterLeaderboardIds;
},
set filterLeaderboardIds(val) {
filterLeaderboardIds = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
build_,
processResponse_: LeaderboardsResponse
};
}
class GroupsListRequest {
constructor() {
this.pageLimit = null;
this.orderByAsc = null;
this.cursor = null;
// only set one of the followings
this.lang = null;
this.createdAt = null;
this.count = null;
function LinkRequest({
// only set one of these fields
custom,
device,
facebook,
google,
email = {
email: '',
password: ''
}
} = {}) {
function build_() {
if (custom) return { link: { custom } };
if (device) return { link: { device } };
if (facebook) return { link: { facebook } };
if (google) return { link: { google } };
if (email.email != '') return { link: { email } };
}
build_() {
var msg = { groupsList: {
pageLimit: this.pageLimit,
orderByAsc: this.orderByAsc,
cursor: this.cursor
} };
return {
get custom() {
return custom;
},
set custom(val) {
custom = val;
},
if (this.lang) {
msg.groupsList.lang = this.lang;
} else if (this.createdAt) {
msg.groupsList.createdAt = this.createdAt;
} else if (this.count) {
msg.groupsList.count = this.count;
}
get device() {
return device;
},
set device(val) {
device = val;
},
return msg;
}
}
get facebook() {
return facebook;
},
set facebook(val) {
facebook = val;
},
class GroupsSelfListRequest {
constructor() {}
get google() {
return google;
},
set google(val) {
google = val;
},
build_() {
return { groupsSelfList: {} };
}
get email() {
return email;
},
set email(val) {
email = val;
},
build_
};
}
class GroupUsersListRequest {
constructor(groupId) {
this.groupId = groupId;
}
build_() {
return { groupUsersList: { groupId: this.groupId } };
}
function MatchResponse(message) {
return message.match;
}
class GroupsJoinRequest {
constructor() {
// this is a list of groupIds.
this.groups = [];
function MatchCreateRequest() {
function build_() {
return {
matchCreate: {}
};
}
build_() {
return { groupsJoin: { groupIds: this.groups } };
}
return {
build_,
processResponse_: MatchResponse
};
}
class GroupsLeaveRequest {
constructor() {
// this is a list of groupIds.
this.groups = [];
}
build_() {
return { groupsLeave: { groupIds: this.groups } };
}
function MatchDataResponse(message) {
message.matchData.data = JSON.parse(base64.decode(message.matchData.data));
return message.matchData;
}
class GroupUsersAddRequest {
constructor() {
this.adds = [];
function MatchDataSendRequest({
matchId,
presences,
opCode,
data
} = {}) {
function build_() {
return {
matchDataSend: {
matchId,
presences,
opCode,
data: base64.encode(JSON.stringify(data))
}
};
}
add(groupId, userId) {
this.adds.push({ groupId: groupId, userId: userId });
}
return {
get matchId() {
return matchId;
},
set matchId(val) {
matchId = val;
},
build_() {
var msg = { groupUsersAdd: { groupUsers: [] } };
this.adds.forEach(function (add) {
msg.groupUsersAdd.groupUsers.push({
groupId: add.groupId,
userId: add.userId
});
});
return msg;
}
}
get presences() {
return presences;
},
set presences(val) {
presences = val;
},
class GroupUsersKickRequest {
constructor() {
this.kicks = [];
}
get opCode() {
return opCode;
},
set opCode(val) {
opCode = val;
},
kick(groupId, userId) {
this.kicks.push({ groupId: groupId, userId: userId });
}
get data() {
return data;
},
set data(val) {
data = val;
},
build_() {
var msg = { groupUsersKick: { groupUsers: [] } };
this.kicks.forEach(function (kick) {
msg.groupUsersKick.groupUsers.push({
groupId: kick.groupId,
userId: kick.userId
});
});
return msg;
}
build_,
processResponse_: MatchDataResponse
};
}
class GroupUsersPromoteRequest {
constructor() {
this.promotes = [];
}
function MatchesResponse(message) {
return message.matches;
}
promote(groupId, userId) {
this.promotes.push({ groupId: groupId, userId: userId });
function MatchesJoinRequest({
matchIds = [],
tokens = []
} = {}) {
function build_() {
return {
matchesJoin: {
matches: [...matchIds.map(matchId => ({ matchId })), ...tokens.map(token => ({ token }))]
}
};
}
build_() {
var msg = { groupUsersPromote: { groupUsers: [] } };
this.promotes.forEach(function (promote) {
msg.groupUsersPromote.groupUsers.push({
groupId: promote.groupId,
userId: promote.userId
});
});
return msg;
}
}
return {
get matchIds() {
return matchIds;
},
set matchIds(val) {
matchIds = val;
},
class NotificationsListRequest {
constructor() {
this.limit = null;
this.resumableCursor = null;
}
get tokens() {
return tokens;
},
set tokens(val) {
tokens = val;
},
build_() {
return { notificationsList: {
limit: this.limit ? this.limit : 10,
resumableCursor: this.resumableCursor
} };
}
build_,
processResponse_: MatchesResponse
};
}
class NotificationsRemoveRequest {
constructor() {
// this is a list of notificationIds.
this.notifications = [];
function MatchesLeaveRequest({
matchIds = []
} = {}) {
function build_() {
return {
matchesLeave: {
matchIds
}
};
}
build_() {
return { notificationsRemove: { notificationIds: this.notifications } };
}
return {
get matchIds() {
return matchIds;
},
set matchIds(val) {
matchIds = val;
},
build_
};
}
class RpcRequest {
constructor() {
this.id = null;
this.payload = null;
}
build_() {
return { rpc: {
id: this.id,
payload: this.payload ? JSON.stringify(this.payload) : null
} };
}
function MatchmakeTicketResponse(message) {
return message.matchmakeTicket;
}
class MatchmakeAddRequest {
constructor(requiredCount) {
this.requiredCount = requiredCount;
this.filters = [];
this.properties = [];
}
function MatchmakeAddRequest(requiredCount) {
let filters = [];
let properties = [];
addTermFilter(name, termSet, matchAllTerms) {
this.filters.push({
name: name,
const self = {
get requiredCount() {
return requiredCount;
},
set requiredCount(val) {
requiredCount = val;
},
get filters() {
return filters;
},
set filters(val) {
filters = val;
},
get properties() {
return properties;
},
set properties(val) {
properties = val;
},
addTermFilter,
addRangeFilter,
addCheckFilter,
addStringSetProperty,
addIntegerProperty,
addBooleanProperty,
build_,
processResponse_: MatchmakeTicketResponse
};
return self;
function addTermFilter(name, termSet, matchAllTerms) {
filters.push({
name,
term: {
terms: termSet,
matchAllTerms: matchAllTerms
matchAllTerms
}
});
return this;
return self;
}
addRangeFilter(name, lowerbound, upperbound) {
this.filters.push({
name: name,
function addRangeFilter(name, lowerbound, upperbound) {
filters.push({
name,
range: {
lowerBound: lowerbound,
upperBound: upperbound
lowerBound,
upperBound
}
});
return this;
return self;
}
addCheckFilter(name, value) {
this.filters.push({
name: name,
function addCheckFilter(name, value) {
filters.push({
name,
check: value
});
return this;
return self;
}
addStringSetProperty(key, termSet) {
this.properties.push({
key: key,
function addStringSetProperty(key, termSet) {
properties.push({
key,
stringSet: termSet
});
return this;
return self;
}
addIntegerProperty(key, integerValue) {
this.properties.push({
key: key,
function addIntegerProperty(key, integerValue) {
properties.push({
key,
intValue: integerValue
});
return this;
return self;
}
addBooleanProperty(key, boolValue) {
this.properties.push({
key: key,
boolValue: boolValue
function addBooleanProperty(key, boolValue) {
properties.push({
key,
boolValue
});
return this;
return self;
}
build_() {
function build_() {
return {
matchmakeAdd: {
requiredCount: this.requiredCount,
filters: this.filters,
properties: this.properties
requiredCount,
filters,
properties
}

@@ -1341,214 +2040,867 @@ };

class MatchmakeRemoveRequest {
constructor(ticket) {
this.ticket = ticket;
function MatchmakeRemoveRequest(ticket) {
function build_() {
return {
matchmakeRemove: {
ticket
}
};
}
build_() {
return { matchmakeRemove: { ticket: this.ticket } };
}
return {
get ticket() {
return ticket;
},
set ticket(val) {
ticket = val;
},
build_
};
}
class MatchCreateRequest {
constructor() {}
function NotificationsResponse(message) {
const {
notifications: {
notifications = []
}
} = message;
build_() {
notifications.forEach(function (notification) {
notification.content = JSON.parse(notification.content);
});
return message.notifications;
}
function NotificationsListRequest({
limit,
resumableCursor
} = {}) {
function build_() {
return {
matchCreate: {}
notificationsList: {
limit: limit ? limit : 10,
resumableCursor
}
};
}
return {
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get resumableCursor() {
return resumableCursor;
},
set resumableCursor(val) {
resumableCursor = val;
},
build_,
processResponse_: NotificationsResponse
};
}
class MatchesJoinRequest {
constructor() {
this.matchIds = [];
this.tokens = [];
function NotificationsRemoveRequest({
notifications = []
} = {}) {
function build_() {
return {
notificationsRemove: {
notificationIds: notifications
}
};
}
build_() {
var msg = {
matchesJoin: { matches: [] }
return {
get notifications() {
return notifications;
},
set notifications(val) {
notifications = val;
},
build_
};
}
function RpcResponse(message) {
let {
rpc: {
id,
payload
}
} = message;
payload = payload ? JSON.parse(payload) : null;
return {
id,
payload
};
}
function RpcRequest({
id,
payload
} = {}) {
function build_() {
return {
rpc: {
id,
payload: payload ? JSON.stringify(payload) : null
}
};
}
this.matchIds.forEach(function (id) {
msg.matchesJoin.matches.push({ matchId: id });
});
return {
get id() {
return id;
},
set id(val) {
id = val;
},
this.tokens.forEach(function (token) {
msg.matchesJoin.matches.push({ token: token });
});
get payload() {
return payload;
},
set payload(val) {
payload = val;
},
return msg;
}
build_,
processResponse_: RpcResponse
};
}
class MatchesLeaveRequest {
constructor() {
this.matchIds = [];
function SelfResponse(message) {
return message.self;
}
function SelfFetchRequest() {
function build_() {
return {
selfFetch: {}
};
}
build_() {
return {
build_,
processResponse_: SelfResponse
};
}
function SelfUpdateRequest({
handle,
fullname,
timezone,
location,
lang,
avatarUrl,
metadata = {}
} = {}) {
function build_() {
return {
matchesLeave: {
matchIds: this.matchIds
selfUpdate: {
handle,
fullname,
timezone,
location,
lang,
avatarUrl,
metadata: JSON.stringify(metadata)
}
};
}
return {
get handle() {
return handle;
},
set handle(val) {
handle = val;
},
get fullname() {
return fullname;
},
set fullname(val) {
fullname = val;
},
get timezone() {
return timezone;
},
set timezone(val) {
timezone = val;
},
get location() {
return location;
},
set location(val) {
location = val;
},
get lang() {
return lang;
},
set lang(val) {
lang = val;
},
get metadata() {
return metadata;
},
set metadata(val) {
metadata = val;
},
get avatarUrl() {
return avatarUrl;
},
set avatarUrl(val) {
avatarUrl = val;
},
build_
};
}
class MatchDataSendRequest {
constructor() {
this.matchId = null;
this.presence = null; //UserPresence
this.opCode = 0;
this.data = null;
function StorageDataResponse(message) {
return message.storageData;
}
function StorageFetchRequest({
keys = []
} = {}) {
const self = {
get keys() {
return keys;
},
set keys(val) {
keys = val;
},
fetch,
build_,
processResponse_: StorageDataResponse
};
return self;
function build_() {
return {
storageFetch: {
keys
}
};
}
build_() {
function fetch(bucket, collection, record, userId) {
keys.push({
bucket,
collection,
record,
userId
});
return self;
}
}
function StorageListRequest({
userId,
bucket,
collection,
limit,
cursor
} = {}) {
function build_() {
return {
matchDataSend: {
matchId: matchId,
presence: presence,
opCode: opCode,
data: base64.encode(JSON.stringify(data))
storageList: {
userId,
bucket,
collection,
limit,
cursor
}
};
}
return {
get userId() {
return userId;
},
set userId(val) {
userId = val;
},
get bucket() {
return bucket;
},
set bucket(val) {
bucket = val;
},
get collection() {
return collection;
},
set collection(val) {
collection = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get cursor() {
return cursor;
},
set cursor(val) {
limit = val;
},
build_,
processResponse_: StorageDataResponse
};
}
class LeaderboardsListRequest {
constructor() {
this.filterLeaderboardIds = [];
this.limit = null;
this.cursor = null;
function StorageRemoveRequest({
keys = []
} = {}) {
const self = {
get keys() {
return keys;
},
set keys(val) {
keys = val;
},
remove,
build_
};
return self;
function build_() {
return {
storageRemove: {
keys
}
};
}
build_() {
var msg = { leaderboardsList: {
filterLeaderboardId: [],
limit: this.limit,
cursor: this.cursor
} };
function remove(bucket, collection, record, userId) {
keys.push({
bucket,
collection,
record,
userId
});
this.filterLeaderboardIds.forEach(function (id) {
msg.leaderboardsList.filterLeaderboardId.push(id);
});
return msg;
return self;
}
}
class LeaderboardRecordsFetchRequest {
constructor() {
this.leaderboardIds = [];
this.limit = null;
this.cursor = null;
function StorageKeysResponse(message) {
return message.storageKeys;
}
function StorageUpdateRequest({
updates = []
} = {}) {
const self = {
get updates() {
return updates;
},
set updates(val) {
updates = val;
},
update,
build_,
processResponse_: StorageKeysResponse
};
return self;
function build_() {
return {
storageUpdate: {
updates
}
};
}
build_() {
var msg = { leaderboardRecordsFetch: {
leaderboardIds: [],
limit: this.limit,
cursor: this.cursor
} };
// storageOps variable must be an array
function update(bucket, collection, record, storageOps = [], permissionRead = 1, permissionWrite = 1, version) {
updates.push({
key: {
bucket,
collection,
record,
version
},
permissionRead,
permissionWrite,
ops: storageOps
});
}
}
this.leaderboardIds.forEach(function (id) {
msg.leaderboardRecordsFetch.leaderboardIds.push(id);
Object.assign(StorageUpdateRequest, {
add,
append,
copy,
incr,
init,
merge,
move,
remove,
replace,
test,
compare
});
function add(path, value) {
return {
op: 0,
path,
value: JSON.stringify(value)
};
}
function append(path, value) {
return {
op: 1,
path,
value: JSON.stringify(value)
};
}
function copy(path, from) {
return {
op: 2,
path,
from
};
}
function incr(path, value) {
return {
op: 3,
path,
value: JSON.stringify(value)
};
}
function init(path, value) {
return {
op: 4,
path,
value: JSON.stringify(value)
};
}
function merge(path, from) {
return {
op: 5,
path,
from
};
}
function move(path, from) {
return {
op: 6,
path,
from
};
}
function remove(path) {
return {
op: 8,
path
};
}
function replace(path, value) {
return {
op: 9,
path,
value: JSON.string(value)
};
}
function test(path, value) {
return {
op: 10,
path,
value: JSON.stringify(value)
};
}
function compare(path, value, assertValue) {
return {
op: 11,
path,
value,
assert
};
}
function StorageWriteRequest({
data = []
} = {}) {
const self = {
get data() {
return data;
},
set data(val) {
data = val;
},
write,
build_,
processResponse_: StorageKeysResponse
};
return self;
function write(bucket, collection, record, value, permissionRead = 1, permissionWrite = 1, version) {
data.push({
bucket,
collection,
record,
value: value ? JSON.stringify(value) : '{}',
version,
permissionRead,
permissionWrite
});
return msg;
return self;
}
function build_() {
return {
storageWrite: {
data
}
};
}
}
class LeaderboardRecordsListRequest {
constructor() {
this.leaderboardId = null;
this.limit = null;
this.cursor = null;
function TopicMessageAckResponse(message) {
return message.topicMessageAck;
}
// only set one of the followings
this.lang = null;
this.location = null;
this.timezone = null;
this.ownerId = null;
this.ownerIds = [];
function TopicMessageSendRequest({
topic,
data
} = {}) {
function build_() {
return {
topicMessageSend: {
topic,
data: JSON.stringify(data)
}
};
}
build_() {
var msg = { leaderboardRecordsList: {
leaderboardId: this.leaderboardId,
limit: this.limit,
cursor: this.cursor
} };
return {
get topic() {
return topic;
},
set topic(val) {
topic = val;
},
if (this.lang) {
msg.leaderboardRecordsList.lang = this.lang;
} else if (this.location) {
msg.leaderboardRecordsList.location = this.createdAt;
} else if (this.timezone) {
msg.leaderboardRecordsList.count = this.count;
} else if (this.ownerId) {
msg.leaderboardRecordsList.ownerId = this.ownerId;
} else if (this.ownerIds.length > 0) {
msg.leaderboardRecordsList.ownerIds = { ownerIds: this.ownerIds };
get data() {
return data;
},
set data(val) {
data = val;
},
build_,
processResponse_: TopicMessageAckResponse
};
}
function TopicMessagesResponse(message) {
const {
topicMessages: {
messages = []
}
} = message;
messages.forEach(message => {
message.data = JSON.parse(message.data);
});
return message.topicMessages;
}
function TopicMessagesListRequest({
cursor,
forward, // boolean
limit, // number <= 100
// set only one of the followings
userId,
room,
groupId
} = {}) {
function build_() {
const msg = {
topicMessagesList: {
cursor,
forward,
limit
}
};
if (userId) {
msg.topicMessagesList.userId = userId;
} else if (room) {
msg.topicMessagesList.room = room;
} else if (groupId) {
msg.topicMessagesList.groupId = groupId;
}
return msg;
}
return {
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
get forward() {
return forward;
},
set forward(val) {
forward = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get userId() {
return userId;
},
set userId(val) {
userId = val;
},
get room() {
return room;
},
set room(val) {
room = val;
},
get groupId() {
return groupId;
},
set groupId(val) {
groupId = val;
},
build_,
processResponse_: TopicMessagesResponse
};
}
class LeaderboardRecordWriteRequest {
constructor() {
this.records = [];
function TopicsResponse(message) {
return message.topics;
}
function TopicsJoinRequest({
// NOTE: The server only processes the first item of the list,
// and will ignore and logs a warning message for other items.
topics = []
} = {}) {
const self = {
get topics() {
return topics;
},
set topics(val) {
topics = val;
},
dm,
group,
room,
build_,
processResponse_: TopicsResponse
};
return self;
function dm(userId) {
topics.push({ userId });
return self;
}
set(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
"set": value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
};
function group(groupId) {
topics.push({ groupId });
return self;
}
this.records.push(record);
function room(room) {
topics.push({ room });
return self;
}
best(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
best: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
function build_() {
return {
topicsJoin: {
joins: topics
}
};
this.records.push(record);
}
}
decrement(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
decr: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
function TopicsLeaveRequest({
// NOTE: The server only processes the first item of the list,
// and will ignore and logs a warning message for other items.
topics = []
} = {}) {
function build_() {
return {
topicsLeave: {
topics
}
};
}
this.records.push(record);
return {
get topics() {
return topics;
},
set topics(val) {
topics = val;
},
build_
};
}
function UnlinkRequest({
custom,
device,
facebook,
google,
email
} = {}) {
function build_() {
if (custom) return { link: { custom } };
if (device) return { link: { device } };
if (facebook) return { link: { facebook } };
if (google) return { link: { google } };
if (email) return { link: { email } };
}
increment(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
incr: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
return {
get custom() {
return custom;
},
set custom(val) {
custom = val;
},
get device() {
return device;
},
set device(val) {
device = val;
},
get facebook() {
return facebook;
},
set facebook(val) {
facebook = val;
},
get google() {
return google;
},
set google(val) {
google = val;
},
get email() {
return email;
},
set email(val) {
email = val;
},
build_
};
}
function UsersResponse(message) {
const {
users: {
users = []
}
} = message;
users.forEach(user => {
user.metadata = JSON.parse(user.metadata);
});
return users;
}
function UsersFetchRequest({
userIds = [],
handles = []
} = {}) {
function build_() {
return {
usersFetch: {
users: [...userIds.map(userId => ({ userId })), ...handles.map(handle => ({ handle }))]
}
};
this.records.push(record);
}
build_() {
return { leaderboardRecordsWrite: { records: this.records } };
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
get handles() {
return handles;
},
set handles(val) {
handles = val;
},
build_,
processResponse_: UsersResponse
};
}

@@ -1576,47 +2928,49 @@

exports.AuthenticateRequest = AuthenticateRequest;
// include fetch polyfill
exports.Client = Client;
exports.Session = Session;
exports.LinkRequest = LinkRequest;
exports.UnlinkRequest = UnlinkRequest;
exports.SelfFetchRequest = SelfFetchRequest;
exports.SelfUpdateRequest = SelfUpdateRequest;
exports.UsersFetchRequest = UsersFetchRequest;
exports.StorageListRequest = StorageListRequest;
exports.StorageFetchRequest = StorageFetchRequest;
exports.StorageWriteRequest = StorageWriteRequest;
exports.StorageRemoveRequest = StorageRemoveRequest;
exports.StorageUpdateRequest = StorageUpdateRequest;
exports.AuthenticateRequest = AuthenticateRequest;
exports.FriendsAddRequest = FriendsAddRequest;
exports.FriendsRemoveRequest = FriendsRemoveRequest;
exports.FriendsBlockRequest = FriendsBlockRequest;
exports.FriendsListRequest = FriendsListRequest;
exports.TopicsJoinRequest = TopicsJoinRequest;
exports.TopicsLeaveRequest = TopicsLeaveRequest;
exports.TopicMessageSendRequest = TopicMessageSendRequest;
exports.TopicMessagesListRequest = TopicMessagesListRequest;
exports.FriendsRemoveRequest = FriendsRemoveRequest;
exports.GroupsCreateRequest = GroupsCreateRequest;
exports.GroupsUpdateRequest = GroupsUpdateRequest;
exports.GroupsRemoveRequest = GroupsRemoveRequest;
exports.GroupsFetchRequest = GroupsFetchRequest;
exports.GroupsJoinRequest = GroupsJoinRequest;
exports.GroupsLeaveRequest = GroupsLeaveRequest;
exports.GroupsListRequest = GroupsListRequest;
exports.GroupsRemoveRequest = GroupsRemoveRequest;
exports.GroupsSelfListRequest = GroupsSelfListRequest;
exports.GroupUsersListRequest = GroupUsersListRequest;
exports.GroupsJoinRequest = GroupsJoinRequest;
exports.GroupsLeaveRequest = GroupsLeaveRequest;
exports.GroupsUpdateRequest = GroupsUpdateRequest;
exports.GroupUsersAddRequest = GroupUsersAddRequest;
exports.GroupUsersKickRequest = GroupUsersKickRequest;
exports.GroupUsersListRequest = GroupUsersListRequest;
exports.GroupUsersPromoteRequest = GroupUsersPromoteRequest;
exports.LeaderboardRecordsFetchRequest = LeaderboardRecordsFetchRequest;
exports.LeaderboardRecordsListRequest = LeaderboardRecordsListRequest;
exports.LeaderboardRecordWriteRequest = LeaderboardRecordWriteRequest;
exports.LeaderboardsListRequest = LeaderboardsListRequest;
exports.LinkRequest = LinkRequest;
exports.MatchCreateRequest = MatchCreateRequest;
exports.MatchDataSendRequest = MatchDataSendRequest;
exports.MatchesJoinRequest = MatchesJoinRequest;
exports.MatchesLeaveRequest = MatchesLeaveRequest;
exports.MatchmakeAddRequest = MatchmakeAddRequest;
exports.MatchmakeRemoveRequest = MatchmakeRemoveRequest;
exports.NotificationsListRequest = NotificationsListRequest;
exports.NotificationsRemoveRequest = NotificationsRemoveRequest;
exports.RpcRequest = RpcRequest;
exports.MatchmakeAddRequest = MatchmakeAddRequest;
exports.MatchmakeRemoveRequest = MatchmakeRemoveRequest;
exports.MatchCreateRequest = MatchCreateRequest;
exports.MatchesJoinRequest = MatchesJoinRequest;
exports.MatchesLeaveRequest = MatchesLeaveRequest;
exports.MatchDataSendRequest = MatchDataSendRequest;
exports.LeaderboardsListRequest = LeaderboardsListRequest;
exports.LeaderboardRecordsFetchRequest = LeaderboardRecordsFetchRequest;
exports.LeaderboardRecordsListRequest = LeaderboardRecordsListRequest;
exports.LeaderboardRecordWriteRequest = LeaderboardRecordWriteRequest;
exports.SelfFetchRequest = SelfFetchRequest;
exports.SelfUpdateRequest = SelfUpdateRequest;
exports.StorageFetchRequest = StorageFetchRequest;
exports.StorageListRequest = StorageListRequest;
exports.StorageRemoveRequest = StorageRemoveRequest;
exports.StorageUpdateRequest = StorageUpdateRequest;
exports.StorageWriteRequest = StorageWriteRequest;
exports.TopicMessageSendRequest = TopicMessageSendRequest;
exports.TopicMessagesListRequest = TopicMessagesListRequest;
exports.TopicsJoinRequest = TopicsJoinRequest;
exports.TopicsLeaveRequest = TopicsLeaveRequest;
exports.UnlinkRequest = UnlinkRequest;
exports.UsersFetchRequest = UsersFetchRequest;

@@ -0,1 +1,474 @@

(function(self) {
'use strict';
if (self.fetch) {
return
}
var support = {
searchParams: 'URLSearchParams' in self,
iterable: 'Symbol' in self && 'iterator' in Symbol,
blob: 'FileReader' in self && 'Blob' in self && (function() {
try {
new Blob();
return true
} catch(e) {
return false
}
})(),
formData: 'FormData' in self,
arrayBuffer: 'ArrayBuffer' in self
};
if (support.arrayBuffer) {
var viewClasses = [
'[object Int8Array]',
'[object Uint8Array]',
'[object Uint8ClampedArray]',
'[object Int16Array]',
'[object Uint16Array]',
'[object Int32Array]',
'[object Uint32Array]',
'[object Float32Array]',
'[object Float64Array]'
];
var isDataView = function(obj) {
return obj && DataView.prototype.isPrototypeOf(obj)
};
var isArrayBufferView = ArrayBuffer.isView || function(obj) {
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
};
}
function normalizeName(name) {
if (typeof name !== 'string') {
name = String(name);
}
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
throw new TypeError('Invalid character in header field name')
}
return name.toLowerCase()
}
function normalizeValue(value) {
if (typeof value !== 'string') {
value = String(value);
}
return value
}
// Build a destructive iterator for the value list
function iteratorFor(items) {
var iterator = {
next: function() {
var value = items.shift();
return {done: value === undefined, value: value}
}
};
if (support.iterable) {
iterator[Symbol.iterator] = function() {
return iterator
};
}
return iterator
}
function Headers(headers) {
this.map = {};
if (headers instanceof Headers) {
headers.forEach(function(value, name) {
this.append(name, value);
}, this);
} else if (Array.isArray(headers)) {
headers.forEach(function(header) {
this.append(header[0], header[1]);
}, this);
} else if (headers) {
Object.getOwnPropertyNames(headers).forEach(function(name) {
this.append(name, headers[name]);
}, this);
}
}
Headers.prototype.append = function(name, value) {
name = normalizeName(name);
value = normalizeValue(value);
var oldValue = this.map[name];
this.map[name] = oldValue ? oldValue+','+value : value;
};
Headers.prototype['delete'] = function(name) {
delete this.map[normalizeName(name)];
};
Headers.prototype.get = function(name) {
name = normalizeName(name);
return this.has(name) ? this.map[name] : null
};
Headers.prototype.has = function(name) {
return this.map.hasOwnProperty(normalizeName(name))
};
Headers.prototype.set = function(name, value) {
this.map[normalizeName(name)] = normalizeValue(value);
};
Headers.prototype.forEach = function(callback, thisArg) {
for (var name in this.map) {
if (this.map.hasOwnProperty(name)) {
callback.call(thisArg, this.map[name], name, this);
}
}
};
Headers.prototype.keys = function() {
var items = [];
this.forEach(function(value, name) { items.push(name); });
return iteratorFor(items)
};
Headers.prototype.values = function() {
var items = [];
this.forEach(function(value) { items.push(value); });
return iteratorFor(items)
};
Headers.prototype.entries = function() {
var items = [];
this.forEach(function(value, name) { items.push([name, value]); });
return iteratorFor(items)
};
if (support.iterable) {
Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
}
function consumed(body) {
if (body.bodyUsed) {
return Promise.reject(new TypeError('Already read'))
}
body.bodyUsed = true;
}
function fileReaderReady(reader) {
return new Promise(function(resolve, reject) {
reader.onload = function() {
resolve(reader.result);
};
reader.onerror = function() {
reject(reader.error);
};
})
}
function readBlobAsArrayBuffer(blob) {
var reader = new FileReader();
var promise = fileReaderReady(reader);
reader.readAsArrayBuffer(blob);
return promise
}
function readBlobAsText(blob) {
var reader = new FileReader();
var promise = fileReaderReady(reader);
reader.readAsText(blob);
return promise
}
function readArrayBufferAsText(buf) {
var view = new Uint8Array(buf);
var chars = new Array(view.length);
for (var i = 0; i < view.length; i++) {
chars[i] = String.fromCharCode(view[i]);
}
return chars.join('')
}
function bufferClone(buf) {
if (buf.slice) {
return buf.slice(0)
} else {
var view = new Uint8Array(buf.byteLength);
view.set(new Uint8Array(buf));
return view.buffer
}
}
function Body() {
this.bodyUsed = false;
this._initBody = function(body) {
this._bodyInit = body;
if (!body) {
this._bodyText = '';
} else if (typeof body === 'string') {
this._bodyText = body;
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body;
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body;
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this._bodyText = body.toString();
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
this._bodyArrayBuffer = bufferClone(body.buffer);
// IE 10-11 can't handle a DataView body.
this._bodyInit = new Blob([this._bodyArrayBuffer]);
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
this._bodyArrayBuffer = bufferClone(body);
} else {
throw new Error('unsupported BodyInit type')
}
if (!this.headers.get('content-type')) {
if (typeof body === 'string') {
this.headers.set('content-type', 'text/plain;charset=UTF-8');
} else if (this._bodyBlob && this._bodyBlob.type) {
this.headers.set('content-type', this._bodyBlob.type);
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
}
}
};
if (support.blob) {
this.blob = function() {
var rejected = consumed(this);
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return Promise.resolve(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
return Promise.resolve(new Blob([this._bodyArrayBuffer]))
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as blob')
} else {
return Promise.resolve(new Blob([this._bodyText]))
}
};
this.arrayBuffer = function() {
if (this._bodyArrayBuffer) {
return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
} else {
return this.blob().then(readBlobAsArrayBuffer)
}
};
}
this.text = function() {
var rejected = consumed(this);
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return readBlobAsText(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as text')
} else {
return Promise.resolve(this._bodyText)
}
};
if (support.formData) {
this.formData = function() {
return this.text().then(decode)
};
}
this.json = function() {
return this.text().then(JSON.parse)
};
return this
}
// HTTP methods whose capitalization should be normalized
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
function normalizeMethod(method) {
var upcased = method.toUpperCase();
return (methods.indexOf(upcased) > -1) ? upcased : method
}
function Request(input, options) {
options = options || {};
var body = options.body;
if (input instanceof Request) {
if (input.bodyUsed) {
throw new TypeError('Already read')
}
this.url = input.url;
this.credentials = input.credentials;
if (!options.headers) {
this.headers = new Headers(input.headers);
}
this.method = input.method;
this.mode = input.mode;
if (!body && input._bodyInit != null) {
body = input._bodyInit;
input.bodyUsed = true;
}
} else {
this.url = String(input);
}
this.credentials = options.credentials || this.credentials || 'omit';
if (options.headers || !this.headers) {
this.headers = new Headers(options.headers);
}
this.method = normalizeMethod(options.method || this.method || 'GET');
this.mode = options.mode || this.mode || null;
this.referrer = null;
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
throw new TypeError('Body not allowed for GET or HEAD requests')
}
this._initBody(body);
}
Request.prototype.clone = function() {
return new Request(this, { body: this._bodyInit })
};
function decode(body) {
var form = new FormData();
body.trim().split('&').forEach(function(bytes) {
if (bytes) {
var split = bytes.split('=');
var name = split.shift().replace(/\+/g, ' ');
var value = split.join('=').replace(/\+/g, ' ');
form.append(decodeURIComponent(name), decodeURIComponent(value));
}
});
return form
}
function parseHeaders(rawHeaders) {
var headers = new Headers();
rawHeaders.split(/\r?\n/).forEach(function(line) {
var parts = line.split(':');
var key = parts.shift().trim();
if (key) {
var value = parts.join(':').trim();
headers.append(key, value);
}
});
return headers
}
Body.call(Request.prototype);
function Response(bodyInit, options) {
if (!options) {
options = {};
}
this.type = 'default';
this.status = 'status' in options ? options.status : 200;
this.ok = this.status >= 200 && this.status < 300;
this.statusText = 'statusText' in options ? options.statusText : 'OK';
this.headers = new Headers(options.headers);
this.url = options.url || '';
this._initBody(bodyInit);
}
Body.call(Response.prototype);
Response.prototype.clone = function() {
return new Response(this._bodyInit, {
status: this.status,
statusText: this.statusText,
headers: new Headers(this.headers),
url: this.url
})
};
Response.error = function() {
var response = new Response(null, {status: 0, statusText: ''});
response.type = 'error';
return response
};
var redirectStatuses = [301, 302, 303, 307, 308];
Response.redirect = function(url, status) {
if (redirectStatuses.indexOf(status) === -1) {
throw new RangeError('Invalid status code')
}
return new Response(null, {status: status, headers: {location: url}})
};
self.Headers = Headers;
self.Request = Request;
self.Response = Response;
self.fetch = function(input, init) {
return new Promise(function(resolve, reject) {
var request = new Request(input, init);
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var options = {
status: xhr.status,
statusText: xhr.statusText,
headers: parseHeaders(xhr.getAllResponseHeaders() || '')
};
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
var body = 'response' in xhr ? xhr.response : xhr.responseText;
resolve(new Response(body, options));
};
xhr.onerror = function() {
reject(new TypeError('Network request failed'));
};
xhr.ontimeout = function() {
reject(new TypeError('Network request failed'));
};
xhr.open(request.method, request.url, true);
if (request.credentials === 'include') {
xhr.withCredentials = true;
}
if ('responseType' in xhr && support.blob) {
xhr.responseType = 'blob';
}
request.headers.forEach(function(value, name) {
xhr.setRequestHeader(name, value);
});
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
})
};
self.fetch.polyfill = true;
})(typeof self !== 'undefined' ? self : window);
/**
* Build a string which looks like a UUIDv4 type.
*/
const uuidv4 = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, character => {
const randomNumber = Math.random() * 16 | 0,
result = character === 'x' ? randomNumber : randomNumber & 0x3 | 0x8;
return result.toString(16);
});
};
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

@@ -178,73 +651,37 @@

/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class Session {
constructor(createdAt, expiresAt, handle, id, token) {
this.token_ = token;
const VERSION = '0.1.0';
const DEFAULT_SERVER_KEY = 'defaultkey';
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = '7350';
/**
* Build a string which looks like a UUIDv4 type.
*/
const uuidv4 = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, character => {
const randomNumber = Math.random() * 16 | 0,
result = character === 'x' ? randomNumber : randomNumber & 0x3 | 0x8;
return result.toString(16);
});
};
class AuthenticateRequest {
constructor(message) {
this.message_ = message;
this.createdAt = createdAt;
this.expiresAt = expiresAt;
this.handle = handle;
this.id = id;
}
static custom(id) {
return new AuthenticateRequest({
custom: id
});
/**
* @param {number} currentime The current system time in milliseconds.
* @returns {bool} True if the session has expired.
*/
isexpired(currenttime) {
return this.expiresAt - currenttime < 0;
}
static device(id) {
return new AuthenticateRequest({
device: id
});
}
static restore(jwt) {
const parts = jwt.split('.');
if (parts.length != 3) {
throw 'jwt is not valid.';
}
const decoded = JSON.parse(base64.decode(parts[1]));
const expiresAt = Math.floor(parseInt(decoded['exp']) * 1000);
static email(email, password) {
return new AuthenticateRequest({
email: {
email: email,
password: password
}
});
return new Session(Date.now(), expiresAt, decoded['han'], decoded['uid'], jwt);
}
}
static facebook(oauthToken) {
return new AuthenticateRequest({
facebook: oauthToken
});
}
const VERSION = '0.1.0';
const DEFAULT_SERVER_KEY = 'defaultkey';
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = '7350';
static google(oauthToken) {
return new AuthenticateRequest({
google: oauthToken
});
}
}
class Client {

@@ -354,74 +791,4 @@ constructor(serverkey = DEFAULT_SERVER_KEY, host = DEFAULT_HOST, port = DEFAULT_PORT, lang = 'en', ssl = false, verbose = false) {

p.reject(message.error);
} else if (message.self) {
p.resolve(message.self);
} else if (message.users) {
message.users.users.forEach(function (user) {
user.metadata = JSON.parse(user.metadata);
});
p.resolve(message.users.users);
} else if (message.storageData) {
p.resolve(message.storageData);
} else if (message.storageKeys) {
p.resolve(message.storageKeys);
} else if (message.friends) {
message.friends.friends.forEach(function (friend) {
friend.user.metadata = JSON.parse(friend.user.metadata);
});
p.resolve(message.friends);
} else if (message.topics) {
p.resolve(message.topics);
} else if (message.topicMessageAck) {
p.resolve(message.topicMessageAck);
} else if (message.topicMessages) {
message.topicMessages.messages.forEach(function (message) {
message.data = JSON.parse(message.data);
});
p.resolve(message.topicMessages);
} else if (message.groups) {
message.groups.groups.forEach(function (group) {
group.metadata = JSON.parse(group.metadata);
});
p.resolve(message.groups);
} else if (message.groupsSelf) {
message.groupsSelf.groupsSelf.forEach(function (groupSelf) {
groupSelf.group.metadata = JSON.parse(groupSelf.group.metadata);
});
p.resolve(message.groupsSelf);
} else if (message.groupUsers) {
message.groupUsers.users.forEach(function (groupUser) {
groupUser.user.metadata = JSON.parse(groupUser.user.metadata);
});
p.resolve(message.groupUsers);
} else if (message.rpc) {
message.rpc.payload = message.rpc.payload ? JSON.parse(message.rpc.payload) : null;
p.resolve({ id: message.rpc.id, payload: message.rpc.payload });
} else if (message.notifications) {
message.notifications.notifications.forEach(function (notification) {
notification.content = JSON.parse(notification.content);
});
p.resolve(message.notifications);
} else if (message.matchmakeTicket) {
p.resolve(message.matchmakeTicket);
} else if (message.match) {
p.resolve(message.match);
} else if (message.matches) {
p.resolve(message.matches);
} else if (message.leaderboards) {
message.leaderboards.leaderboards.forEach(function (leaderboard) {
leaderboard.metadata = JSON.parse(leaderboard.metadata);
});
p.resolve(message.leaderboards);
} else if (message.leaderboardRecords) {
message.leaderboardRecords.records.forEach(function (record) {
record.metadata = JSON.parse(record.metadata);
});
p.resolve(message.leaderboardRecords);
} else {
// if the object has properties, other than the collationId, log a warning
if (window.console && Object.keys(message).length > 1) {
console.error("Unrecognized message received: %o", message);
p.resolve(message);
} else {
p.resolve();
}
p.resolve(message);
}

@@ -448,6 +815,8 @@ }

message.collationId = collationId;
return this.send_(message, collationId, request.constructor.name);
return this.send_(message, collationId).then(message => {
if (request.processResponse_) return request.processResponse_(message);
});
}
send_(message, collationId, requestName) {
send_(message, collationId) {
if (this.socket_ == null) {

@@ -468,3 +837,3 @@ return new Promise((resolve, reject) => {

if (this.verbose && window.console) {
console.log("%s: %o", requestName, message);
console.log("%o", message);
}

@@ -518,494 +887,655 @@

class Session {
constructor(createdAt, expiresAt, handle, id, token) {
this.token_ = token;
function AuthenticateRequest(message) {
return {
message_: message
};
}
this.createdAt = createdAt;
this.expiresAt = expiresAt;
this.handle = handle;
this.id = id;
}
Object.assign(AuthenticateRequest, {
custom,
device,
email,
facebook,
google
});
/**
* @param {number} currentime The current system time in milliseconds.
* @returns {bool} True if the session has expired.
*/
isexpired(currenttime) {
return this.expiresAt - currenttime < 0;
}
function custom(id) {
return new AuthenticateRequest({
custom: id
});
}
static restore(jwt) {
const parts = jwt.split('.');
if (parts.length != 3) {
throw 'jwt is not valid.';
function device(id) {
return new AuthenticateRequest({
device: id
});
}
function email(email, password) {
return new AuthenticateRequest({
email: {
email,
password
}
const decoded = JSON.parse(base64.decode(parts[1]));
const expiresAt = Math.floor(parseInt(decoded['exp']) * 1000);
});
}
return new Session(Date.now(), expiresAt, decoded['han'], decoded['uid'], jwt);
}
function facebook(oauthToken) {
return new AuthenticateRequest({
facebook: oauthToken
});
}
class LinkRequest {
constructor() {
// only set one of these fields
this.custom = null;
this.device = null;
this.facebook = null;
this.google = null;
this.email = {
email: "",
password: ""
function google(oauthToken) {
return new AuthenticateRequest({
google: oauthToken
});
}
function FriendsAddRequest({
userIds = [],
handles = []
} = {}) {
function build_() {
return {
friendsAdd: {
friends: [...userIds.map(userId => ({ userId })), ...handles.map(handle => ({ handle }))]
}
};
}
build_() {
if (this.custom) {
return { link: { custom: this.custom } };
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
if (this.device) {
return { link: { device: this.device } };
}
get handles() {
return handles;
},
set handles(val) {
handles = val;
},
if (this.facebook) {
return { link: { facebook: this.facebook } };
}
if (this.google) {
return { link: { google: this.google } };
}
if (this.email.email != "") {
return { link: { email: this.email } };
}
}
build_
};
}
class UnlinkRequest {
constructor() {
// only set one of these fields
this.custom = null;
this.device = null;
this.facebook = null;
this.google = null;
this.email = null;
function FriendsBlockRequest({
userIds = []
} = {}) {
function build_() {
return {
friendsBlock: {
userIds: userIds.map(userId => ({ userId }))
}
};
}
build_() {
if (this.custom) {
return { unlink: { custom: this.custom } };
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
if (this.device) {
return { unlink: { device: this.device } };
}
build_
};
}
if (this.facebook) {
return { unlink: { facebook: this.facebook } };
}
function FriendsResponse(message) {
const {
friends: {
friends = []
} = {}
} = message;
if (this.google) {
return { unlink: { google: this.google } };
}
friends.forEach(friend => {
friend.user.metadata = JSON.parse(friend.user.metadata);
});
if (this.email) {
return { unlink: { email: this.email } };
}
}
return message.friends;
}
class SelfFetchRequest {
constructor() {}
build_() {
function FriendsListRequest() {
function build_() {
return {
selfFetch: {}
friendsList: {}
};
}
return {
build_,
processResponse_: FriendsResponse
};
}
class SelfUpdateRequest {
constructor() {
this.handle = null;
this.fullname = null;
this.timezone = null;
this.location = null;
this.lang = null;
this.metadata = null;
this.avatarUrl = null;
}
build_() {
function FriendsRemoveRequest({
userIds = []
} = {}) {
function build_() {
return {
selfUpdate: {
handle: this.handle,
fullname: this.fullname,
timezone: this.timezone,
location: this.location,
lang: this.lang,
avatarUrl: this.avatarUrl,
metadata: this.metadata ? JSON.stringify(this.metadata) : "{}"
friendsRemove: {
userIds: userIds.map(userId => ({ userId }))
}
};
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
build_
};
}
class UsersFetchRequest {
constructor() {
// base64 user IDs
this.userIds = [];
this.handles = [];
}
function GroupsResponse(message) {
const {
groups: {
groups = []
} = {}
} = message;
build_() {
var msg = { usersFetch: { users: [] } };
this.userIds.forEach(function (id) {
msg.usersFetch.users.push({ userId: id });
});
this.handles.forEach(function (handle) {
msg.usersFetch.users.push({ handle: handle });
});
return msg;
}
groups.forEach(group => {
group.metadata = JSON.parse(group.metadata);
});
return message.groups;
}
class StorageListRequest {
constructor() {
// base64 user ID
this.userId = null;
this.bucket = null;
this.collection = null;
this.limit = null;
this.cursor = null;
function GroupsCreateRequest({
groups = []
} = {}) {
function create(name, description, avatarUrl, lang, metadata = {}, privateGroup) {
groups.push({
name,
description,
avatarUrl,
lang,
private: privateGroup,
metadata: JSON.stringify(metadata)
});
}
build_() {
function build_() {
return {
storageList: {
userId: this.userId,
bucket: this.bucket,
collection: this.collection,
limit: this.limit,
cursor: this.cursor
groupsCreate: {
groups
}
};
}
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
create,
build_,
processResponse_: GroupsResponse
};
}
class StorageFetchRequest {
constructor() {
this.keys = [];
function GroupsFetchRequest({
groupIds = [],
names = []
} = {}) {
function build_() {
return {
groupsFetch: {
groups: [...groupIds.map(groupId => ({ groupId })), ...names.map(name => ({ name }))]
}
};
}
fetch(bucket, collection, record, userId) {
this.keys.push({
bucket: bucket,
collection: collection,
record: record,
userId: userId
});
return this;
}
return {
get groupIds() {
return groupIds;
},
set groupIds(val) {
groupIds = val;
},
build_() {
return { storageFetch: { keys: this.keys } };
}
get names() {
return names;
},
set names(val) {
names = val;
},
build_,
processResponse_: GroupsResponse
};
}
class StorageWriteRequest {
constructor() {
this.data = [];
function GroupsJoinRequest({
groups = []
} = {}) {
function build_() {
return {
groupsJoin: {
groupIds: groups
}
};
}
write(bucket, collection, record, value, permissionRead = 1, permissionWrite = 1, version) {
this.data.push({
bucket: bucket,
collection: collection,
record: record,
value: value ? JSON.stringify(value) : "{}",
version: version ? version : null,
permissionRead: permissionRead,
permissionWrite: permissionWrite
});
return this;
}
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
build_() {
return { storageWrite: { data: this.data } };
}
build_
};
}
class StorageRemoveRequest {
constructor() {
this.keys = [];
function GroupsLeaveRequest({
groups = []
} = {}) {
function build_() {
return {
groupsLeave: {
groupIds: groups
}
};
}
remove(bucket, collection, record, userId) {
this.keys.push({
bucket: bucket,
collection: collection,
record: record,
userId: userId
});
return this;
}
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
build_() {
return { storageRemove: { keys: this.keys } };
}
build_
};
}
class StorageUpdateRequest {
constructor() {
this.updates = [];
}
function GroupsListRequest({
pageLimit,
orderByAsc,
cursor,
build_() {
return { storageUpdate: { updates: this.updates } };
}
// only set one of the followings
lang,
createdAt,
count
} = {}) {
function build_() {
const msg = {
groupsList: {
pageLimit,
orderByAsc,
cursor
}
};
/**
storageOps variable must be an array
*/
update(bucket, collection, record, storageOps = [], permissionRead = 1, permissionWrite = 1, version) {
this.updates.push({
key: {
bucket: bucket,
collection: collection,
record: record,
version: version ? version : null
},
permissionRead: permissionRead,
permissionWrite: permissionWrite,
ops: storageOps
});
return this;
}
if (lang) {
msg.groupsList.lang = lang;
} else if (createdAt) {
msg.groupsList.createdAt = createdAt;
} else if (count) {
msg.groupsList.count = count;
}
static add(path, value) {
return {
op: 0,
path: path,
value: JSON.stringify(value)
};
return msg;
}
static append(path, value) {
return {
op: 1,
path: path,
value: JSON.stringify(value)
};
}
return {
get pageLimit() {
return pageLimit;
},
set pageLimit(val) {
pageLimit = val;
},
static copy(path, from) {
return {
op: 2,
path: path,
from: from
};
}
get orderByAsc() {
return orderByAsc;
},
set orderByAsc(val) {
orderByAsc = val;
},
static incr(path, value) {
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
get lang() {
return lang;
},
set lang(val) {
lang = val;
},
get createdAt() {
return createdAt;
},
set createdAt(val) {
createdAt = val;
},
get count() {
return count;
},
set count(val) {
count = val;
},
build_,
processResponse_: GroupsResponse
};
}
function GroupsRemoveRequest({
groups = []
} = {}) {
function build_() {
return {
op: 3,
path: path,
value: JSON.stringify(value)
groupsRemove: {
groupIds: groups
}
};
}
static init(path, value) {
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
build_
};
}
function GroupsSelfResponse(message) {
const {
groupsSelf: {
groupsSelf = []
} = {}
} = message;
groupsSelf.forEach(groupSelf => {
groupSelf.group.metadata = JSON.parse(groupSelf.group.metadata);
});
return message.groupsSelf;
}
function GroupsSelfListRequest() {
function build_() {
return {
op: 4,
path: path,
value: JSON.stringify(value)
groupsSelfList: {}
};
}
static merge(path, from) {
return {
op: 5,
path: path,
from: from
};
return {
build_,
processResponse_: GroupsSelfResponse
};
}
function GroupsUpdateRequest({
groups = []
} = {}) {
function update(groupId, name, description, avatarUrl, lang, metadata = {}, privateGroup) {
groups.push({
groupId,
name,
description,
avatarUrl,
lang,
private: privateGroup,
metadata: JSON.string(metadata)
});
}
static move(path, from) {
function build_() {
return {
op: 6,
path: path,
from: from
groupsUpdate: {
groups
}
};
}
static remove(path) {
return {
op: 8,
path: path
};
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
update,
build_
};
}
function GroupUsersAddRequest({
adds = []
} = {}) {
function add(groupId, userId) {
adds.push({
groupId,
userID
});
}
static replace(path, value) {
function build_() {
return {
op: 9,
path: path,
value: JSON.stringify(value)
groupUsersAdd: {
groupUsers: adds
}
};
}
static test(path, value) {
return {
op: 10,
path: path,
value: JSON.stringify(value)
};
return {
get adds() {
return adds;
},
set add(val) {
adds = val;
},
add,
build_
};
}
function GroupUsersKickRequest({
kicks = []
} = {}) {
function kick(groupId, userId) {
kicks.push({ groupId, userID });
}
static compare(path, value, assertValue) {
function build_() {
return {
op: 11,
path: path,
value: JSON.stringify(value),
assert: assertValue
groupUsersKick: {
groupUsers: kicks
}
};
}
}
class FriendsAddRequest {
constructor() {
// base64 user IDs
this.userIds = [];
this.handles = [];
}
return {
get kicks() {
return kicks;
},
set kicks(val) {
kicks = val;
},
build_() {
var msg = { friendsAdd: { friends: [] } };
this.userIds.forEach(function (id) {
msg.friendsAdd.friends.push({ userId: id });
});
this.handles.forEach(function (handle) {
msg.friendsAdd.friends.push({ handle: handle });
});
return msg;
}
kick,
build_
};
}
class FriendsRemoveRequest {
constructor() {
// base64 user IDs
this.userIds = [];
}
function GroupUsersResponse(message) {
const {
groupUsers: {
users = []
}
} = message;
build_() {
var msg = { friendsRemove: { userIds: [] } };
this.userIds.forEach(function (id) {
msg.friendsRemove.userIds.push({ userId: id });
});
return msg;
}
users.forEach(groupUser => {
groupUser.user.metadata = JSON.parse(groupUser.user.metadata);
});
return message.groupUsers;
}
class FriendsBlockRequest {
constructor() {
// base64 user IDs
this.userIds = [];
function GroupUsersListRequest(groupId) {
function build_() {
return {
groupUsersList: {
groupId
}
};
}
build_() {
var msg = { friendsBlock: { userIds: [] } };
this.userIds.forEach(function (id) {
msg.friendsBlock.userIds.push({ userId: id });
});
return msg;
}
return {
get groupId() {
return groupId;
},
set groupId(val) {
groupId = val;
},
build_,
processResponse_: GroupUsersResponse
};
}
class FriendsListRequest {
constructor() {}
function GroupUsersPromoteRequest({
promotes = []
} = {}) {
function promote(groupId, userID) {
promotes.push({ groupId, userId });
}
build_() {
function build_() {
return {
friendsList: {}
groupUsersPromote: {
groupUsers: promote
}
};
}
}
class TopicsJoinRequest {
constructor() {
// NOTE: The server only processes the first item of the list, and will ignore and logs a warning message for other items.
this.topics = [];
}
return {
get promotes() {
return promotes;
},
set promotes(val) {
promotes = val;
},
dm(userId) {
this.topics.push({ userId: userId });
return this;
}
promote,
build_
};
}
group(groupId) {
this.topics.push({ groupId: groupId });
return this;
}
function LeaderboardRecordsResponse(message) {
const {
leaderboardRecords: {
records = []
}
} = message;
room(room) {
this.topics.push({ room: room });
return this;
}
records.forEach(record => {
record.metadata = JSON.parse(record.metadata);
});
build_() {
return { topicsJoin: { joins: this.topics } };
}
return message.leaderboardRecords;
}
class TopicsLeaveRequest {
constructor() {
// NOTE: The server only processes the first item of the list, and will ignore and logs a warning message for other items.
this.topics = []; // this is a list of topicIds.
function LeaderboardRecordsFetchRequest({
leaderboardIds = [],
limit,
cursor
} = {}) {
function build_() {
return {
leaderboardRecordsFetch: {
leaderboardIds,
limit,
cursor
}
};
}
build_() {
return { topicsLeave: { topics: this.topics } };
}
}
return {
get leaderboardIds() {
return leaderboardIds;
},
set leaderboardIds(val) {
leaderboardIds = val;
},
class TopicMessageSendRequest {
constructor() {
// this is the topicId.
this.topic = null;
this.data = null;
}
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
build_() {
return { topicMessageSend: {
topic: this.topic,
data: JSON.stringify(this.data)
} };
}
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
build_,
processResponse_: LeaderboardRecordsResponse
};
}
class TopicMessagesListRequest {
constructor() {
this.cursor = null;
this.forward = null; // boolean
this.limit = null; // number <= 100
function LeaderboardRecordsListRequest({
leaderboardId,
limit,
cursor,
// set only one of the followings
this.userId = null;
this.room = null;
this.groupId = null;
}
// only set one the following
lang,
location,
timezone,
ownerId,
ownerIds = []
} = {}) {
function build_() {
const msg = {
leaderboardRecordsList: {
leaderboardId,
limit,
cursor
}
};
build_() {
var msg = { topicMessagesList: {
cursor: this.cursor,
forward: this.forward,
limit: this.limit
} };
if (this.userId) {
msg.topicMessagesList.userId = this.userId;
} else if (this.room) {
msg.topicMessagesList.room = this.room;
} else if (this.groupId) {
msg.topicMessagesList.groupId = this.groupId;
if (lang) {
msg.leaderboardRecordsList.lang = lang;
} else if (location) {
msg.leaderboardRecordsList.location = location;
} else if (timezone) {
msg.leaderboardRecordsList.timezone = timezone;
} else if (ownerId) {
msg.leaderboardRecordsList.ownerId = ownerId;
} else if (ownerIds.length > 0) {
msg.leaderboardRecordsList.ownerIds = { ownerIds: ownerIds };
}

@@ -1015,317 +1545,486 @@

}
return {
get leaderboardId() {
return leaderboardId;
},
set leaderboardId(val) {
leaderboardId = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
get lang() {
return lang;
},
set lang(val) {
lang = val;
},
get location() {
return location;
},
set location(val) {
location = val;
},
get timezone() {
return timezone;
},
set timezone(val) {
timezone = val;
},
get ownerId() {
return ownerId;
},
set ownerId(val) {
ownerId = val;
},
get ownerIds() {
return ownerIds;
},
set ownerIds(val) {
ownerIds = val;
},
build_,
processResponse_: LeaderboardRecordsResponse
};
}
class GroupsCreateRequest {
constructor() {
this.groups = [];
function LeaderboardRecordWriteRequest({
records = []
} = {}) {
function set(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
set: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
});
}
create(name, description, avatarUrl, lang, metadata, privateGroup) {
this.groups.push({
name: name,
description: description,
avatarUrl: avatarUrl,
lang: lang,
"private": privateGroup,
metadata: metadata ? JSON.stringify(metadata) : "{}"
function best(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
best: value,
metadata: JSON.stringify(metadata),
location,
timezone
});
}
build_() {
return { groupsCreate: { groups: this.groups } };
function decrement(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
decr: value,
metadata: JSON.stringify(metadata),
location,
timezone
});
}
}
class GroupsUpdateRequest {
constructor() {
this.groups = [];
function increment(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
incr: value,
metadata: JSON.stringify(metadata),
location,
timezone
});
}
update(groupId, name, description, avatarUrl, lang, metadata, privateGroup) {
this.groups.push({
groupId: groupId,
name: name,
description: description,
avatarUrl: avatarUrl,
lang: lang,
"private": privateGroup,
metadata: metadata ? JSON.stringify(metadata) : "{}"
});
function build_() {
return {
leaderboardRecordsWrite: {
records
}
};
}
build_() {
return { groupsUpdate: { groups: this.groups } };
}
return {
get records() {
return records;
},
set records(val) {
records = val;
},
set,
best,
decrement,
increment,
build_,
processResponse_: LeaderboardRecordsResponse
};
}
class GroupsRemoveRequest {
constructor() {
// this is a list of groupIds.
this.groups = [];
}
function LeaderboardsResponse(message) {
const {
leaderboards: {
leaderboards = []
}
} = message;
build_() {
return { groupsRemove: { groupIds: this.groups } };
}
leaderboards.forEach(leaderboard => {
leaderboard.metadata = JSON.parse(leaderboard.metadata);
});
return message.leaderboards;
}
class GroupsFetchRequest {
constructor() {
// this is a list of groupIds.
this.groupIds = [];
this.names = [];
function LeaderboardsListRequest({
filterLeaderboardIds = [],
limit,
cursor
} = {}) {
function build_() {
return {
leaderboardsList: {
filterLeaderboardId: filterLeaderboardIds,
limit,
cursor
}
};
}
build_() {
var msg = { groupsFetch: { groups: [] } };
this.groupIds.forEach(function (id) {
msg.groupsFetch.groups.push({ groupId: id });
});
this.names.forEach(function (name) {
msg.groupsFetch.groups.push({ name: name });
});
return msg;
}
return {
get filterLeaderboardIds() {
return filterLeaderboardIds;
},
set filterLeaderboardIds(val) {
filterLeaderboardIds = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
build_,
processResponse_: LeaderboardsResponse
};
}
class GroupsListRequest {
constructor() {
this.pageLimit = null;
this.orderByAsc = null;
this.cursor = null;
// only set one of the followings
this.lang = null;
this.createdAt = null;
this.count = null;
function LinkRequest({
// only set one of these fields
custom,
device,
facebook,
google,
email = {
email: '',
password: ''
}
} = {}) {
function build_() {
if (custom) return { link: { custom } };
if (device) return { link: { device } };
if (facebook) return { link: { facebook } };
if (google) return { link: { google } };
if (email.email != '') return { link: { email } };
}
build_() {
var msg = { groupsList: {
pageLimit: this.pageLimit,
orderByAsc: this.orderByAsc,
cursor: this.cursor
} };
return {
get custom() {
return custom;
},
set custom(val) {
custom = val;
},
if (this.lang) {
msg.groupsList.lang = this.lang;
} else if (this.createdAt) {
msg.groupsList.createdAt = this.createdAt;
} else if (this.count) {
msg.groupsList.count = this.count;
}
get device() {
return device;
},
set device(val) {
device = val;
},
return msg;
}
}
get facebook() {
return facebook;
},
set facebook(val) {
facebook = val;
},
class GroupsSelfListRequest {
constructor() {}
get google() {
return google;
},
set google(val) {
google = val;
},
build_() {
return { groupsSelfList: {} };
}
get email() {
return email;
},
set email(val) {
email = val;
},
build_
};
}
class GroupUsersListRequest {
constructor(groupId) {
this.groupId = groupId;
}
build_() {
return { groupUsersList: { groupId: this.groupId } };
}
function MatchResponse(message) {
return message.match;
}
class GroupsJoinRequest {
constructor() {
// this is a list of groupIds.
this.groups = [];
function MatchCreateRequest() {
function build_() {
return {
matchCreate: {}
};
}
build_() {
return { groupsJoin: { groupIds: this.groups } };
}
return {
build_,
processResponse_: MatchResponse
};
}
class GroupsLeaveRequest {
constructor() {
// this is a list of groupIds.
this.groups = [];
}
build_() {
return { groupsLeave: { groupIds: this.groups } };
}
function MatchDataResponse(message) {
message.matchData.data = JSON.parse(base64.decode(message.matchData.data));
return message.matchData;
}
class GroupUsersAddRequest {
constructor() {
this.adds = [];
function MatchDataSendRequest({
matchId,
presences,
opCode,
data
} = {}) {
function build_() {
return {
matchDataSend: {
matchId,
presences,
opCode,
data: base64.encode(JSON.stringify(data))
}
};
}
add(groupId, userId) {
this.adds.push({ groupId: groupId, userId: userId });
}
return {
get matchId() {
return matchId;
},
set matchId(val) {
matchId = val;
},
build_() {
var msg = { groupUsersAdd: { groupUsers: [] } };
this.adds.forEach(function (add) {
msg.groupUsersAdd.groupUsers.push({
groupId: add.groupId,
userId: add.userId
});
});
return msg;
}
}
get presences() {
return presences;
},
set presences(val) {
presences = val;
},
class GroupUsersKickRequest {
constructor() {
this.kicks = [];
}
get opCode() {
return opCode;
},
set opCode(val) {
opCode = val;
},
kick(groupId, userId) {
this.kicks.push({ groupId: groupId, userId: userId });
}
get data() {
return data;
},
set data(val) {
data = val;
},
build_() {
var msg = { groupUsersKick: { groupUsers: [] } };
this.kicks.forEach(function (kick) {
msg.groupUsersKick.groupUsers.push({
groupId: kick.groupId,
userId: kick.userId
});
});
return msg;
}
build_,
processResponse_: MatchDataResponse
};
}
class GroupUsersPromoteRequest {
constructor() {
this.promotes = [];
}
function MatchesResponse(message) {
return message.matches;
}
promote(groupId, userId) {
this.promotes.push({ groupId: groupId, userId: userId });
function MatchesJoinRequest({
matchIds = [],
tokens = []
} = {}) {
function build_() {
return {
matchesJoin: {
matches: [...matchIds.map(matchId => ({ matchId })), ...tokens.map(token => ({ token }))]
}
};
}
build_() {
var msg = { groupUsersPromote: { groupUsers: [] } };
this.promotes.forEach(function (promote) {
msg.groupUsersPromote.groupUsers.push({
groupId: promote.groupId,
userId: promote.userId
});
});
return msg;
}
}
return {
get matchIds() {
return matchIds;
},
set matchIds(val) {
matchIds = val;
},
class NotificationsListRequest {
constructor() {
this.limit = null;
this.resumableCursor = null;
}
get tokens() {
return tokens;
},
set tokens(val) {
tokens = val;
},
build_() {
return { notificationsList: {
limit: this.limit ? this.limit : 10,
resumableCursor: this.resumableCursor
} };
}
build_,
processResponse_: MatchesResponse
};
}
class NotificationsRemoveRequest {
constructor() {
// this is a list of notificationIds.
this.notifications = [];
function MatchesLeaveRequest({
matchIds = []
} = {}) {
function build_() {
return {
matchesLeave: {
matchIds
}
};
}
build_() {
return { notificationsRemove: { notificationIds: this.notifications } };
}
return {
get matchIds() {
return matchIds;
},
set matchIds(val) {
matchIds = val;
},
build_
};
}
class RpcRequest {
constructor() {
this.id = null;
this.payload = null;
}
build_() {
return { rpc: {
id: this.id,
payload: this.payload ? JSON.stringify(this.payload) : null
} };
}
function MatchmakeTicketResponse(message) {
return message.matchmakeTicket;
}
class MatchmakeAddRequest {
constructor(requiredCount) {
this.requiredCount = requiredCount;
this.filters = [];
this.properties = [];
}
function MatchmakeAddRequest(requiredCount) {
let filters = [];
let properties = [];
addTermFilter(name, termSet, matchAllTerms) {
this.filters.push({
name: name,
const self = {
get requiredCount() {
return requiredCount;
},
set requiredCount(val) {
requiredCount = val;
},
get filters() {
return filters;
},
set filters(val) {
filters = val;
},
get properties() {
return properties;
},
set properties(val) {
properties = val;
},
addTermFilter,
addRangeFilter,
addCheckFilter,
addStringSetProperty,
addIntegerProperty,
addBooleanProperty,
build_,
processResponse_: MatchmakeTicketResponse
};
return self;
function addTermFilter(name, termSet, matchAllTerms) {
filters.push({
name,
term: {
terms: termSet,
matchAllTerms: matchAllTerms
matchAllTerms
}
});
return this;
return self;
}
addRangeFilter(name, lowerbound, upperbound) {
this.filters.push({
name: name,
function addRangeFilter(name, lowerbound, upperbound) {
filters.push({
name,
range: {
lowerBound: lowerbound,
upperBound: upperbound
lowerBound,
upperBound
}
});
return this;
return self;
}
addCheckFilter(name, value) {
this.filters.push({
name: name,
function addCheckFilter(name, value) {
filters.push({
name,
check: value
});
return this;
return self;
}
addStringSetProperty(key, termSet) {
this.properties.push({
key: key,
function addStringSetProperty(key, termSet) {
properties.push({
key,
stringSet: termSet
});
return this;
return self;
}
addIntegerProperty(key, integerValue) {
this.properties.push({
key: key,
function addIntegerProperty(key, integerValue) {
properties.push({
key,
intValue: integerValue
});
return this;
return self;
}
addBooleanProperty(key, boolValue) {
this.properties.push({
key: key,
boolValue: boolValue
function addBooleanProperty(key, boolValue) {
properties.push({
key,
boolValue
});
return this;
return self;
}
build_() {
function build_() {
return {
matchmakeAdd: {
requiredCount: this.requiredCount,
filters: this.filters,
properties: this.properties
requiredCount,
filters,
properties
}

@@ -1336,214 +2035,867 @@ };

class MatchmakeRemoveRequest {
constructor(ticket) {
this.ticket = ticket;
function MatchmakeRemoveRequest(ticket) {
function build_() {
return {
matchmakeRemove: {
ticket
}
};
}
build_() {
return { matchmakeRemove: { ticket: this.ticket } };
}
return {
get ticket() {
return ticket;
},
set ticket(val) {
ticket = val;
},
build_
};
}
class MatchCreateRequest {
constructor() {}
function NotificationsResponse(message) {
const {
notifications: {
notifications = []
}
} = message;
build_() {
notifications.forEach(function (notification) {
notification.content = JSON.parse(notification.content);
});
return message.notifications;
}
function NotificationsListRequest({
limit,
resumableCursor
} = {}) {
function build_() {
return {
matchCreate: {}
notificationsList: {
limit: limit ? limit : 10,
resumableCursor
}
};
}
return {
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get resumableCursor() {
return resumableCursor;
},
set resumableCursor(val) {
resumableCursor = val;
},
build_,
processResponse_: NotificationsResponse
};
}
class MatchesJoinRequest {
constructor() {
this.matchIds = [];
this.tokens = [];
function NotificationsRemoveRequest({
notifications = []
} = {}) {
function build_() {
return {
notificationsRemove: {
notificationIds: notifications
}
};
}
build_() {
var msg = {
matchesJoin: { matches: [] }
return {
get notifications() {
return notifications;
},
set notifications(val) {
notifications = val;
},
build_
};
}
function RpcResponse(message) {
let {
rpc: {
id,
payload
}
} = message;
payload = payload ? JSON.parse(payload) : null;
return {
id,
payload
};
}
function RpcRequest({
id,
payload
} = {}) {
function build_() {
return {
rpc: {
id,
payload: payload ? JSON.stringify(payload) : null
}
};
}
this.matchIds.forEach(function (id) {
msg.matchesJoin.matches.push({ matchId: id });
});
return {
get id() {
return id;
},
set id(val) {
id = val;
},
this.tokens.forEach(function (token) {
msg.matchesJoin.matches.push({ token: token });
});
get payload() {
return payload;
},
set payload(val) {
payload = val;
},
return msg;
}
build_,
processResponse_: RpcResponse
};
}
class MatchesLeaveRequest {
constructor() {
this.matchIds = [];
function SelfResponse(message) {
return message.self;
}
function SelfFetchRequest() {
function build_() {
return {
selfFetch: {}
};
}
build_() {
return {
build_,
processResponse_: SelfResponse
};
}
function SelfUpdateRequest({
handle,
fullname,
timezone,
location,
lang,
avatarUrl,
metadata = {}
} = {}) {
function build_() {
return {
matchesLeave: {
matchIds: this.matchIds
selfUpdate: {
handle,
fullname,
timezone,
location,
lang,
avatarUrl,
metadata: JSON.stringify(metadata)
}
};
}
return {
get handle() {
return handle;
},
set handle(val) {
handle = val;
},
get fullname() {
return fullname;
},
set fullname(val) {
fullname = val;
},
get timezone() {
return timezone;
},
set timezone(val) {
timezone = val;
},
get location() {
return location;
},
set location(val) {
location = val;
},
get lang() {
return lang;
},
set lang(val) {
lang = val;
},
get metadata() {
return metadata;
},
set metadata(val) {
metadata = val;
},
get avatarUrl() {
return avatarUrl;
},
set avatarUrl(val) {
avatarUrl = val;
},
build_
};
}
class MatchDataSendRequest {
constructor() {
this.matchId = null;
this.presence = null; //UserPresence
this.opCode = 0;
this.data = null;
function StorageDataResponse(message) {
return message.storageData;
}
function StorageFetchRequest({
keys = []
} = {}) {
const self = {
get keys() {
return keys;
},
set keys(val) {
keys = val;
},
fetch,
build_,
processResponse_: StorageDataResponse
};
return self;
function build_() {
return {
storageFetch: {
keys
}
};
}
build_() {
function fetch(bucket, collection, record, userId) {
keys.push({
bucket,
collection,
record,
userId
});
return self;
}
}
function StorageListRequest({
userId,
bucket,
collection,
limit,
cursor
} = {}) {
function build_() {
return {
matchDataSend: {
matchId: matchId,
presence: presence,
opCode: opCode,
data: base64.encode(JSON.stringify(data))
storageList: {
userId,
bucket,
collection,
limit,
cursor
}
};
}
return {
get userId() {
return userId;
},
set userId(val) {
userId = val;
},
get bucket() {
return bucket;
},
set bucket(val) {
bucket = val;
},
get collection() {
return collection;
},
set collection(val) {
collection = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get cursor() {
return cursor;
},
set cursor(val) {
limit = val;
},
build_,
processResponse_: StorageDataResponse
};
}
class LeaderboardsListRequest {
constructor() {
this.filterLeaderboardIds = [];
this.limit = null;
this.cursor = null;
function StorageRemoveRequest({
keys = []
} = {}) {
const self = {
get keys() {
return keys;
},
set keys(val) {
keys = val;
},
remove,
build_
};
return self;
function build_() {
return {
storageRemove: {
keys
}
};
}
build_() {
var msg = { leaderboardsList: {
filterLeaderboardId: [],
limit: this.limit,
cursor: this.cursor
} };
function remove(bucket, collection, record, userId) {
keys.push({
bucket,
collection,
record,
userId
});
this.filterLeaderboardIds.forEach(function (id) {
msg.leaderboardsList.filterLeaderboardId.push(id);
});
return msg;
return self;
}
}
class LeaderboardRecordsFetchRequest {
constructor() {
this.leaderboardIds = [];
this.limit = null;
this.cursor = null;
function StorageKeysResponse(message) {
return message.storageKeys;
}
function StorageUpdateRequest({
updates = []
} = {}) {
const self = {
get updates() {
return updates;
},
set updates(val) {
updates = val;
},
update,
build_,
processResponse_: StorageKeysResponse
};
return self;
function build_() {
return {
storageUpdate: {
updates
}
};
}
build_() {
var msg = { leaderboardRecordsFetch: {
leaderboardIds: [],
limit: this.limit,
cursor: this.cursor
} };
// storageOps variable must be an array
function update(bucket, collection, record, storageOps = [], permissionRead = 1, permissionWrite = 1, version) {
updates.push({
key: {
bucket,
collection,
record,
version
},
permissionRead,
permissionWrite,
ops: storageOps
});
}
}
this.leaderboardIds.forEach(function (id) {
msg.leaderboardRecordsFetch.leaderboardIds.push(id);
Object.assign(StorageUpdateRequest, {
add,
append,
copy,
incr,
init,
merge,
move,
remove,
replace,
test,
compare
});
function add(path, value) {
return {
op: 0,
path,
value: JSON.stringify(value)
};
}
function append(path, value) {
return {
op: 1,
path,
value: JSON.stringify(value)
};
}
function copy(path, from) {
return {
op: 2,
path,
from
};
}
function incr(path, value) {
return {
op: 3,
path,
value: JSON.stringify(value)
};
}
function init(path, value) {
return {
op: 4,
path,
value: JSON.stringify(value)
};
}
function merge(path, from) {
return {
op: 5,
path,
from
};
}
function move(path, from) {
return {
op: 6,
path,
from
};
}
function remove(path) {
return {
op: 8,
path
};
}
function replace(path, value) {
return {
op: 9,
path,
value: JSON.string(value)
};
}
function test(path, value) {
return {
op: 10,
path,
value: JSON.stringify(value)
};
}
function compare(path, value, assertValue) {
return {
op: 11,
path,
value,
assert
};
}
function StorageWriteRequest({
data = []
} = {}) {
const self = {
get data() {
return data;
},
set data(val) {
data = val;
},
write,
build_,
processResponse_: StorageKeysResponse
};
return self;
function write(bucket, collection, record, value, permissionRead = 1, permissionWrite = 1, version) {
data.push({
bucket,
collection,
record,
value: value ? JSON.stringify(value) : '{}',
version,
permissionRead,
permissionWrite
});
return msg;
return self;
}
function build_() {
return {
storageWrite: {
data
}
};
}
}
class LeaderboardRecordsListRequest {
constructor() {
this.leaderboardId = null;
this.limit = null;
this.cursor = null;
function TopicMessageAckResponse(message) {
return message.topicMessageAck;
}
// only set one of the followings
this.lang = null;
this.location = null;
this.timezone = null;
this.ownerId = null;
this.ownerIds = [];
function TopicMessageSendRequest({
topic,
data
} = {}) {
function build_() {
return {
topicMessageSend: {
topic,
data: JSON.stringify(data)
}
};
}
build_() {
var msg = { leaderboardRecordsList: {
leaderboardId: this.leaderboardId,
limit: this.limit,
cursor: this.cursor
} };
return {
get topic() {
return topic;
},
set topic(val) {
topic = val;
},
if (this.lang) {
msg.leaderboardRecordsList.lang = this.lang;
} else if (this.location) {
msg.leaderboardRecordsList.location = this.createdAt;
} else if (this.timezone) {
msg.leaderboardRecordsList.count = this.count;
} else if (this.ownerId) {
msg.leaderboardRecordsList.ownerId = this.ownerId;
} else if (this.ownerIds.length > 0) {
msg.leaderboardRecordsList.ownerIds = { ownerIds: this.ownerIds };
get data() {
return data;
},
set data(val) {
data = val;
},
build_,
processResponse_: TopicMessageAckResponse
};
}
function TopicMessagesResponse(message) {
const {
topicMessages: {
messages = []
}
} = message;
messages.forEach(message => {
message.data = JSON.parse(message.data);
});
return message.topicMessages;
}
function TopicMessagesListRequest({
cursor,
forward, // boolean
limit, // number <= 100
// set only one of the followings
userId,
room,
groupId
} = {}) {
function build_() {
const msg = {
topicMessagesList: {
cursor,
forward,
limit
}
};
if (userId) {
msg.topicMessagesList.userId = userId;
} else if (room) {
msg.topicMessagesList.room = room;
} else if (groupId) {
msg.topicMessagesList.groupId = groupId;
}
return msg;
}
return {
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
get forward() {
return forward;
},
set forward(val) {
forward = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get userId() {
return userId;
},
set userId(val) {
userId = val;
},
get room() {
return room;
},
set room(val) {
room = val;
},
get groupId() {
return groupId;
},
set groupId(val) {
groupId = val;
},
build_,
processResponse_: TopicMessagesResponse
};
}
class LeaderboardRecordWriteRequest {
constructor() {
this.records = [];
function TopicsResponse(message) {
return message.topics;
}
function TopicsJoinRequest({
// NOTE: The server only processes the first item of the list,
// and will ignore and logs a warning message for other items.
topics = []
} = {}) {
const self = {
get topics() {
return topics;
},
set topics(val) {
topics = val;
},
dm,
group,
room,
build_,
processResponse_: TopicsResponse
};
return self;
function dm(userId) {
topics.push({ userId });
return self;
}
set(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
"set": value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
};
function group(groupId) {
topics.push({ groupId });
return self;
}
this.records.push(record);
function room(room) {
topics.push({ room });
return self;
}
best(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
best: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
function build_() {
return {
topicsJoin: {
joins: topics
}
};
this.records.push(record);
}
}
decrement(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
decr: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
function TopicsLeaveRequest({
// NOTE: The server only processes the first item of the list,
// and will ignore and logs a warning message for other items.
topics = []
} = {}) {
function build_() {
return {
topicsLeave: {
topics
}
};
}
this.records.push(record);
return {
get topics() {
return topics;
},
set topics(val) {
topics = val;
},
build_
};
}
function UnlinkRequest({
custom,
device,
facebook,
google,
email
} = {}) {
function build_() {
if (custom) return { link: { custom } };
if (device) return { link: { device } };
if (facebook) return { link: { facebook } };
if (google) return { link: { google } };
if (email) return { link: { email } };
}
increment(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
incr: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
return {
get custom() {
return custom;
},
set custom(val) {
custom = val;
},
get device() {
return device;
},
set device(val) {
device = val;
},
get facebook() {
return facebook;
},
set facebook(val) {
facebook = val;
},
get google() {
return google;
},
set google(val) {
google = val;
},
get email() {
return email;
},
set email(val) {
email = val;
},
build_
};
}
function UsersResponse(message) {
const {
users: {
users = []
}
} = message;
users.forEach(user => {
user.metadata = JSON.parse(user.metadata);
});
return users;
}
function UsersFetchRequest({
userIds = [],
handles = []
} = {}) {
function build_() {
return {
usersFetch: {
users: [...userIds.map(userId => ({ userId })), ...handles.map(handle => ({ handle }))]
}
};
this.records.push(record);
}
build_() {
return { leaderboardRecordsWrite: { records: this.records } };
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
get handles() {
return handles;
},
set handles(val) {
handles = val;
},
build_,
processResponse_: UsersResponse
};
}

@@ -1571,2 +2923,4 @@

export { AuthenticateRequest, Client, Session, LinkRequest, UnlinkRequest, SelfFetchRequest, SelfUpdateRequest, UsersFetchRequest, StorageListRequest, StorageFetchRequest, StorageWriteRequest, StorageRemoveRequest, StorageUpdateRequest, FriendsAddRequest, FriendsRemoveRequest, FriendsBlockRequest, FriendsListRequest, TopicsJoinRequest, TopicsLeaveRequest, TopicMessageSendRequest, TopicMessagesListRequest, GroupsCreateRequest, GroupsUpdateRequest, GroupsRemoveRequest, GroupsFetchRequest, GroupsListRequest, GroupsSelfListRequest, GroupUsersListRequest, GroupsJoinRequest, GroupsLeaveRequest, GroupUsersAddRequest, GroupUsersKickRequest, GroupUsersPromoteRequest, NotificationsListRequest, NotificationsRemoveRequest, RpcRequest, MatchmakeAddRequest, MatchmakeRemoveRequest, MatchCreateRequest, MatchesJoinRequest, MatchesLeaveRequest, MatchDataSendRequest, LeaderboardsListRequest, LeaderboardRecordsFetchRequest, LeaderboardRecordsListRequest, LeaderboardRecordWriteRequest };
// include fetch polyfill
export { Client, Session, AuthenticateRequest, FriendsAddRequest, FriendsBlockRequest, FriendsListRequest, FriendsRemoveRequest, GroupsCreateRequest, GroupsFetchRequest, GroupsJoinRequest, GroupsLeaveRequest, GroupsListRequest, GroupsRemoveRequest, GroupsSelfListRequest, GroupsUpdateRequest, GroupUsersAddRequest, GroupUsersKickRequest, GroupUsersListRequest, GroupUsersPromoteRequest, LeaderboardRecordsFetchRequest, LeaderboardRecordsListRequest, LeaderboardRecordWriteRequest, LeaderboardsListRequest, LinkRequest, MatchCreateRequest, MatchDataSendRequest, MatchesJoinRequest, MatchesLeaveRequest, MatchmakeAddRequest, MatchmakeRemoveRequest, NotificationsListRequest, NotificationsRemoveRequest, RpcRequest, SelfFetchRequest, SelfUpdateRequest, StorageFetchRequest, StorageListRequest, StorageRemoveRequest, StorageUpdateRequest, StorageWriteRequest, TopicMessageSendRequest, TopicMessagesListRequest, TopicsJoinRequest, TopicsLeaveRequest, UnlinkRequest, UsersFetchRequest };

@@ -7,2 +7,475 @@ (function (global, factory) {

(function(self) {
'use strict';
if (self.fetch) {
return
}
var support = {
searchParams: 'URLSearchParams' in self,
iterable: 'Symbol' in self && 'iterator' in Symbol,
blob: 'FileReader' in self && 'Blob' in self && (function() {
try {
new Blob();
return true
} catch(e) {
return false
}
})(),
formData: 'FormData' in self,
arrayBuffer: 'ArrayBuffer' in self
};
if (support.arrayBuffer) {
var viewClasses = [
'[object Int8Array]',
'[object Uint8Array]',
'[object Uint8ClampedArray]',
'[object Int16Array]',
'[object Uint16Array]',
'[object Int32Array]',
'[object Uint32Array]',
'[object Float32Array]',
'[object Float64Array]'
];
var isDataView = function(obj) {
return obj && DataView.prototype.isPrototypeOf(obj)
};
var isArrayBufferView = ArrayBuffer.isView || function(obj) {
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
};
}
function normalizeName(name) {
if (typeof name !== 'string') {
name = String(name);
}
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
throw new TypeError('Invalid character in header field name')
}
return name.toLowerCase()
}
function normalizeValue(value) {
if (typeof value !== 'string') {
value = String(value);
}
return value
}
// Build a destructive iterator for the value list
function iteratorFor(items) {
var iterator = {
next: function() {
var value = items.shift();
return {done: value === undefined, value: value}
}
};
if (support.iterable) {
iterator[Symbol.iterator] = function() {
return iterator
};
}
return iterator
}
function Headers(headers) {
this.map = {};
if (headers instanceof Headers) {
headers.forEach(function(value, name) {
this.append(name, value);
}, this);
} else if (Array.isArray(headers)) {
headers.forEach(function(header) {
this.append(header[0], header[1]);
}, this);
} else if (headers) {
Object.getOwnPropertyNames(headers).forEach(function(name) {
this.append(name, headers[name]);
}, this);
}
}
Headers.prototype.append = function(name, value) {
name = normalizeName(name);
value = normalizeValue(value);
var oldValue = this.map[name];
this.map[name] = oldValue ? oldValue+','+value : value;
};
Headers.prototype['delete'] = function(name) {
delete this.map[normalizeName(name)];
};
Headers.prototype.get = function(name) {
name = normalizeName(name);
return this.has(name) ? this.map[name] : null
};
Headers.prototype.has = function(name) {
return this.map.hasOwnProperty(normalizeName(name))
};
Headers.prototype.set = function(name, value) {
this.map[normalizeName(name)] = normalizeValue(value);
};
Headers.prototype.forEach = function(callback, thisArg) {
for (var name in this.map) {
if (this.map.hasOwnProperty(name)) {
callback.call(thisArg, this.map[name], name, this);
}
}
};
Headers.prototype.keys = function() {
var items = [];
this.forEach(function(value, name) { items.push(name); });
return iteratorFor(items)
};
Headers.prototype.values = function() {
var items = [];
this.forEach(function(value) { items.push(value); });
return iteratorFor(items)
};
Headers.prototype.entries = function() {
var items = [];
this.forEach(function(value, name) { items.push([name, value]); });
return iteratorFor(items)
};
if (support.iterable) {
Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
}
function consumed(body) {
if (body.bodyUsed) {
return Promise.reject(new TypeError('Already read'))
}
body.bodyUsed = true;
}
function fileReaderReady(reader) {
return new Promise(function(resolve, reject) {
reader.onload = function() {
resolve(reader.result);
};
reader.onerror = function() {
reject(reader.error);
};
})
}
function readBlobAsArrayBuffer(blob) {
var reader = new FileReader();
var promise = fileReaderReady(reader);
reader.readAsArrayBuffer(blob);
return promise
}
function readBlobAsText(blob) {
var reader = new FileReader();
var promise = fileReaderReady(reader);
reader.readAsText(blob);
return promise
}
function readArrayBufferAsText(buf) {
var view = new Uint8Array(buf);
var chars = new Array(view.length);
for (var i = 0; i < view.length; i++) {
chars[i] = String.fromCharCode(view[i]);
}
return chars.join('')
}
function bufferClone(buf) {
if (buf.slice) {
return buf.slice(0)
} else {
var view = new Uint8Array(buf.byteLength);
view.set(new Uint8Array(buf));
return view.buffer
}
}
function Body() {
this.bodyUsed = false;
this._initBody = function(body) {
this._bodyInit = body;
if (!body) {
this._bodyText = '';
} else if (typeof body === 'string') {
this._bodyText = body;
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body;
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body;
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this._bodyText = body.toString();
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
this._bodyArrayBuffer = bufferClone(body.buffer);
// IE 10-11 can't handle a DataView body.
this._bodyInit = new Blob([this._bodyArrayBuffer]);
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
this._bodyArrayBuffer = bufferClone(body);
} else {
throw new Error('unsupported BodyInit type')
}
if (!this.headers.get('content-type')) {
if (typeof body === 'string') {
this.headers.set('content-type', 'text/plain;charset=UTF-8');
} else if (this._bodyBlob && this._bodyBlob.type) {
this.headers.set('content-type', this._bodyBlob.type);
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
}
}
};
if (support.blob) {
this.blob = function() {
var rejected = consumed(this);
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return Promise.resolve(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
return Promise.resolve(new Blob([this._bodyArrayBuffer]))
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as blob')
} else {
return Promise.resolve(new Blob([this._bodyText]))
}
};
this.arrayBuffer = function() {
if (this._bodyArrayBuffer) {
return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
} else {
return this.blob().then(readBlobAsArrayBuffer)
}
};
}
this.text = function() {
var rejected = consumed(this);
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return readBlobAsText(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as text')
} else {
return Promise.resolve(this._bodyText)
}
};
if (support.formData) {
this.formData = function() {
return this.text().then(decode)
};
}
this.json = function() {
return this.text().then(JSON.parse)
};
return this
}
// HTTP methods whose capitalization should be normalized
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
function normalizeMethod(method) {
var upcased = method.toUpperCase();
return (methods.indexOf(upcased) > -1) ? upcased : method
}
function Request(input, options) {
options = options || {};
var body = options.body;
if (input instanceof Request) {
if (input.bodyUsed) {
throw new TypeError('Already read')
}
this.url = input.url;
this.credentials = input.credentials;
if (!options.headers) {
this.headers = new Headers(input.headers);
}
this.method = input.method;
this.mode = input.mode;
if (!body && input._bodyInit != null) {
body = input._bodyInit;
input.bodyUsed = true;
}
} else {
this.url = String(input);
}
this.credentials = options.credentials || this.credentials || 'omit';
if (options.headers || !this.headers) {
this.headers = new Headers(options.headers);
}
this.method = normalizeMethod(options.method || this.method || 'GET');
this.mode = options.mode || this.mode || null;
this.referrer = null;
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
throw new TypeError('Body not allowed for GET or HEAD requests')
}
this._initBody(body);
}
Request.prototype.clone = function() {
return new Request(this, { body: this._bodyInit })
};
function decode(body) {
var form = new FormData();
body.trim().split('&').forEach(function(bytes) {
if (bytes) {
var split = bytes.split('=');
var name = split.shift().replace(/\+/g, ' ');
var value = split.join('=').replace(/\+/g, ' ');
form.append(decodeURIComponent(name), decodeURIComponent(value));
}
});
return form
}
function parseHeaders(rawHeaders) {
var headers = new Headers();
rawHeaders.split(/\r?\n/).forEach(function(line) {
var parts = line.split(':');
var key = parts.shift().trim();
if (key) {
var value = parts.join(':').trim();
headers.append(key, value);
}
});
return headers
}
Body.call(Request.prototype);
function Response(bodyInit, options) {
if (!options) {
options = {};
}
this.type = 'default';
this.status = 'status' in options ? options.status : 200;
this.ok = this.status >= 200 && this.status < 300;
this.statusText = 'statusText' in options ? options.statusText : 'OK';
this.headers = new Headers(options.headers);
this.url = options.url || '';
this._initBody(bodyInit);
}
Body.call(Response.prototype);
Response.prototype.clone = function() {
return new Response(this._bodyInit, {
status: this.status,
statusText: this.statusText,
headers: new Headers(this.headers),
url: this.url
})
};
Response.error = function() {
var response = new Response(null, {status: 0, statusText: ''});
response.type = 'error';
return response
};
var redirectStatuses = [301, 302, 303, 307, 308];
Response.redirect = function(url, status) {
if (redirectStatuses.indexOf(status) === -1) {
throw new RangeError('Invalid status code')
}
return new Response(null, {status: status, headers: {location: url}})
};
self.Headers = Headers;
self.Request = Request;
self.Response = Response;
self.fetch = function(input, init) {
return new Promise(function(resolve, reject) {
var request = new Request(input, init);
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var options = {
status: xhr.status,
statusText: xhr.statusText,
headers: parseHeaders(xhr.getAllResponseHeaders() || '')
};
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
var body = 'response' in xhr ? xhr.response : xhr.responseText;
resolve(new Response(body, options));
};
xhr.onerror = function() {
reject(new TypeError('Network request failed'));
};
xhr.ontimeout = function() {
reject(new TypeError('Network request failed'));
};
xhr.open(request.method, request.url, true);
if (request.credentials === 'include') {
xhr.withCredentials = true;
}
if ('responseType' in xhr && support.blob) {
xhr.responseType = 'blob';
}
request.headers.forEach(function(value, name) {
xhr.setRequestHeader(name, value);
});
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
})
};
self.fetch.polyfill = true;
})(typeof self !== 'undefined' ? self : window);
/**
* Build a string which looks like a UUIDv4 type.
*/
const uuidv4 = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, character => {
const randomNumber = Math.random() * 16 | 0,
result = character === 'x' ? randomNumber : randomNumber & 0x3 | 0x8;
return result.toString(16);
});
};
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

@@ -185,73 +658,37 @@

/*
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class Session {
constructor(createdAt, expiresAt, handle, id, token) {
this.token_ = token;
const VERSION = '0.1.0';
const DEFAULT_SERVER_KEY = 'defaultkey';
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = '7350';
/**
* Build a string which looks like a UUIDv4 type.
*/
const uuidv4 = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, character => {
const randomNumber = Math.random() * 16 | 0,
result = character === 'x' ? randomNumber : randomNumber & 0x3 | 0x8;
return result.toString(16);
});
};
class AuthenticateRequest {
constructor(message) {
this.message_ = message;
this.createdAt = createdAt;
this.expiresAt = expiresAt;
this.handle = handle;
this.id = id;
}
static custom(id) {
return new AuthenticateRequest({
custom: id
});
/**
* @param {number} currentime The current system time in milliseconds.
* @returns {bool} True if the session has expired.
*/
isexpired(currenttime) {
return this.expiresAt - currenttime < 0;
}
static device(id) {
return new AuthenticateRequest({
device: id
});
}
static restore(jwt) {
const parts = jwt.split('.');
if (parts.length != 3) {
throw 'jwt is not valid.';
}
const decoded = JSON.parse(base64.decode(parts[1]));
const expiresAt = Math.floor(parseInt(decoded['exp']) * 1000);
static email(email, password) {
return new AuthenticateRequest({
email: {
email: email,
password: password
}
});
return new Session(Date.now(), expiresAt, decoded['han'], decoded['uid'], jwt);
}
}
static facebook(oauthToken) {
return new AuthenticateRequest({
facebook: oauthToken
});
}
const VERSION = '0.1.0';
const DEFAULT_SERVER_KEY = 'defaultkey';
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = '7350';
static google(oauthToken) {
return new AuthenticateRequest({
google: oauthToken
});
}
}
class Client {

@@ -361,74 +798,4 @@ constructor(serverkey = DEFAULT_SERVER_KEY, host = DEFAULT_HOST, port = DEFAULT_PORT, lang = 'en', ssl = false, verbose = false) {

p.reject(message.error);
} else if (message.self) {
p.resolve(message.self);
} else if (message.users) {
message.users.users.forEach(function (user) {
user.metadata = JSON.parse(user.metadata);
});
p.resolve(message.users.users);
} else if (message.storageData) {
p.resolve(message.storageData);
} else if (message.storageKeys) {
p.resolve(message.storageKeys);
} else if (message.friends) {
message.friends.friends.forEach(function (friend) {
friend.user.metadata = JSON.parse(friend.user.metadata);
});
p.resolve(message.friends);
} else if (message.topics) {
p.resolve(message.topics);
} else if (message.topicMessageAck) {
p.resolve(message.topicMessageAck);
} else if (message.topicMessages) {
message.topicMessages.messages.forEach(function (message) {
message.data = JSON.parse(message.data);
});
p.resolve(message.topicMessages);
} else if (message.groups) {
message.groups.groups.forEach(function (group) {
group.metadata = JSON.parse(group.metadata);
});
p.resolve(message.groups);
} else if (message.groupsSelf) {
message.groupsSelf.groupsSelf.forEach(function (groupSelf) {
groupSelf.group.metadata = JSON.parse(groupSelf.group.metadata);
});
p.resolve(message.groupsSelf);
} else if (message.groupUsers) {
message.groupUsers.users.forEach(function (groupUser) {
groupUser.user.metadata = JSON.parse(groupUser.user.metadata);
});
p.resolve(message.groupUsers);
} else if (message.rpc) {
message.rpc.payload = message.rpc.payload ? JSON.parse(message.rpc.payload) : null;
p.resolve({ id: message.rpc.id, payload: message.rpc.payload });
} else if (message.notifications) {
message.notifications.notifications.forEach(function (notification) {
notification.content = JSON.parse(notification.content);
});
p.resolve(message.notifications);
} else if (message.matchmakeTicket) {
p.resolve(message.matchmakeTicket);
} else if (message.match) {
p.resolve(message.match);
} else if (message.matches) {
p.resolve(message.matches);
} else if (message.leaderboards) {
message.leaderboards.leaderboards.forEach(function (leaderboard) {
leaderboard.metadata = JSON.parse(leaderboard.metadata);
});
p.resolve(message.leaderboards);
} else if (message.leaderboardRecords) {
message.leaderboardRecords.records.forEach(function (record) {
record.metadata = JSON.parse(record.metadata);
});
p.resolve(message.leaderboardRecords);
} else {
// if the object has properties, other than the collationId, log a warning
if (window.console && Object.keys(message).length > 1) {
console.error("Unrecognized message received: %o", message);
p.resolve(message);
} else {
p.resolve();
}
p.resolve(message);
}

@@ -455,6 +822,8 @@ }

message.collationId = collationId;
return this.send_(message, collationId, request.constructor.name);
return this.send_(message, collationId).then(message => {
if (request.processResponse_) return request.processResponse_(message);
});
}
send_(message, collationId, requestName) {
send_(message, collationId) {
if (this.socket_ == null) {

@@ -475,3 +844,3 @@ return new Promise((resolve, reject) => {

if (this.verbose && window.console) {
console.log("%s: %o", requestName, message);
console.log("%o", message);
}

@@ -525,494 +894,655 @@

class Session {
constructor(createdAt, expiresAt, handle, id, token) {
this.token_ = token;
function AuthenticateRequest(message) {
return {
message_: message
};
}
this.createdAt = createdAt;
this.expiresAt = expiresAt;
this.handle = handle;
this.id = id;
}
Object.assign(AuthenticateRequest, {
custom,
device,
email,
facebook,
google
});
/**
* @param {number} currentime The current system time in milliseconds.
* @returns {bool} True if the session has expired.
*/
isexpired(currenttime) {
return this.expiresAt - currenttime < 0;
}
function custom(id) {
return new AuthenticateRequest({
custom: id
});
}
static restore(jwt) {
const parts = jwt.split('.');
if (parts.length != 3) {
throw 'jwt is not valid.';
function device(id) {
return new AuthenticateRequest({
device: id
});
}
function email(email, password) {
return new AuthenticateRequest({
email: {
email,
password
}
const decoded = JSON.parse(base64.decode(parts[1]));
const expiresAt = Math.floor(parseInt(decoded['exp']) * 1000);
});
}
return new Session(Date.now(), expiresAt, decoded['han'], decoded['uid'], jwt);
}
function facebook(oauthToken) {
return new AuthenticateRequest({
facebook: oauthToken
});
}
class LinkRequest {
constructor() {
// only set one of these fields
this.custom = null;
this.device = null;
this.facebook = null;
this.google = null;
this.email = {
email: "",
password: ""
function google(oauthToken) {
return new AuthenticateRequest({
google: oauthToken
});
}
function FriendsAddRequest({
userIds = [],
handles = []
} = {}) {
function build_() {
return {
friendsAdd: {
friends: [...userIds.map(userId => ({ userId })), ...handles.map(handle => ({ handle }))]
}
};
}
build_() {
if (this.custom) {
return { link: { custom: this.custom } };
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
if (this.device) {
return { link: { device: this.device } };
}
get handles() {
return handles;
},
set handles(val) {
handles = val;
},
if (this.facebook) {
return { link: { facebook: this.facebook } };
}
if (this.google) {
return { link: { google: this.google } };
}
if (this.email.email != "") {
return { link: { email: this.email } };
}
}
build_
};
}
class UnlinkRequest {
constructor() {
// only set one of these fields
this.custom = null;
this.device = null;
this.facebook = null;
this.google = null;
this.email = null;
function FriendsBlockRequest({
userIds = []
} = {}) {
function build_() {
return {
friendsBlock: {
userIds: userIds.map(userId => ({ userId }))
}
};
}
build_() {
if (this.custom) {
return { unlink: { custom: this.custom } };
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
if (this.device) {
return { unlink: { device: this.device } };
}
build_
};
}
if (this.facebook) {
return { unlink: { facebook: this.facebook } };
}
function FriendsResponse(message) {
const {
friends: {
friends = []
} = {}
} = message;
if (this.google) {
return { unlink: { google: this.google } };
}
friends.forEach(friend => {
friend.user.metadata = JSON.parse(friend.user.metadata);
});
if (this.email) {
return { unlink: { email: this.email } };
}
}
return message.friends;
}
class SelfFetchRequest {
constructor() {}
build_() {
function FriendsListRequest() {
function build_() {
return {
selfFetch: {}
friendsList: {}
};
}
return {
build_,
processResponse_: FriendsResponse
};
}
class SelfUpdateRequest {
constructor() {
this.handle = null;
this.fullname = null;
this.timezone = null;
this.location = null;
this.lang = null;
this.metadata = null;
this.avatarUrl = null;
}
build_() {
function FriendsRemoveRequest({
userIds = []
} = {}) {
function build_() {
return {
selfUpdate: {
handle: this.handle,
fullname: this.fullname,
timezone: this.timezone,
location: this.location,
lang: this.lang,
avatarUrl: this.avatarUrl,
metadata: this.metadata ? JSON.stringify(this.metadata) : "{}"
friendsRemove: {
userIds: userIds.map(userId => ({ userId }))
}
};
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
build_
};
}
class UsersFetchRequest {
constructor() {
// base64 user IDs
this.userIds = [];
this.handles = [];
}
function GroupsResponse(message) {
const {
groups: {
groups = []
} = {}
} = message;
build_() {
var msg = { usersFetch: { users: [] } };
this.userIds.forEach(function (id) {
msg.usersFetch.users.push({ userId: id });
});
this.handles.forEach(function (handle) {
msg.usersFetch.users.push({ handle: handle });
});
return msg;
}
groups.forEach(group => {
group.metadata = JSON.parse(group.metadata);
});
return message.groups;
}
class StorageListRequest {
constructor() {
// base64 user ID
this.userId = null;
this.bucket = null;
this.collection = null;
this.limit = null;
this.cursor = null;
function GroupsCreateRequest({
groups = []
} = {}) {
function create(name, description, avatarUrl, lang, metadata = {}, privateGroup) {
groups.push({
name,
description,
avatarUrl,
lang,
private: privateGroup,
metadata: JSON.stringify(metadata)
});
}
build_() {
function build_() {
return {
storageList: {
userId: this.userId,
bucket: this.bucket,
collection: this.collection,
limit: this.limit,
cursor: this.cursor
groupsCreate: {
groups
}
};
}
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
create,
build_,
processResponse_: GroupsResponse
};
}
class StorageFetchRequest {
constructor() {
this.keys = [];
function GroupsFetchRequest({
groupIds = [],
names = []
} = {}) {
function build_() {
return {
groupsFetch: {
groups: [...groupIds.map(groupId => ({ groupId })), ...names.map(name => ({ name }))]
}
};
}
fetch(bucket, collection, record, userId) {
this.keys.push({
bucket: bucket,
collection: collection,
record: record,
userId: userId
});
return this;
}
return {
get groupIds() {
return groupIds;
},
set groupIds(val) {
groupIds = val;
},
build_() {
return { storageFetch: { keys: this.keys } };
}
get names() {
return names;
},
set names(val) {
names = val;
},
build_,
processResponse_: GroupsResponse
};
}
class StorageWriteRequest {
constructor() {
this.data = [];
function GroupsJoinRequest({
groups = []
} = {}) {
function build_() {
return {
groupsJoin: {
groupIds: groups
}
};
}
write(bucket, collection, record, value, permissionRead = 1, permissionWrite = 1, version) {
this.data.push({
bucket: bucket,
collection: collection,
record: record,
value: value ? JSON.stringify(value) : "{}",
version: version ? version : null,
permissionRead: permissionRead,
permissionWrite: permissionWrite
});
return this;
}
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
build_() {
return { storageWrite: { data: this.data } };
}
build_
};
}
class StorageRemoveRequest {
constructor() {
this.keys = [];
function GroupsLeaveRequest({
groups = []
} = {}) {
function build_() {
return {
groupsLeave: {
groupIds: groups
}
};
}
remove(bucket, collection, record, userId) {
this.keys.push({
bucket: bucket,
collection: collection,
record: record,
userId: userId
});
return this;
}
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
build_() {
return { storageRemove: { keys: this.keys } };
}
build_
};
}
class StorageUpdateRequest {
constructor() {
this.updates = [];
}
function GroupsListRequest({
pageLimit,
orderByAsc,
cursor,
build_() {
return { storageUpdate: { updates: this.updates } };
}
// only set one of the followings
lang,
createdAt,
count
} = {}) {
function build_() {
const msg = {
groupsList: {
pageLimit,
orderByAsc,
cursor
}
};
/**
storageOps variable must be an array
*/
update(bucket, collection, record, storageOps = [], permissionRead = 1, permissionWrite = 1, version) {
this.updates.push({
key: {
bucket: bucket,
collection: collection,
record: record,
version: version ? version : null
},
permissionRead: permissionRead,
permissionWrite: permissionWrite,
ops: storageOps
});
return this;
}
if (lang) {
msg.groupsList.lang = lang;
} else if (createdAt) {
msg.groupsList.createdAt = createdAt;
} else if (count) {
msg.groupsList.count = count;
}
static add(path, value) {
return {
op: 0,
path: path,
value: JSON.stringify(value)
};
return msg;
}
static append(path, value) {
return {
op: 1,
path: path,
value: JSON.stringify(value)
};
}
return {
get pageLimit() {
return pageLimit;
},
set pageLimit(val) {
pageLimit = val;
},
static copy(path, from) {
return {
op: 2,
path: path,
from: from
};
}
get orderByAsc() {
return orderByAsc;
},
set orderByAsc(val) {
orderByAsc = val;
},
static incr(path, value) {
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
get lang() {
return lang;
},
set lang(val) {
lang = val;
},
get createdAt() {
return createdAt;
},
set createdAt(val) {
createdAt = val;
},
get count() {
return count;
},
set count(val) {
count = val;
},
build_,
processResponse_: GroupsResponse
};
}
function GroupsRemoveRequest({
groups = []
} = {}) {
function build_() {
return {
op: 3,
path: path,
value: JSON.stringify(value)
groupsRemove: {
groupIds: groups
}
};
}
static init(path, value) {
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
build_
};
}
function GroupsSelfResponse(message) {
const {
groupsSelf: {
groupsSelf = []
} = {}
} = message;
groupsSelf.forEach(groupSelf => {
groupSelf.group.metadata = JSON.parse(groupSelf.group.metadata);
});
return message.groupsSelf;
}
function GroupsSelfListRequest() {
function build_() {
return {
op: 4,
path: path,
value: JSON.stringify(value)
groupsSelfList: {}
};
}
static merge(path, from) {
return {
op: 5,
path: path,
from: from
};
return {
build_,
processResponse_: GroupsSelfResponse
};
}
function GroupsUpdateRequest({
groups = []
} = {}) {
function update(groupId, name, description, avatarUrl, lang, metadata = {}, privateGroup) {
groups.push({
groupId,
name,
description,
avatarUrl,
lang,
private: privateGroup,
metadata: JSON.string(metadata)
});
}
static move(path, from) {
function build_() {
return {
op: 6,
path: path,
from: from
groupsUpdate: {
groups
}
};
}
static remove(path) {
return {
op: 8,
path: path
};
return {
get groups() {
return groups;
},
set groups(val) {
groups = val;
},
update,
build_
};
}
function GroupUsersAddRequest({
adds = []
} = {}) {
function add(groupId, userId) {
adds.push({
groupId,
userID
});
}
static replace(path, value) {
function build_() {
return {
op: 9,
path: path,
value: JSON.stringify(value)
groupUsersAdd: {
groupUsers: adds
}
};
}
static test(path, value) {
return {
op: 10,
path: path,
value: JSON.stringify(value)
};
return {
get adds() {
return adds;
},
set add(val) {
adds = val;
},
add,
build_
};
}
function GroupUsersKickRequest({
kicks = []
} = {}) {
function kick(groupId, userId) {
kicks.push({ groupId, userID });
}
static compare(path, value, assertValue) {
function build_() {
return {
op: 11,
path: path,
value: JSON.stringify(value),
assert: assertValue
groupUsersKick: {
groupUsers: kicks
}
};
}
}
class FriendsAddRequest {
constructor() {
// base64 user IDs
this.userIds = [];
this.handles = [];
}
return {
get kicks() {
return kicks;
},
set kicks(val) {
kicks = val;
},
build_() {
var msg = { friendsAdd: { friends: [] } };
this.userIds.forEach(function (id) {
msg.friendsAdd.friends.push({ userId: id });
});
this.handles.forEach(function (handle) {
msg.friendsAdd.friends.push({ handle: handle });
});
return msg;
}
kick,
build_
};
}
class FriendsRemoveRequest {
constructor() {
// base64 user IDs
this.userIds = [];
}
function GroupUsersResponse(message) {
const {
groupUsers: {
users = []
}
} = message;
build_() {
var msg = { friendsRemove: { userIds: [] } };
this.userIds.forEach(function (id) {
msg.friendsRemove.userIds.push({ userId: id });
});
return msg;
}
users.forEach(groupUser => {
groupUser.user.metadata = JSON.parse(groupUser.user.metadata);
});
return message.groupUsers;
}
class FriendsBlockRequest {
constructor() {
// base64 user IDs
this.userIds = [];
function GroupUsersListRequest(groupId) {
function build_() {
return {
groupUsersList: {
groupId
}
};
}
build_() {
var msg = { friendsBlock: { userIds: [] } };
this.userIds.forEach(function (id) {
msg.friendsBlock.userIds.push({ userId: id });
});
return msg;
}
return {
get groupId() {
return groupId;
},
set groupId(val) {
groupId = val;
},
build_,
processResponse_: GroupUsersResponse
};
}
class FriendsListRequest {
constructor() {}
function GroupUsersPromoteRequest({
promotes = []
} = {}) {
function promote(groupId, userID) {
promotes.push({ groupId, userId });
}
build_() {
function build_() {
return {
friendsList: {}
groupUsersPromote: {
groupUsers: promote
}
};
}
}
class TopicsJoinRequest {
constructor() {
// NOTE: The server only processes the first item of the list, and will ignore and logs a warning message for other items.
this.topics = [];
}
return {
get promotes() {
return promotes;
},
set promotes(val) {
promotes = val;
},
dm(userId) {
this.topics.push({ userId: userId });
return this;
}
promote,
build_
};
}
group(groupId) {
this.topics.push({ groupId: groupId });
return this;
}
function LeaderboardRecordsResponse(message) {
const {
leaderboardRecords: {
records = []
}
} = message;
room(room) {
this.topics.push({ room: room });
return this;
}
records.forEach(record => {
record.metadata = JSON.parse(record.metadata);
});
build_() {
return { topicsJoin: { joins: this.topics } };
}
return message.leaderboardRecords;
}
class TopicsLeaveRequest {
constructor() {
// NOTE: The server only processes the first item of the list, and will ignore and logs a warning message for other items.
this.topics = []; // this is a list of topicIds.
function LeaderboardRecordsFetchRequest({
leaderboardIds = [],
limit,
cursor
} = {}) {
function build_() {
return {
leaderboardRecordsFetch: {
leaderboardIds,
limit,
cursor
}
};
}
build_() {
return { topicsLeave: { topics: this.topics } };
}
}
return {
get leaderboardIds() {
return leaderboardIds;
},
set leaderboardIds(val) {
leaderboardIds = val;
},
class TopicMessageSendRequest {
constructor() {
// this is the topicId.
this.topic = null;
this.data = null;
}
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
build_() {
return { topicMessageSend: {
topic: this.topic,
data: JSON.stringify(this.data)
} };
}
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
build_,
processResponse_: LeaderboardRecordsResponse
};
}
class TopicMessagesListRequest {
constructor() {
this.cursor = null;
this.forward = null; // boolean
this.limit = null; // number <= 100
function LeaderboardRecordsListRequest({
leaderboardId,
limit,
cursor,
// set only one of the followings
this.userId = null;
this.room = null;
this.groupId = null;
}
// only set one the following
lang,
location,
timezone,
ownerId,
ownerIds = []
} = {}) {
function build_() {
const msg = {
leaderboardRecordsList: {
leaderboardId,
limit,
cursor
}
};
build_() {
var msg = { topicMessagesList: {
cursor: this.cursor,
forward: this.forward,
limit: this.limit
} };
if (this.userId) {
msg.topicMessagesList.userId = this.userId;
} else if (this.room) {
msg.topicMessagesList.room = this.room;
} else if (this.groupId) {
msg.topicMessagesList.groupId = this.groupId;
if (lang) {
msg.leaderboardRecordsList.lang = lang;
} else if (location) {
msg.leaderboardRecordsList.location = location;
} else if (timezone) {
msg.leaderboardRecordsList.timezone = timezone;
} else if (ownerId) {
msg.leaderboardRecordsList.ownerId = ownerId;
} else if (ownerIds.length > 0) {
msg.leaderboardRecordsList.ownerIds = { ownerIds: ownerIds };
}

@@ -1022,317 +1552,486 @@

}
return {
get leaderboardId() {
return leaderboardId;
},
set leaderboardId(val) {
leaderboardId = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
get lang() {
return lang;
},
set lang(val) {
lang = val;
},
get location() {
return location;
},
set location(val) {
location = val;
},
get timezone() {
return timezone;
},
set timezone(val) {
timezone = val;
},
get ownerId() {
return ownerId;
},
set ownerId(val) {
ownerId = val;
},
get ownerIds() {
return ownerIds;
},
set ownerIds(val) {
ownerIds = val;
},
build_,
processResponse_: LeaderboardRecordsResponse
};
}
class GroupsCreateRequest {
constructor() {
this.groups = [];
function LeaderboardRecordWriteRequest({
records = []
} = {}) {
function set(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
set: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
});
}
create(name, description, avatarUrl, lang, metadata, privateGroup) {
this.groups.push({
name: name,
description: description,
avatarUrl: avatarUrl,
lang: lang,
"private": privateGroup,
metadata: metadata ? JSON.stringify(metadata) : "{}"
function best(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
best: value,
metadata: JSON.stringify(metadata),
location,
timezone
});
}
build_() {
return { groupsCreate: { groups: this.groups } };
function decrement(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
decr: value,
metadata: JSON.stringify(metadata),
location,
timezone
});
}
}
class GroupsUpdateRequest {
constructor() {
this.groups = [];
function increment(leaderboardId, value, metadata, location, timezone) {
records.push({
leaderboardId,
incr: value,
metadata: JSON.stringify(metadata),
location,
timezone
});
}
update(groupId, name, description, avatarUrl, lang, metadata, privateGroup) {
this.groups.push({
groupId: groupId,
name: name,
description: description,
avatarUrl: avatarUrl,
lang: lang,
"private": privateGroup,
metadata: metadata ? JSON.stringify(metadata) : "{}"
});
function build_() {
return {
leaderboardRecordsWrite: {
records
}
};
}
build_() {
return { groupsUpdate: { groups: this.groups } };
}
return {
get records() {
return records;
},
set records(val) {
records = val;
},
set,
best,
decrement,
increment,
build_,
processResponse_: LeaderboardRecordsResponse
};
}
class GroupsRemoveRequest {
constructor() {
// this is a list of groupIds.
this.groups = [];
}
function LeaderboardsResponse(message) {
const {
leaderboards: {
leaderboards = []
}
} = message;
build_() {
return { groupsRemove: { groupIds: this.groups } };
}
leaderboards.forEach(leaderboard => {
leaderboard.metadata = JSON.parse(leaderboard.metadata);
});
return message.leaderboards;
}
class GroupsFetchRequest {
constructor() {
// this is a list of groupIds.
this.groupIds = [];
this.names = [];
function LeaderboardsListRequest({
filterLeaderboardIds = [],
limit,
cursor
} = {}) {
function build_() {
return {
leaderboardsList: {
filterLeaderboardId: filterLeaderboardIds,
limit,
cursor
}
};
}
build_() {
var msg = { groupsFetch: { groups: [] } };
this.groupIds.forEach(function (id) {
msg.groupsFetch.groups.push({ groupId: id });
});
this.names.forEach(function (name) {
msg.groupsFetch.groups.push({ name: name });
});
return msg;
}
return {
get filterLeaderboardIds() {
return filterLeaderboardIds;
},
set filterLeaderboardIds(val) {
filterLeaderboardIds = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
build_,
processResponse_: LeaderboardsResponse
};
}
class GroupsListRequest {
constructor() {
this.pageLimit = null;
this.orderByAsc = null;
this.cursor = null;
// only set one of the followings
this.lang = null;
this.createdAt = null;
this.count = null;
function LinkRequest({
// only set one of these fields
custom,
device,
facebook,
google,
email = {
email: '',
password: ''
}
} = {}) {
function build_() {
if (custom) return { link: { custom } };
if (device) return { link: { device } };
if (facebook) return { link: { facebook } };
if (google) return { link: { google } };
if (email.email != '') return { link: { email } };
}
build_() {
var msg = { groupsList: {
pageLimit: this.pageLimit,
orderByAsc: this.orderByAsc,
cursor: this.cursor
} };
return {
get custom() {
return custom;
},
set custom(val) {
custom = val;
},
if (this.lang) {
msg.groupsList.lang = this.lang;
} else if (this.createdAt) {
msg.groupsList.createdAt = this.createdAt;
} else if (this.count) {
msg.groupsList.count = this.count;
}
get device() {
return device;
},
set device(val) {
device = val;
},
return msg;
}
}
get facebook() {
return facebook;
},
set facebook(val) {
facebook = val;
},
class GroupsSelfListRequest {
constructor() {}
get google() {
return google;
},
set google(val) {
google = val;
},
build_() {
return { groupsSelfList: {} };
}
get email() {
return email;
},
set email(val) {
email = val;
},
build_
};
}
class GroupUsersListRequest {
constructor(groupId) {
this.groupId = groupId;
}
build_() {
return { groupUsersList: { groupId: this.groupId } };
}
function MatchResponse(message) {
return message.match;
}
class GroupsJoinRequest {
constructor() {
// this is a list of groupIds.
this.groups = [];
function MatchCreateRequest() {
function build_() {
return {
matchCreate: {}
};
}
build_() {
return { groupsJoin: { groupIds: this.groups } };
}
return {
build_,
processResponse_: MatchResponse
};
}
class GroupsLeaveRequest {
constructor() {
// this is a list of groupIds.
this.groups = [];
}
build_() {
return { groupsLeave: { groupIds: this.groups } };
}
function MatchDataResponse(message) {
message.matchData.data = JSON.parse(base64.decode(message.matchData.data));
return message.matchData;
}
class GroupUsersAddRequest {
constructor() {
this.adds = [];
function MatchDataSendRequest({
matchId,
presences,
opCode,
data
} = {}) {
function build_() {
return {
matchDataSend: {
matchId,
presences,
opCode,
data: base64.encode(JSON.stringify(data))
}
};
}
add(groupId, userId) {
this.adds.push({ groupId: groupId, userId: userId });
}
return {
get matchId() {
return matchId;
},
set matchId(val) {
matchId = val;
},
build_() {
var msg = { groupUsersAdd: { groupUsers: [] } };
this.adds.forEach(function (add) {
msg.groupUsersAdd.groupUsers.push({
groupId: add.groupId,
userId: add.userId
});
});
return msg;
}
}
get presences() {
return presences;
},
set presences(val) {
presences = val;
},
class GroupUsersKickRequest {
constructor() {
this.kicks = [];
}
get opCode() {
return opCode;
},
set opCode(val) {
opCode = val;
},
kick(groupId, userId) {
this.kicks.push({ groupId: groupId, userId: userId });
}
get data() {
return data;
},
set data(val) {
data = val;
},
build_() {
var msg = { groupUsersKick: { groupUsers: [] } };
this.kicks.forEach(function (kick) {
msg.groupUsersKick.groupUsers.push({
groupId: kick.groupId,
userId: kick.userId
});
});
return msg;
}
build_,
processResponse_: MatchDataResponse
};
}
class GroupUsersPromoteRequest {
constructor() {
this.promotes = [];
}
function MatchesResponse(message) {
return message.matches;
}
promote(groupId, userId) {
this.promotes.push({ groupId: groupId, userId: userId });
function MatchesJoinRequest({
matchIds = [],
tokens = []
} = {}) {
function build_() {
return {
matchesJoin: {
matches: [...matchIds.map(matchId => ({ matchId })), ...tokens.map(token => ({ token }))]
}
};
}
build_() {
var msg = { groupUsersPromote: { groupUsers: [] } };
this.promotes.forEach(function (promote) {
msg.groupUsersPromote.groupUsers.push({
groupId: promote.groupId,
userId: promote.userId
});
});
return msg;
}
}
return {
get matchIds() {
return matchIds;
},
set matchIds(val) {
matchIds = val;
},
class NotificationsListRequest {
constructor() {
this.limit = null;
this.resumableCursor = null;
}
get tokens() {
return tokens;
},
set tokens(val) {
tokens = val;
},
build_() {
return { notificationsList: {
limit: this.limit ? this.limit : 10,
resumableCursor: this.resumableCursor
} };
}
build_,
processResponse_: MatchesResponse
};
}
class NotificationsRemoveRequest {
constructor() {
// this is a list of notificationIds.
this.notifications = [];
function MatchesLeaveRequest({
matchIds = []
} = {}) {
function build_() {
return {
matchesLeave: {
matchIds
}
};
}
build_() {
return { notificationsRemove: { notificationIds: this.notifications } };
}
return {
get matchIds() {
return matchIds;
},
set matchIds(val) {
matchIds = val;
},
build_
};
}
class RpcRequest {
constructor() {
this.id = null;
this.payload = null;
}
build_() {
return { rpc: {
id: this.id,
payload: this.payload ? JSON.stringify(this.payload) : null
} };
}
function MatchmakeTicketResponse(message) {
return message.matchmakeTicket;
}
class MatchmakeAddRequest {
constructor(requiredCount) {
this.requiredCount = requiredCount;
this.filters = [];
this.properties = [];
}
function MatchmakeAddRequest(requiredCount) {
let filters = [];
let properties = [];
addTermFilter(name, termSet, matchAllTerms) {
this.filters.push({
name: name,
const self = {
get requiredCount() {
return requiredCount;
},
set requiredCount(val) {
requiredCount = val;
},
get filters() {
return filters;
},
set filters(val) {
filters = val;
},
get properties() {
return properties;
},
set properties(val) {
properties = val;
},
addTermFilter,
addRangeFilter,
addCheckFilter,
addStringSetProperty,
addIntegerProperty,
addBooleanProperty,
build_,
processResponse_: MatchmakeTicketResponse
};
return self;
function addTermFilter(name, termSet, matchAllTerms) {
filters.push({
name,
term: {
terms: termSet,
matchAllTerms: matchAllTerms
matchAllTerms
}
});
return this;
return self;
}
addRangeFilter(name, lowerbound, upperbound) {
this.filters.push({
name: name,
function addRangeFilter(name, lowerbound, upperbound) {
filters.push({
name,
range: {
lowerBound: lowerbound,
upperBound: upperbound
lowerBound,
upperBound
}
});
return this;
return self;
}
addCheckFilter(name, value) {
this.filters.push({
name: name,
function addCheckFilter(name, value) {
filters.push({
name,
check: value
});
return this;
return self;
}
addStringSetProperty(key, termSet) {
this.properties.push({
key: key,
function addStringSetProperty(key, termSet) {
properties.push({
key,
stringSet: termSet
});
return this;
return self;
}
addIntegerProperty(key, integerValue) {
this.properties.push({
key: key,
function addIntegerProperty(key, integerValue) {
properties.push({
key,
intValue: integerValue
});
return this;
return self;
}
addBooleanProperty(key, boolValue) {
this.properties.push({
key: key,
boolValue: boolValue
function addBooleanProperty(key, boolValue) {
properties.push({
key,
boolValue
});
return this;
return self;
}
build_() {
function build_() {
return {
matchmakeAdd: {
requiredCount: this.requiredCount,
filters: this.filters,
properties: this.properties
requiredCount,
filters,
properties
}

@@ -1343,214 +2042,867 @@ };

class MatchmakeRemoveRequest {
constructor(ticket) {
this.ticket = ticket;
function MatchmakeRemoveRequest(ticket) {
function build_() {
return {
matchmakeRemove: {
ticket
}
};
}
build_() {
return { matchmakeRemove: { ticket: this.ticket } };
}
return {
get ticket() {
return ticket;
},
set ticket(val) {
ticket = val;
},
build_
};
}
class MatchCreateRequest {
constructor() {}
function NotificationsResponse(message) {
const {
notifications: {
notifications = []
}
} = message;
build_() {
notifications.forEach(function (notification) {
notification.content = JSON.parse(notification.content);
});
return message.notifications;
}
function NotificationsListRequest({
limit,
resumableCursor
} = {}) {
function build_() {
return {
matchCreate: {}
notificationsList: {
limit: limit ? limit : 10,
resumableCursor
}
};
}
return {
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get resumableCursor() {
return resumableCursor;
},
set resumableCursor(val) {
resumableCursor = val;
},
build_,
processResponse_: NotificationsResponse
};
}
class MatchesJoinRequest {
constructor() {
this.matchIds = [];
this.tokens = [];
function NotificationsRemoveRequest({
notifications = []
} = {}) {
function build_() {
return {
notificationsRemove: {
notificationIds: notifications
}
};
}
build_() {
var msg = {
matchesJoin: { matches: [] }
return {
get notifications() {
return notifications;
},
set notifications(val) {
notifications = val;
},
build_
};
}
function RpcResponse(message) {
let {
rpc: {
id,
payload
}
} = message;
payload = payload ? JSON.parse(payload) : null;
return {
id,
payload
};
}
function RpcRequest({
id,
payload
} = {}) {
function build_() {
return {
rpc: {
id,
payload: payload ? JSON.stringify(payload) : null
}
};
}
this.matchIds.forEach(function (id) {
msg.matchesJoin.matches.push({ matchId: id });
});
return {
get id() {
return id;
},
set id(val) {
id = val;
},
this.tokens.forEach(function (token) {
msg.matchesJoin.matches.push({ token: token });
});
get payload() {
return payload;
},
set payload(val) {
payload = val;
},
return msg;
}
build_,
processResponse_: RpcResponse
};
}
class MatchesLeaveRequest {
constructor() {
this.matchIds = [];
function SelfResponse(message) {
return message.self;
}
function SelfFetchRequest() {
function build_() {
return {
selfFetch: {}
};
}
build_() {
return {
build_,
processResponse_: SelfResponse
};
}
function SelfUpdateRequest({
handle,
fullname,
timezone,
location,
lang,
avatarUrl,
metadata = {}
} = {}) {
function build_() {
return {
matchesLeave: {
matchIds: this.matchIds
selfUpdate: {
handle,
fullname,
timezone,
location,
lang,
avatarUrl,
metadata: JSON.stringify(metadata)
}
};
}
return {
get handle() {
return handle;
},
set handle(val) {
handle = val;
},
get fullname() {
return fullname;
},
set fullname(val) {
fullname = val;
},
get timezone() {
return timezone;
},
set timezone(val) {
timezone = val;
},
get location() {
return location;
},
set location(val) {
location = val;
},
get lang() {
return lang;
},
set lang(val) {
lang = val;
},
get metadata() {
return metadata;
},
set metadata(val) {
metadata = val;
},
get avatarUrl() {
return avatarUrl;
},
set avatarUrl(val) {
avatarUrl = val;
},
build_
};
}
class MatchDataSendRequest {
constructor() {
this.matchId = null;
this.presence = null; //UserPresence
this.opCode = 0;
this.data = null;
function StorageDataResponse(message) {
return message.storageData;
}
function StorageFetchRequest({
keys = []
} = {}) {
const self = {
get keys() {
return keys;
},
set keys(val) {
keys = val;
},
fetch,
build_,
processResponse_: StorageDataResponse
};
return self;
function build_() {
return {
storageFetch: {
keys
}
};
}
build_() {
function fetch(bucket, collection, record, userId) {
keys.push({
bucket,
collection,
record,
userId
});
return self;
}
}
function StorageListRequest({
userId,
bucket,
collection,
limit,
cursor
} = {}) {
function build_() {
return {
matchDataSend: {
matchId: matchId,
presence: presence,
opCode: opCode,
data: base64.encode(JSON.stringify(data))
storageList: {
userId,
bucket,
collection,
limit,
cursor
}
};
}
return {
get userId() {
return userId;
},
set userId(val) {
userId = val;
},
get bucket() {
return bucket;
},
set bucket(val) {
bucket = val;
},
get collection() {
return collection;
},
set collection(val) {
collection = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get cursor() {
return cursor;
},
set cursor(val) {
limit = val;
},
build_,
processResponse_: StorageDataResponse
};
}
class LeaderboardsListRequest {
constructor() {
this.filterLeaderboardIds = [];
this.limit = null;
this.cursor = null;
function StorageRemoveRequest({
keys = []
} = {}) {
const self = {
get keys() {
return keys;
},
set keys(val) {
keys = val;
},
remove,
build_
};
return self;
function build_() {
return {
storageRemove: {
keys
}
};
}
build_() {
var msg = { leaderboardsList: {
filterLeaderboardId: [],
limit: this.limit,
cursor: this.cursor
} };
function remove(bucket, collection, record, userId) {
keys.push({
bucket,
collection,
record,
userId
});
this.filterLeaderboardIds.forEach(function (id) {
msg.leaderboardsList.filterLeaderboardId.push(id);
});
return msg;
return self;
}
}
class LeaderboardRecordsFetchRequest {
constructor() {
this.leaderboardIds = [];
this.limit = null;
this.cursor = null;
function StorageKeysResponse(message) {
return message.storageKeys;
}
function StorageUpdateRequest({
updates = []
} = {}) {
const self = {
get updates() {
return updates;
},
set updates(val) {
updates = val;
},
update,
build_,
processResponse_: StorageKeysResponse
};
return self;
function build_() {
return {
storageUpdate: {
updates
}
};
}
build_() {
var msg = { leaderboardRecordsFetch: {
leaderboardIds: [],
limit: this.limit,
cursor: this.cursor
} };
// storageOps variable must be an array
function update(bucket, collection, record, storageOps = [], permissionRead = 1, permissionWrite = 1, version) {
updates.push({
key: {
bucket,
collection,
record,
version
},
permissionRead,
permissionWrite,
ops: storageOps
});
}
}
this.leaderboardIds.forEach(function (id) {
msg.leaderboardRecordsFetch.leaderboardIds.push(id);
Object.assign(StorageUpdateRequest, {
add,
append,
copy,
incr,
init,
merge,
move,
remove,
replace,
test,
compare
});
function add(path, value) {
return {
op: 0,
path,
value: JSON.stringify(value)
};
}
function append(path, value) {
return {
op: 1,
path,
value: JSON.stringify(value)
};
}
function copy(path, from) {
return {
op: 2,
path,
from
};
}
function incr(path, value) {
return {
op: 3,
path,
value: JSON.stringify(value)
};
}
function init(path, value) {
return {
op: 4,
path,
value: JSON.stringify(value)
};
}
function merge(path, from) {
return {
op: 5,
path,
from
};
}
function move(path, from) {
return {
op: 6,
path,
from
};
}
function remove(path) {
return {
op: 8,
path
};
}
function replace(path, value) {
return {
op: 9,
path,
value: JSON.string(value)
};
}
function test(path, value) {
return {
op: 10,
path,
value: JSON.stringify(value)
};
}
function compare(path, value, assertValue) {
return {
op: 11,
path,
value,
assert
};
}
function StorageWriteRequest({
data = []
} = {}) {
const self = {
get data() {
return data;
},
set data(val) {
data = val;
},
write,
build_,
processResponse_: StorageKeysResponse
};
return self;
function write(bucket, collection, record, value, permissionRead = 1, permissionWrite = 1, version) {
data.push({
bucket,
collection,
record,
value: value ? JSON.stringify(value) : '{}',
version,
permissionRead,
permissionWrite
});
return msg;
return self;
}
function build_() {
return {
storageWrite: {
data
}
};
}
}
class LeaderboardRecordsListRequest {
constructor() {
this.leaderboardId = null;
this.limit = null;
this.cursor = null;
function TopicMessageAckResponse(message) {
return message.topicMessageAck;
}
// only set one of the followings
this.lang = null;
this.location = null;
this.timezone = null;
this.ownerId = null;
this.ownerIds = [];
function TopicMessageSendRequest({
topic,
data
} = {}) {
function build_() {
return {
topicMessageSend: {
topic,
data: JSON.stringify(data)
}
};
}
build_() {
var msg = { leaderboardRecordsList: {
leaderboardId: this.leaderboardId,
limit: this.limit,
cursor: this.cursor
} };
return {
get topic() {
return topic;
},
set topic(val) {
topic = val;
},
if (this.lang) {
msg.leaderboardRecordsList.lang = this.lang;
} else if (this.location) {
msg.leaderboardRecordsList.location = this.createdAt;
} else if (this.timezone) {
msg.leaderboardRecordsList.count = this.count;
} else if (this.ownerId) {
msg.leaderboardRecordsList.ownerId = this.ownerId;
} else if (this.ownerIds.length > 0) {
msg.leaderboardRecordsList.ownerIds = { ownerIds: this.ownerIds };
get data() {
return data;
},
set data(val) {
data = val;
},
build_,
processResponse_: TopicMessageAckResponse
};
}
function TopicMessagesResponse(message) {
const {
topicMessages: {
messages = []
}
} = message;
messages.forEach(message => {
message.data = JSON.parse(message.data);
});
return message.topicMessages;
}
function TopicMessagesListRequest({
cursor,
forward, // boolean
limit, // number <= 100
// set only one of the followings
userId,
room,
groupId
} = {}) {
function build_() {
const msg = {
topicMessagesList: {
cursor,
forward,
limit
}
};
if (userId) {
msg.topicMessagesList.userId = userId;
} else if (room) {
msg.topicMessagesList.room = room;
} else if (groupId) {
msg.topicMessagesList.groupId = groupId;
}
return msg;
}
return {
get cursor() {
return cursor;
},
set cursor(val) {
cursor = val;
},
get forward() {
return forward;
},
set forward(val) {
forward = val;
},
get limit() {
return limit;
},
set limit(val) {
limit = val;
},
get userId() {
return userId;
},
set userId(val) {
userId = val;
},
get room() {
return room;
},
set room(val) {
room = val;
},
get groupId() {
return groupId;
},
set groupId(val) {
groupId = val;
},
build_,
processResponse_: TopicMessagesResponse
};
}
class LeaderboardRecordWriteRequest {
constructor() {
this.records = [];
function TopicsResponse(message) {
return message.topics;
}
function TopicsJoinRequest({
// NOTE: The server only processes the first item of the list,
// and will ignore and logs a warning message for other items.
topics = []
} = {}) {
const self = {
get topics() {
return topics;
},
set topics(val) {
topics = val;
},
dm,
group,
room,
build_,
processResponse_: TopicsResponse
};
return self;
function dm(userId) {
topics.push({ userId });
return self;
}
set(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
"set": value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
};
function group(groupId) {
topics.push({ groupId });
return self;
}
this.records.push(record);
function room(room) {
topics.push({ room });
return self;
}
best(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
best: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
function build_() {
return {
topicsJoin: {
joins: topics
}
};
this.records.push(record);
}
}
decrement(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
decr: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
function TopicsLeaveRequest({
// NOTE: The server only processes the first item of the list,
// and will ignore and logs a warning message for other items.
topics = []
} = {}) {
function build_() {
return {
topicsLeave: {
topics
}
};
}
this.records.push(record);
return {
get topics() {
return topics;
},
set topics(val) {
topics = val;
},
build_
};
}
function UnlinkRequest({
custom,
device,
facebook,
google,
email
} = {}) {
function build_() {
if (custom) return { link: { custom } };
if (device) return { link: { device } };
if (facebook) return { link: { facebook } };
if (google) return { link: { google } };
if (email) return { link: { email } };
}
increment(leaderboardId, value, metadata, location, timezone) {
var record = {
leaderboardId: leaderboardId,
incr: value,
metadata: JSON.stringify(metadata),
location: location,
timezone: timezone
return {
get custom() {
return custom;
},
set custom(val) {
custom = val;
},
get device() {
return device;
},
set device(val) {
device = val;
},
get facebook() {
return facebook;
},
set facebook(val) {
facebook = val;
},
get google() {
return google;
},
set google(val) {
google = val;
},
get email() {
return email;
},
set email(val) {
email = val;
},
build_
};
}
function UsersResponse(message) {
const {
users: {
users = []
}
} = message;
users.forEach(user => {
user.metadata = JSON.parse(user.metadata);
});
return users;
}
function UsersFetchRequest({
userIds = [],
handles = []
} = {}) {
function build_() {
return {
usersFetch: {
users: [...userIds.map(userId => ({ userId })), ...handles.map(handle => ({ handle }))]
}
};
this.records.push(record);
}
build_() {
return { leaderboardRecordsWrite: { records: this.records } };
}
return {
get userIds() {
return userIds;
},
set userIds(val) {
userIds = val;
},
get handles() {
return handles;
},
set handles(val) {
handles = val;
},
build_,
processResponse_: UsersResponse
};
}

@@ -1578,48 +2930,50 @@

exports.AuthenticateRequest = AuthenticateRequest;
// include fetch polyfill
exports.Client = Client;
exports.Session = Session;
exports.LinkRequest = LinkRequest;
exports.UnlinkRequest = UnlinkRequest;
exports.SelfFetchRequest = SelfFetchRequest;
exports.SelfUpdateRequest = SelfUpdateRequest;
exports.UsersFetchRequest = UsersFetchRequest;
exports.StorageListRequest = StorageListRequest;
exports.StorageFetchRequest = StorageFetchRequest;
exports.StorageWriteRequest = StorageWriteRequest;
exports.StorageRemoveRequest = StorageRemoveRequest;
exports.StorageUpdateRequest = StorageUpdateRequest;
exports.AuthenticateRequest = AuthenticateRequest;
exports.FriendsAddRequest = FriendsAddRequest;
exports.FriendsRemoveRequest = FriendsRemoveRequest;
exports.FriendsBlockRequest = FriendsBlockRequest;
exports.FriendsListRequest = FriendsListRequest;
exports.TopicsJoinRequest = TopicsJoinRequest;
exports.TopicsLeaveRequest = TopicsLeaveRequest;
exports.TopicMessageSendRequest = TopicMessageSendRequest;
exports.TopicMessagesListRequest = TopicMessagesListRequest;
exports.FriendsRemoveRequest = FriendsRemoveRequest;
exports.GroupsCreateRequest = GroupsCreateRequest;
exports.GroupsUpdateRequest = GroupsUpdateRequest;
exports.GroupsRemoveRequest = GroupsRemoveRequest;
exports.GroupsFetchRequest = GroupsFetchRequest;
exports.GroupsJoinRequest = GroupsJoinRequest;
exports.GroupsLeaveRequest = GroupsLeaveRequest;
exports.GroupsListRequest = GroupsListRequest;
exports.GroupsRemoveRequest = GroupsRemoveRequest;
exports.GroupsSelfListRequest = GroupsSelfListRequest;
exports.GroupUsersListRequest = GroupUsersListRequest;
exports.GroupsJoinRequest = GroupsJoinRequest;
exports.GroupsLeaveRequest = GroupsLeaveRequest;
exports.GroupsUpdateRequest = GroupsUpdateRequest;
exports.GroupUsersAddRequest = GroupUsersAddRequest;
exports.GroupUsersKickRequest = GroupUsersKickRequest;
exports.GroupUsersListRequest = GroupUsersListRequest;
exports.GroupUsersPromoteRequest = GroupUsersPromoteRequest;
exports.LeaderboardRecordsFetchRequest = LeaderboardRecordsFetchRequest;
exports.LeaderboardRecordsListRequest = LeaderboardRecordsListRequest;
exports.LeaderboardRecordWriteRequest = LeaderboardRecordWriteRequest;
exports.LeaderboardsListRequest = LeaderboardsListRequest;
exports.LinkRequest = LinkRequest;
exports.MatchCreateRequest = MatchCreateRequest;
exports.MatchDataSendRequest = MatchDataSendRequest;
exports.MatchesJoinRequest = MatchesJoinRequest;
exports.MatchesLeaveRequest = MatchesLeaveRequest;
exports.MatchmakeAddRequest = MatchmakeAddRequest;
exports.MatchmakeRemoveRequest = MatchmakeRemoveRequest;
exports.NotificationsListRequest = NotificationsListRequest;
exports.NotificationsRemoveRequest = NotificationsRemoveRequest;
exports.RpcRequest = RpcRequest;
exports.MatchmakeAddRequest = MatchmakeAddRequest;
exports.MatchmakeRemoveRequest = MatchmakeRemoveRequest;
exports.MatchCreateRequest = MatchCreateRequest;
exports.MatchesJoinRequest = MatchesJoinRequest;
exports.MatchesLeaveRequest = MatchesLeaveRequest;
exports.MatchDataSendRequest = MatchDataSendRequest;
exports.LeaderboardsListRequest = LeaderboardsListRequest;
exports.LeaderboardRecordsFetchRequest = LeaderboardRecordsFetchRequest;
exports.LeaderboardRecordsListRequest = LeaderboardRecordsListRequest;
exports.LeaderboardRecordWriteRequest = LeaderboardRecordWriteRequest;
exports.SelfFetchRequest = SelfFetchRequest;
exports.SelfUpdateRequest = SelfUpdateRequest;
exports.StorageFetchRequest = StorageFetchRequest;
exports.StorageListRequest = StorageListRequest;
exports.StorageRemoveRequest = StorageRemoveRequest;
exports.StorageUpdateRequest = StorageUpdateRequest;
exports.StorageWriteRequest = StorageWriteRequest;
exports.TopicMessageSendRequest = TopicMessageSendRequest;
exports.TopicMessagesListRequest = TopicMessagesListRequest;
exports.TopicsJoinRequest = TopicsJoinRequest;
exports.TopicsLeaveRequest = TopicsLeaveRequest;
exports.UnlinkRequest = UnlinkRequest;
exports.UsersFetchRequest = UsersFetchRequest;

@@ -1626,0 +2980,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

{
"name": "@heroiclabs/nakama-js",
"version": "0.3.0",
"version": "0.4.0",
"description": "JavaScript client for Nakama server.",
"keywords": ["realtime", "realtime chat", "nakama", "game server"],
"keywords": [
"realtime",
"realtime chat",
"nakama",
"game server"
],
"homepage": "https://heroiclabs.com",

@@ -23,3 +28,4 @@ "bugs": "https://github.com/heroiclabs/nakama-js/issues",

"dependencies": {
"base-64": "^0.1.0"
"base-64": "^0.1.0",
"whatwg-fetch": "^2.0.3"
},

@@ -32,3 +38,4 @@ "devDependencies": {

"rollup-plugin-commonjs": "^8.2.4",
"rollup-plugin-node-resolve": "^3.0.0"
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-root-import": "^0.2.2"
},

@@ -35,0 +42,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc