# new ImmersClient(destinationDescription, optionsopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
destinationDescription |
Destination
|
Activities.APPlace
|
string
|
Metadata about this destination used when sharing or url for the related Place object. Either a Destination/APPlace object or a url where one can be fetched. |
|
options |
object
|
<optional> |
|
localImmer |
string
|
<optional> |
Domain (host) of the local Immers Server, if there is one |
allowStorage |
boolean
|
<optional> |
Enable localStorage of handle & token for reconnection (make sure you've provided complaince notices as needed) |
Classes
Members
Array.<string>
# authorizedScopes
List of scopes authorized by the user during login. This may differ from what you requested, as the user can override during the authorization process.
- See:
-
- {SCOPES}
string
# handle
Users Immers handle, if known. May be available even when logged-out if passed via URL or stored from past login
Promise.<Activities.APPlace>
# localImmerPlaceObject
fetch the /o/immer object for the current immer from memory cache or network
Object.<string, any>
# sessionInfo
Additional data returned from the user's immer on login
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
isNewUser |
boolean
|
<optional> |
true when this is the first login of a new local user |
email |
string
|
<optional> |
only included on home immer domain when that immer has passEmailToHub config enabled and this is their first login |
provider |
string
|
<optional> |
identity provider domain if on home immer domain and logged in with OpenId Connect and this is their first login |
Methods
# addAvatar(sourceActivity) → {Promise.<string>}
Add an existing avatar to a user's personal avatar collection
Parameters:
Name | Type | Description |
---|---|---|
sourceActivity |
string
|
Activities.APActivity
|
Create activity for the avatar or IRI of activity (other activities with the avatar as their object, e.g. Offer, also allowed) |
IRI of avatar add activity
Promise.<string>
# async addFriend(handle)
This method will either initiate a new friend request or, if a request has already been received from the target user, accept a pending friend request. To create a friend connection, both users will need to call this method with the other user's handle.
Parameters:
Name | Type | Description |
---|---|---|
handle |
string
|
the target user's immers handle or profile id |
# async blockList(forceRefresh) → {Promise.<Array.<string>>}
Fetch list of Profile.id of all users blocked by this user
Parameters:
Name | Type | Description |
---|---|---|
forceRefresh |
boolean
|
skip local cache and fetch from server |
Promise.<Array.<string>>
# async blockUser(handle)
Add an someone to this immerser's blocklist. While on a blocklist, no messages/requests will sent or received between these two users, and any past messages will be omitted from feeds and friends lists. You should also prevent realtime interactions in your application from users in Profile.collections.blocked (e.g. hide avatars, mute audio)
Parameters:
Name | Type | Description |
---|---|---|
handle |
string
|
the target user's immers handle or profile id |
# async connect(tokenCatcherURL, requestedRole, handleopt) → {string}
Connect to user's Immers Space profile, using pop-up window for OAuth if needed
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tokenCatcherURL |
string
|
Page on your domain that runs catchToken on load to retrieve the granted access token. Can be the same page as long as loading it again in a pop-up won't cause a the main session to disconnect. |
|
requestedRole |
string
|
Access level to request, see roles for details |
|
handle |
string
|
<optional> |
User's immers handle. Optional if you have a local Immers Server |
- Deprecated:
- Split into to methods, login and enter, for better control over when a user goes online
token OAuth2 acess token
string
# async corsProxyFetch(url, headers)
Attempt to fetch a cross-domain resource. Prefers using the local immer's proxy service if available, falling back to the user's home immer's proxy service if available or plain fetch.
Parameters:
Name | Type | Description |
---|---|---|
url |
string
|
resource to GET |
headers |
object
|
fetch headers |
# createAvatar(name, glb, icon, privacy, toopt) → {Promise.<string>}
Upload a 3d model as an avatar and optionally share it
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string
|
Name/description |
|
glb |
Blob
|
3d model gltf binary file |
|
icon |
Blob
|
Preview image for thumbnails |
|
privacy |
string
|
'direct', 'friends', or 'public' |
|
to |
<optional> |
Addressees. Accepts Immers handles (username[domain.name]) and ActivityPub IRIs |
IRI of avatar creation post
Promise.<string>
# async deleteMessage(sourceActivity) → {Promise.<string>}
Delete a message.
Parameters:
Name | Type | Description |
---|---|---|
sourceActivity |
string
|
Activities.APActivity
|
IRI of activity or Activity in the Outbox |
IRI of the remove activity
Promise.<string>
# disconnect()
Disconnect from User's immer, retaining credentials to reconnect
# async enter(destinationDescriptionopt)
Mark user as "online" at this immer and share the location with their friends. Must be called after successful login or restoreSession
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
destinationDescription |
Destination
|
Activities.APPlace
|
string
|
<optional> |
# async feed() → {Promise.<Array.<Message>>}
Fetch a page of recent activity Messages
Promise.<Array.<Message>>
# async friendsList() → {Promise.<Array.<FriendStatus>>}
Fetch list of friends and their online status and location
Promise.<Array.<FriendStatus>>
# async getProfile(handle) → {Profile|undefined}
Get a user's profile object from their handle. Uses logged-in users's home immer proxy service if available
Parameters:
Name | Type | Description |
---|---|---|
handle |
string
|
Immers handle |
- User profile or undefined if failed
Profile
|
undefined
# handleImmerLinkClick(clickEvent)
Make navigating between immers easier by providing the user's handle to the next experience so they don't have to type it in. Use as an onClick handler to inject the "me hash" into any cross-origin anchor when navigating. Can be registered directly on the anchor or on a parent element. Will fallback to default click behavior if same-origin, not logged in, or unable to process url.
Parameters:
Name | Type | Description |
---|---|---|
clickEvent |
MouseEvent
|
# async login(tokenCatcherURL, requestedRole, handleopt, registrationopt) → {Promise.<string>}
Connect to user's Immers Space profile, using pop-up window for OAuth
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tokenCatcherURL |
string
|
Page on your domain that runs catchToken on load to retrieve the granted access token. Can be the same page as long as loading it again in a pop-up won't cause a the main session to disconnect. |
|
requestedRole |
string
|
Access level to request, see roles for details |
|
handle |
string
|
<optional> |
User's immers handle. Optional if you have a local Immers Server |
registration |
boolean
|
<optional> |
For use with local immer only, open the popup with the registration tab selected instead of login. handle will be used to prefill the registratoin form if provided |
token OAuth2 acess token
Promise.<string>
# loginWithToken(token, homeImmer, authorizedScopes, sessionInfoopt) → {Promise.<boolean>}
Initialize client with an existing credential, e.g. one obtained through a service account or one returned from catchToken when performing a redirect based OAuth flow
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
token |
string
|
OAuth2 Access Token |
|
homeImmer |
string
|
Domain (host) for user's home immer |
|
authorizedScopes |
string
|
Array.<string>
|
Scopes authorized for the token |
|
sessionInfo |
object
|
<optional> |
optional session data provided alongside token |
true if the login was successful
Promise.<boolean>
# async logout(alsoLogoutFromImmeropt) → {Promise.<void>}
Disconnect from User's immer and delete any traces of user identity. If the user is from the local immer on the same apex domain (more info), alsoLogoutFromImmer can cause the login session on the immer to be terminated as well for a complete logout.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
alsoLogoutFromImmer |
boolean
|
<optional> |
terminate the login session on the local immer as well |
Promise.<void>
# async move(destinationDescription)
Update user's current online location and share with friends
Parameters:
Name | Type | Description |
---|---|---|
destinationDescription |
Destination
|
Activities.APPlace
|
string
|
# navigateToImmerLink(href)
Navigate to a given url while injecting a "me hash" to provide the user's handle to the destination site so that they don't have to re-enter it. Safe to use without checking if user is logged in, will just navigate normally if not
Parameters:
Name | Type | Description |
---|---|---|
href |
string
|
# async reconnect() → {Promise.<boolean>}
Attempt to restore session from a previously granted token. Requires options.allowStorage
- Deprecated:
- Split into to methods, restoreSession and enter, for better control over when a user goes online
Was reconnection successful
Promise.<boolean>
# async removeAvatar(sourceActivity) → {Promise.<string>}
Remove user's avatar from their Avatar Collection.
Parameters:
Name | Type | Description |
---|---|---|
sourceActivity |
string
|
Activities.APActivity
|
Activity IRI or Activity from the Avatars Collection to remove |
IRI of the remove activity
Promise.<string>
# async removeFriend(handle)
Remove a relationship to another immerser, either by removing an existing friend, rejecting a pending incoming friend request, or canceling a pending outgoing friend request
Parameters:
Name | Type | Description |
---|---|---|
handle |
string
|
the target user's immers handle or profile id |
# async resolveProfileIRI(handle) → {string|undefined}
Get a user ID/URL from their handle using webfinger
Parameters:
Name | Type | Description |
---|---|---|
handle |
string
|
immers handle |
- The profile IRI or undefined if failed
string
|
undefined
# async restoreSession() → {Promise.<boolean>}
Attempt to restore session from a previously granted token. Requires options.allowStorage
Was reconnection successful
Promise.<boolean>
# sendChatMessage(content, privacy, toopt) → {Promise.<string>}
Send a message with text content.
privacy level determines who receives and can acccess the message.
direct: Only those named in to
receive the message.
friends: Direct plus friends list.
public: Direct plus Friends plus accessible via URL for sharing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
content |
string
|
The text/HTML content. Will be sanitized before sending |
|
privacy |
string
|
'direct', 'friends', or 'public' |
|
to |
Array.<string>
|
<optional> |
Addressees. Accepts Immers handles (username[domain.name]) and ActivityPub IRIs |
Url of newly posted message
Promise.<string>
# async sendImage(image, privacy, toopt) → {Promise.<string>}
Upload and/or share an image.
When image is a canvas element, its toBlob method is used to generate a
png image to upload.
When image is a File/Blob, it will be uploaded to the user's home immer
and shared. The name
attribute is optional, but type
must contain the
correct MIME. When image is a url, an existing image is shared without
re-uploading. It's better to upload a file so that the user's home
immer can ensure it remains available.
privacy level determines who receives and can acccess the message.
direct: Only those named in to
receive the message.
friends: Direct plus friends list.
public: Direct plus Friends plus accessible via URL for sharing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
image |
File
|
Blob
|
HTMLCanvasElement
|
string
|
Image data to upload or url to share |
|
privacy |
string
|
'direct', 'friends', or 'public' |
|
to |
Array.<string>
|
<optional> |
Addressees. Accepts Immers handles (username[domain.name]) and ActivityPub IRIs |
Url of newly posted message
Promise.<string>
# async sendModel(name, glb, iconopt, privacyopt, toopt)
Upload and optionally share a 3D model. GLB is preferred. Other single-file model formats can be uploaded, but may not be supported when shared to other immers. The blob's type attribute must contain the correct MIME.
The privacy and to arguments determine who receives and can access a post featuring the uploaded model.
For some uses, like collecting a new avatar, you may omit these to not share a post
(this user will still be able to see the model in their outbox).
direct: Only those named in to
receive the message.
friends: Direct plus friends list.
public: Direct plus Friends plus accessible via URL for sharing.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string
|
Label for the model |
||
glb |
File
|
Blob
|
the 3D model file |
||
icon |
File
|
Blob
|
<optional> |
optional 2d image preview for the model |
|
privacy |
string
|
<optional> |
direct | 'direct', 'friends', or 'public' |
to |
Array.<string>
|
<optional> |
Addressees. Accepts Immers handles (username[domain.name]) and ActivityPub IRIs |
# sendVideo(video, privacy, toopt) → {Promise.<string>}
Upload and/or share a video.
When video is a File/Blob, it will be uploaded to the user's home immer
and shared. The name
attribute is optional, but type
must contain the
correct MIME. When video is a url, an existing video is shared without
re-uploading. It's better to upload a file so that the user's home
immer can ensure it remains available.
Privacy level determines who receives and can access the message.
direct: Only those named in to
receive the message.
friends: Direct plus friends list.
public: Direct plus Friends plus accessible via URL for sharing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
video |
File
|
Blob
|
string
|
Video data to upload or url to share |
|
privacy |
string
|
'direct', 'friends', or 'public' |
|
to |
Array.<string>
|
<optional> |
Addressees. Accepts Immers handles (username[domain.name]) and ActivityPub IRIs |
Url of newly posted message
Promise.<string>
# async unblockUser(handle)
Remove someone to this immerser's blocklist. Messages will once again be sent & received between users and past messages from before the block will be visible again in feeds and friends lists.
Parameters:
Name | Type | Description |
---|---|---|
handle |
string
|
the target user's immers handle or profile id |
# updateProfileInfo(info)
Update user's profile description
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
info |
object
|
||
displayName |
string
|
<optional> |
User's preferred shorthand identifier, may contain spaces & symbols |
bio |
string
|
<optional> |
Summary paragraph displayed on user profile |
# async useAvatar(avatar) → {Promise.<string>}
Update user's avatar in their profile.
Parameters:
Name | Type | Description |
---|---|---|
avatar |
object
|
string
|
Model type object or id for one (or activity containing the model as its object) |
IRI of profile update activity
Promise.<string>
# async waitUntilConnected() → {Promise.<true>}
Utility method to hide details for checking if user is logged in or waiting util they have before performing actions that require a logged-in user
Promise.<true>
Example
await client.waitUntilConnected()
client.sendChatMessage('Hey friends, I am connected!', 'friends')
# static DestinationFromPlace(place) → {Destination}
Extract a Destination from a place object
Parameters:
Name | Type | Description |
---|---|---|
place |
Activities.APPlace
|
# static FriendStatusFromActivity(activity) → {FriendStatus}
Extract friend status information from their most recent location activity
Parameters:
Name | Type | Description |
---|---|---|
activity |
Activities.APActivity
|
# static FriendsSorter(a, b)
Array.sort compareFunction to sort a friends list putting online friends at the top and the rest by most recent update
Parameters:
Name | Type | Description |
---|---|---|
a |
FriendStatus
|
|
b |
FriendStatus
|
# static MessageFromActivity(activity) → {Message|null}
Extract a Message from an activity object
Parameters:
Name | Type | Description |
---|---|---|
activity |
Activities.APActivity
|
Message
|
null
# static ProfileFromActor(actor) → {Profile}
Convert ActivityPub Actor format to Immers profile
Parameters:
Name | Type | Description |
---|---|---|
actor |
Activities.APActor
|
ActivityPub Actor object |
# static URLFromProperty(prop) → {string|undefined}
Links in ActivityPub objects can take a variety of forms. Find and return the URL string.
Parameters:
Name | Type | Description |
---|---|---|
prop |
Activities.APObject
|
object
|
string
|
URL string, if present
string
|
undefined