GithubHelp home page GithubHelp logo

playfab / javascriptsdk Goto Github PK

View Code? Open in Web Editor NEW
43.0 29.0 28.0 4.22 MB

JavaScriptSDK for the Client API of PlayFab

License: Apache License 2.0

JavaScript 94.71% HTML 0.20% CSS 0.70% TypeScript 4.39%
playfab javascript typescript

javascriptsdk's Introduction

JavaScriptSDK README

1. Overview:

JavaScriptSDK for the Client API of PlayFab

This SDK can alternatively be used via our CDN. Additional details can be found here.

If you want to start coding right away, check out our JavaScript Getting Started Guide

2. Prerequisites:

To connect to the PlayFab service, your machine must be running TLS v1.2 or better.

3. Example Project (UNDER CONSTRUCTION)

The Example project is being revised for the upcoming 1.0 release

This sdk includes an optional example project that is used by PlayFab to verify sdk features are fully functional.

Please read about the testTitleData.json format, and purpose here:

  • testTitleData.md must be created and placed in the root of the example (beside index.html & PlayFabApiTest.ts), and must be named "testTitleData.json"

4. Troubleshooting:

For a complete list of available APIs, check out the online documentation.

Contact Us

We love to hear from our developer community! Do you have ideas on how we can make our products and services better?

Our Developer Success Team can assist with answering any questions as well as process any feedback you have about PlayFab services.

Forums, Support and Knowledge Base

7. NPM support:

You may install JavaScript SDK with npm by running :

npm install playfab-web-sdk

Notice that it will install web JavaScript package as opposed to npm install playfab-sdk which will install NodeJS SDK.

While npm is generally used for server side packages, you may use one of popular build tools to mix NPM installed packages into your clientside JS codebase. Consider Babel, Webpack, Gulp or Grunt for different approaches to building and automation.

6. Acknowledgements

dylanh724 - The previous tutorial before the current Getting Started Guide

7. Copyright and Licensing Information:

Apache License -- Version 2.0, January 2004 http://www.apache.org/licenses/

Full details available within the LICENSE file.

javascriptsdk's People

Contributors

bvanous avatar hungwunfai avatar lazerwalker avatar markval avatar matt-augustine avatar pgilmorepf avatar playfabjenkinsbot avatar sini-codes avatar toddbellmsft avatar zac-playfab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

javascriptsdk's Issues

session ticket is never stored

When using any of the API's functions that should store the session ticket, the actual retrieved ticked never is considered for being saved in exports.settings.session_ticket.

The erroneous line is

settings.session_ticket = result.SessionTicket != null ? settings.session_ticket : settings.session_ticket;

and should be corrected to

settings.session_ticket = result.SessionTicket != null ? result.SessionTicket : settings.session_ticket;

LoginXXX calls do not pass customData and extraHeaders to ExecuteRequest.

Expected Behavior

result.CustomData contains the customData object passed to the LoginXXX API

The extraHeaders object passed to the LoginXXX API is used in the REST request

Observed Behavior

result.CustomData is undefined

extraHeaders is not used for LoginXXX calls

Steps to Reproduce

  1. Call any of the LoginXXX APIs and pass in a customData object. For example { "foo": "bar" }
  2. Set a breakpoint in the callback and when hit examine the value of result.CustomData.

Remark

A result of this behavior is that you are unable to use extraHeaders or customData with the various LoginXXX calls.

Support Promises for API calls

I've been using both this SDK and the NodeJS SDK extensively for a few months now, and I've found that the SDKs are much easier to use when API calls are promise-based. I've been using a wrapper function that provides this functionality, which works fine but is not ideal. That looks something like this (shortened for brevity)

function playfabAPI(endpoint, requestObject) {
    return new Promise(function(resolve, reject) {
        PlayFabClientSDK[endpoint](requestObject, function(error, result) {
            if (error !== null) {
                // Request error
                return reject(new Error(error));
            }
            else if (result && result["code"] == 200) {
                // Request successful
                return resolve(result);
            }
            else {
                // Non-200 HTTP status
                return reject(new Error(result.status));
            }
        });
    });
}

This makes for cleaner code, adds useful functionality, and eliminates a lot of redundant error checking code. The current request functions are consistent enough for this to work in most cases so far but I'm a bit wary of using it in production. What I would propose is to implement this either alongside the current format, or as an additional SDK/script, for compatibility reasons.


Example of how this change could be implemented in a given function:

Current

exports.UpdateUserData = function (request, callback) {
    if (PlayFab._internalSettings.sessionTicket == null) {
        throw "Must be logged in to call this method";
    }
    PlayFab.MakeRequest(
        PlayFab.GetServerUrl() + "/Client/UpdateUserData",
        request,
        "X-Authorization",
        PlayFab._internalSettings.sessionTicket,
        function (error, result) {
            if (callback != null) {
                callback(error, result);
            }
        },
    );
};

Proposed

exports.UpdateUserData = function (request)
{
    return new Promise((resolve, reject) => {
        if (PlayFab._internalSettings.sessionTicket == null) {
            throw "Must be logged in to call this method";
        }
        PlayFab.MakeRequest(
            PlayFab.GetServerUrl() + "/Client/UpdateUserData",
            request,
            "X-Authorization",
            PlayFab._internalSettings.sessionTicket,
            (error, result) => {
                if (error !== null) {
                    return reject(new Error(error));
                }
                else if (result && result["code"] == 200) {
                    return resolve(result);
                }
                else {
                    return reject(new Error(result.status));
                }
            },
        );
    });
};

Example usage of current vs proposed usage:

Current

PlayFabClientSDK.UpdateUserData(requestParameters, function(error, result) {
    // Check for + handle errors... 
    // Handle result...
});

Proposed

PlayFabClientSDK.UpdateUserData(requestParameters).then((userDataResult) => {
    // Handle userDataResult...
}).catch((error) => {
    // Handle errors... 
});

This would also have the added benefit of allowing the use of async/await which can greatly simplify code structure, e.g. when chaining requests

(async function() {
    const userDataResult = await PlayFabClientSDK.UpdateUserData(requestParameters);
    // Handle userDataResult/make additional API requests
})();

Let me know what you guys think. Is this something that would be better served using the SDK generator with a custom config, or would it be feasible to get an official implementation?

Can't use TypeScript definitions

image

I'm not sure why it happens, maybe I do miss something. Probably, there must be types property in package.json, as described here: How to get your d.ts files to users

But if I copy type definitions to my project manually, it works fine. So problem is in a package settings or something, not in files itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.