Better player experience can be achieved when players are updated by changes in the match in real-time. By connecting to the API using a WebSocket, changes to the match will be sent to clients immediately.

An example

Here is an example in JavaScript of how to establish a connection and listen for changes for a match after making the initial matchmaking request from which you get the match id.


var matchId = '<insert-match-id>'
var connection = new WebSocket('wss://api.polynect.io/matches/' + matchId, 'match.polynect.io');
connection.onopen = function() {
    console.log("Listening on match " + matchId);
}
connection.onmessage = function(message) {
    var match = JSON.parse(message.data);
    console.log(match);
};

The second argument when constructing the WebSocket connection is the protocol and should be match.polynect.io.

Message content

The messages include the same data as you would receive when making a matchmaking request as shown in the article Getting started

Got an idea for a game?


We would love to hear about it and to discuss how to best integrate it with Polynect. Other business inquiries are also welcome. Please write to adam@polynect.io

Copyright © Polynect