User Information
Access information about connected users including display names, user IDs, and connection IDs using the Sync Kit UserInfo system.
- Snapchat: not supported
- SPECS: fully supported
- Camera Kit Web: not supported
- Camera Kit Mobile: not supported
- SnapchatNot supported
- SPECSFully supported
- Camera Kit WebNot supported
- Camera Kit MobileNot supported
You can identify users in a Connected Lens session in multiple ways through the UserInfo class: UserInfo.userId, UserInfo.connectionId, and UserInfo.displayName.
UserInfo is available from a number of sources, including SessionController APIs, SyncEntity.ownerInfo, and NetworkRoot.ownerInfo. MessageInfo for Networked Events also includes userId and connectionId of the message sender.
UserId
UserInfo.userId is tied to a user's Snapchat account. If two SPECS devices are paired to the same user account, the userId for those devices in the session will be the same. The userId for a given user is different in different Lenses. UserInfo.userId is a string.
ConnectionId
UserInfo.connectionId is tied to the device that has joined the session. UserInfo.connectionId is unique to each connected device, and unique to each time the device joins a session. Realtime Store ownership is tied to connectionId, not userId. UserInfo.connectionId is a string.
DisplayName
UserInfo.displayName is the name a user chooses on their Snapchat account profile. It is consistent across devices, Lenses, and sessions. UserInfo.displayName is a string.
SpecsUser
You can also get a SpecsUser for any user in the session with SessionController.getSpecsUser(userInfo, callback). A SpecsUser also has userName, hasBitmoji, birthday, and zodiac.
For the local user, these come from their SPECS account, and birthday and zodiac are null if the account has no birth date. For other users in the session, only displayName and Bitmoji information are available: userName is empty, and birthday and zodiac are null.
A SpecsUser can be used in Bitmoji surfaces such as Bitmoji Module. This is useful for showing a user's Bitmoji in a Connected Lens session.
Important: The callback receives null in mocked singleplayer mode, since there is no user information available, and when there is no session yet.
- TypeScript
- JavaScript
import { SessionController } from 'SyncKit.lspkg/Core/SessionController';
@component
export class GetSpecsUserInfo extends BaseScriptComponent {
private sessionController: SessionController =
SessionController.getInstance();
onAwake() {
this.sessionController.notifyOnReady(() => this.onReady());
}
private onReady(): void {
const localUserInfo = this.sessionController.getLocalUserInfo();
if (!localUserInfo) {
print('No local user info available');
return;
} else {
print('Local user info available: ' + JSON.stringify(localUserInfo));
}
// Get the SpecsUser for the local user
this.sessionController.getSpecsUser(
localUserInfo,
(specsUser: SpecsUser | null) => {
if (!specsUser) {
print('getSpecsUser returned null (expected in singleplayer mode)');
return;
}
const name = specsUser.displayName || specsUser.userName || '<unknown>';
print(
'Got SpecsUser: ' + name + ', hasBitmoji=' + specsUser.hasBitmoji
);
}
);
}
}
var sessionController = global.sessionController;
function onAwake() {
print('GetSpecsUserScript: onAwake called');
if (sessionController) {
sessionController.notifyOnReady(onReady);
} else {
print('SessionController not available');
}
}
function onReady() {
print('GetSpecsUserScript: onReady called');
var localUserInfo = sessionController.getLocalUserInfo();
if (!localUserInfo) {
print('No local user info available');
return;
}
// Get the SpecsUser for the local user
sessionController.getSpecsUser(localUserInfo, function (specsUser) {
if (!specsUser) {
print('getSpecsUser returned null (expected in singleplayer mode)');
return;
}
var name = specsUser.displayName || specsUser.userName || '<unknown>';
print('Got SpecsUser: ' + name + ', hasBitmoji=' + specsUser.hasBitmoji);
});
}
// Initialize the script
onAwake();
Example Scenario
This is a straightforward example showing a situation where one user joins a Connected Lenses session on two devices at once, and another user joins on a single device. These example userIds, connectionIds, and displayNames are simplified for explanation.
Lens #1
| User | userId | connectionId | displayName |
|---|---|---|---|
| User A | userA | 123 | User A |
| User A | userA | 456 | User A |
| User B | userB | 789 | User B |
Lens #2
| User | userId | connectionId | displayName |
|---|---|---|---|
| User A | userA | 987 | User A |
| User A | userA | 654 | User A |
| User B | userB | 321 | User B |