Skip to content

Social (Cocos)

Two layers of social in the Cocos wrapper:

  • FRVR friends graph — synced to the server, cross‑channel: syncFriends, getAllFriends, addFriend, removeFriend.
  • Platform surfaces — native share sheet, invite picker, and update channel: shareMessage, inviteUsers, sendUpdate, getPlatformFriends. Gated by the current channel.

For real‑time events (friend status changes, game invite sockets), see Social live.

Requires the player to be authenticated.

await FRVRSDK.instance.syncFriends();
const friends = await FRVRSDK.instance.getAllFriends();

await FRVRSDK.instance.addFriend(friendId);
await FRVRSDK.instance.removeFriend(friendId);

Call syncFriends() once per session — it uploads the channel’s friend list so the FRVR backend can match and register them.

Different channels expose different subsets — guard your UI before showing buttons:

if (FRVRSDK.instance.isSocialAPISupported('shareMessage')) {
  showShareButton();
}

if (await FRVRSDK.instance.canInvite()) {
  showInviteButton();
}

Common API names you can pass to isSocialAPISupported: shareMessage, inviteUsers, sendUpdate, getPlatformFriends, getContextId, getContextData, getContextPlayers.

Posts to the user’s timeline / story / share sheet, depending on the channel.

await FRVRSDK.instance.shareMessage({
  image:    imageBase64,            // BASE64 / JPEG / PNG
  text:     'I hit 10,000 points!',
  headline: 'New high score',
  cta:      'Beat my score',
  entryPointData: { from: 'share', score: 10000 },
});
FieldTypeRequiredPurpose
imagestringyesImage data URL or hosted URL (BASE64 / JPEG / PNG).
textstringyesBody / description text.
headlinestringnoShort headline above the body, where supported.
ctastringnoCall‑to‑action button label.
entryPointDataobjectnoPayload delivered to the recipient via entry point when they open the share.

Opens the channel’s friend picker so the player can invite specific contacts directly into the game.

if (await FRVRSDK.instance.canInvite()) {
  await FRVRSDK.instance.inviteUsers({
    image:    imageBase64,
    text:     'Come play with me!',
    headline: 'Join my game',
    cta:      'Play now',
    entryPointData: { from: 'invite', lobbyId: 'lobby_42' },
  });
}
FieldTypeRequiredPurpose
imagestringyesImage data URL or hosted URL (BASE64 / JPEG / PNG).
textstringyesMessage shown alongside the image.
headlinestringnoShort headline above the body, where supported.
ctastringnoCall‑to‑action button label.
entryPointDataobjectnoPayload available to the recipient through entry point on join.

canInvite() returns false on channels where invites are unavailable — gate your UI on it.

Yields control to the platform so it can deliver a templated update (Facebook context update, Snapchat sticker, Discord activity, …). Templates live in the SDK’s default templates config — drop the channel‑specific config into your game folder to use them.

await FRVRSDK.instance.sendUpdate({
  template:       'JOIN_PLAYER',
  image:          imageBase64,
  bitmojiVariant: 'HAPPY',                   // snapchat only
  entryPointData: { lobbyId: 'lobby_42' },
});
FieldTypePurpose
templatestringPredefined template name (e.g. 'JOIN_PLAYER').
imagestringImage data URL or hosted URL (BASE64 / JPEG / PNG).
bitmojiVariantstringSnapchat bitmoji pose — 'HAPPY', 'WINK', 'HEARTEYES', etc.
entryPointDataobjectPayload delivered via entry point when the recipient opens the update.
overrideobjectChannel‑specific raw payloads (snapchat, facebookInstant, facebookRooms, discord) that replace the template fields.

Read the channel’s native friend list (e.g. the player’s Facebook gaming friends):

const platformFriends = await FRVRSDK.instance.getPlatformFriends();
// → Friend[]: { id, name, nickname?, image, channel }

Use this for invite UIs that mimic the host platform’s look, or to pre‑populate a “friend picker” of your own. For the cross‑channel FRVR graph, use getAllFriends() instead.

Where the user currently is on the host (FB context, Snap chat, Discord activity):

const ctxId      = await FRVRSDK.instance.getContextId();
const ctxData    = await FRVRSDK.instance.getContextData();
const ctxPlayers = await FRVRSDK.instance.getContextPlayers();

getContextPlayers() returns the same Friend[] shape as getPlatformFriends(), scoped to whoever is currently in the chat / room / party with the player.