Constructor
new Webcom(app, configopt)
Constructs a Webcom
instance, which represents a particular location in the data tree of a Webcom
application, which is specified by the app
parameter.
Reading data is done using on()
and once()
methods.
Writing data is done using set()
, push()
, update()
and remove()
methods.
Browsing the data tree is done using Query#child
, Query#parent
or
Query#root
methods. See Browse data for more details.
Internally, a Webcom
instance opens a web-socket connection to the Webcom back end for the requested
application, unless the {goOnline:false}
option is passed to the constructor.
All Webcom
instances on the same application share the same web-socket connection as well as the same
authentication state. Consequently, you cannot authenticate several users on the same application.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
app |
string | WebcomApp | The Webcom application, which this instance of |
|||||||||||||||||||||||||||||||||||||||||
config |
<optional> |
Configuration options. Note that these options are taken into account only on the first call to
the Properties
|
- Deprecated:
- Since 3.0 - Use
Webcom.App
instead.
- Since 3.0 - Use
Extends
Members
(static, constant) Authentication :Authentication.API
Gets the entry point for accessing all relevant constants and functions related to the Authentication
service.
Type:
- Since:
- 3.5
(static) Constraint :ServerlessDb.Constraint
Convenient link to the ServerlessDb.Constraint
class. This property is intended to access the
static members None
,
First
, Last
,
StartAt
, EndAt
and
Between
to build instances of this class.
Type:
- Since:
- 3.0
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
(static, constant) Event :ServerlessDb.EventDescriptor
Convenient link to the ServerlessDb.EventDescriptor
class. This property is intended to access the
ServerlessDb.EventDescriptor.ValueChange
and ServerlessDb.EventDescriptor.Child
static members to build instances of this class.
Type:
- Since:
- 2.10
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
(static, constant) FORGET :ServerlessDb.FORGET
Gets the ServerlessDb.FORGET
constant.
Type:
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
(static, constant) KEEP :ServerlessDb.KEEP
Gets the ServerlessDb.KEEP
constant.
Type:
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
(static, constant) KEEP_UPDATING :ServerlessDb.KEEP_UPDATING
Gets the ServerlessDb.KEEP_UPDATING
constant.
Type:
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
(static, constant) Log :LogManager
Gets the LogManager
API to control logs produced by the Webcom SDK.
Type:
- Since:
- 2.11
(static, constant) NEXT_DISCONNECTION :ServerlessDb.NEXT_DISCONNECTION
Gets the ServerlessDb.NEXT_DISCONNECTION
constant.
Type:
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
(static, constant) NOW :ServerlessDb.NOW
Gets the ServerlessDb.NOW
constant.
Type:
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
(static, constant) ON_DISCONNECTION :ServerlessDb.ON_DISCONNECTION
Gets the ServerlessDb.ON_DISCONNECTION
constant.
Type:
- Since:
- 3.3
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
(static, constant) SDK_VERSION :string
Version of the current Webcom SDK.
Type:
- string
(static, constant) ServerlessDb :ServerlessDb.API
Gets the entry point for accessing all relevant constants and functions related to the ServerlessDb
service.
Type:
- Since:
- 3.5
(static, constant) ServerValue :Object
Dictionary of special objects intended to be replaced by a value computed by the Webcom back end when
written into a ServerlessDb.ServerlessDbNode
:
- the
TIMESTAMP
property gives a value that will be replaced with the actual timestamp of the Webcom back end.
Type:
- Object
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
(readonly) authenticator :Authentication
Authentication service that manages this instance.
Type:
- Overrides:
- Deprecated:
- Since 3.0 - Use
WebcomApp#authentication
instead.
- Since 3.0 - Use
authState :Authentication.State
Returns the current authentication state based on the Webcom Authentication Service model.
Type:
- Since:
- 2.8
- Deprecated:
- Since 2.11 -Use the
currentState
property ofQuery#authenticator
instead.
- Since 2.11 -Use the
(readonly) datasync :ServerlessDb
ServerlessDb service that manages this instance.
Type:
- Overrides:
- Deprecated:
- Since 3.0 - Use
WebcomApp#serverlessDb
instead.
- Since 3.0 - Use
Methods
(static) App(appId, configopt) → {WebcomApp}
Creates an instance of WebcomApp
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
appId |
string | The identifier of the Webcom application the |
|
config |
WebcomApp.Configuration | string |
<optional> |
Configuration of the
A simpler configuration may be provided as a string representing the base URL of the targeted hosting
Webcom platform (following the syntax: If not set, an empty |
- Since:
- 2.8
Returns:
- Type
- WebcomApp
(static) avatarURL(user) → {string|undefined}
Gets the user's avatar URL (if known) from the identity referred to by an authentication state.
Parameters:
Name | Type | Description |
---|---|---|
user |
Authentication.AuthenticationDetails | The authentication details of the user (can be found in authentication state objects). |
- Since:
- 2.8
- Deprecated:
- Since 3.5 - Moved to
Webcom.Authentication
.
- Since 3.5 - Moved to
Returns:
the user's avatar URL if known or undefined
otherwise
- Type
- string | undefined
(static) Callback(callback, cancelationPolicyopt) → {ServerlessDb.Callback}
Creates an instance of ServerlessDb.Callback
notification channel, which is intended to be
registered with the ServerlessDb.ServerlessDbNode#subscribe
method and to receive notifications of data changes in
real time (through the ServerlessDb
websocket).
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callback |
ServerlessDb.SubscriptionCallback | The function that will receive notifications each time the subscribed event is raised. |
||
cancelationPolicy |
ServerlessDb.FORGET | ServerlessDb.KEEP | ServerlessDb.KEEP_UPDATING |
<optional> |
ServerlessDb.KEEP | The policy to apply on the local cache when the corresponding subscription will end. |
- Since:
- 3.0
- Deprecated:
- Since 3.5 - Moved to
Webcom.ServerlessDb
.
- Since 3.5 - Moved to
Returns:
(static) pushIdToDateTime(id) → {number}
Retrieves the date time associated with a node identifier generated by the Webcom#push
method.
If the given identifier is not generated by the Webcom#push
method, the result is indeterminate,
generally a negative number.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The identifier, which to retrieve the date from. |
- Since:
- 2.8
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#timestamp
instead.
- Since 3.0 - Use
Returns:
The date time associated with the given identifier, expressed in milliseconds since Unix Epoch.
- Type
- number
(static) Webhook(identifier, context) → {ServerlessDb.Webhook}
Creates an instance of ServerlessDb.Webhook
notification channel, which is intended to be
registered with the ServerlessDb.ServerlessDbNode#subscribe
method.
Parameters:
Name | Type | Description |
---|---|---|
identifier |
string | The identifier of webhook defined in the Webcom developer console, which will be targeted by all further events notified to this target. |
context |
string | A customized string, which will be attached to all further events notified to this target. |
- Since:
- 2.10
Returns:
- Type
- ServerlessDb.Webhook
addAccount(provider, details, messageopt) → {Promise}
Creates a new identity managed by the Webcom Authentication Service.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
provider |
string | The internal provider to use to create the identity. Currently, only |
|||||||||||||||||||||
details |
Object | The details associated with the identity to create. Properties
|
|||||||||||||||||||||
message |
Object |
<optional> |
The parameters to apply to the verification message to be sent to the user. Properties
|
- Since:
- 2.6.2
- Deprecated:
- Since 2.8 - Use
Webcom#addIdentity
instead.
- Since 2.8 - Use
Returns:
A promise that will be resolved once the identity creation successfully completed. In case of
success (reps. failure), the resolve (resp. reject) callback is called with one argument filled with the
same value as the auth
(resp. error
) parameter of
authentication callbacks.
Note that the just created identity is in the "unverified" state and cannot be used to sign a user in until it
is verified. To do so, the user will receive a token or a code on the specified email address or MSISDN, which
must be passed back to the Webcom#verifyIdentity
method.
- Type
- Promise
addAuthCallback(callback) → {Authentication.authCallback}
Adds an authentication callback function to the set of functions that watch changes of the authentication state. This function will be (asynchronously) called with the current authentication state, and then each time the authentication state changes.
Parameters:
Name | Type | Description |
---|---|---|
callback |
Authentication.authCallback | the callback function to add. |
- Since:
- 2.8
- Deprecated:
- Since 3.0 - Use
Authentication#subscribe
instead.
- Since 3.0 - Use
- See:
Returns:
the added callback function. Note that it is useful to keep a
reference on this function as soon as you need to remove it from the subscribed functions using the
Webcom#removeAuthCallback
method.
addIdentity(provider, details, messageopt) → {Promise}
Creates a new identity managed by the Webcom Authentication Service.
If the Webcom#useCurrentContextForNextAuthOperation
method is called just before this method, then the
new identity is bound to the Webcom account of the currently authenticated user. Otherwise, or if no user
is currently authenticated, the new identity is bound to a new Webcom account (to be created at the same
time).
Currently, Webcom is able to manage email- and phone-based identities.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
provider |
string | The internal provider to use to create the identity. Currently, only |
|||||||||||||||||||||
details |
Object | The details associated with the identity to create. Properties
|
|||||||||||||||||||||
message |
Object |
<optional> |
The parameters to apply to the verification message to be sent to the user. Properties
|
- Since:
- 2.8
- Deprecated:
- Since 3.0 - Use
Authentication#addIdentity
instead.
- Since 3.0 - Use
- See:
Returns:
A promise that will be resolved once the identity creation successfully completed. In case of
success (reps. failure), the resolve (resp. reject) callback is called with one argument filled with the
same value as the auth
(resp. error
) parameter of
authentication callbacks.
Note that the just created identity is in the "unverified" state and cannot be used to sign a user in until it
is verified. To do so, the user will receive a token or a code on the specified email address or MSISDN, which
must be passed back to the Webcom#verifyIdentity
method.
- Type
- Promise
auth(cred, onCompleteopt)
Authenticates the user using a (already available) Webcom authentication token.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
cred |
string | The Webcom authentication token to use |
|
onComplete |
Authentication.authCallback |
<optional> |
Callback function to be called when the authentication completes. |
- Deprecated:
- Since 1.3.2 - Use
authWithToken()
instead.
- Since 1.3.2 - Use
authAnonymously(onCompleteopt) → {Promise}
Authenticates the user using a temporary account (to be lost at next sign out or at authentication token expiration) with no explicit credentials.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
onComplete |
Authentication.authCallback |
<optional> |
Callback function to be called when the authentication
completes. |
- Since:
- 1.1
- Deprecated:
- Since 3.0 - Use
Authentication#signInAsGuest
instead.
- Since 3.0 - Use
- See:
Returns:
The authentication is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. The resolve (resp. reject) callback
is called with one argument filled with the same value as the auth
(resp. error
) parameter of
authentication callbacks.
- Type
- Promise
authInternally(provider, credentials) → {Promise}
Authenticates the user using a given Webcom internally managed authentication method among:
- Email-based authentication, with a personal password,
- Phone-base authentication, with a one time password (OTP). In this case, an OTP must be sent to the user
beforehand using the
Webcom#sendOtp
method and the returned challenge identifier must be kept (see thecredentials.challenge
parameter).
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
provider |
string | The authentication method to use: |
||||||||||||||||
credentials |
Object | The user's credentials. Their content depends on the chosen authentication method. Properties
|
- Since:
- 2.8
- Deprecated:
- Since 3.0 - Use
Authentication#signInWithCredentials
instead.
- Since 3.0 - Use
- See:
Returns:
The authentication is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. The resolve (resp. reject) callback
is called with one argument filled with the same value as the auth
(resp. error
) parameter of
authentication callbacks.
- Type
- Promise
authWithCustomProvider(provider, credentials, onCompleteopt) → {Promise}
Authenticates the user using credentials provided by a third-party ad-hoc identity provider.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
provider |
string | Identifier of the custom provider to use. |
|
credentials |
string | Credentials for the user to authenticate, to be supplied by the 3rd-party identity provider. |
|
onComplete |
Authentication.authCallback |
<optional> |
Callback function to be called when the authentication
completes. |
- Since:
- 2.2.2
- Deprecated:
- Since 3.0 - Use
Authentication#signInWithCustomProvider
instead.
- Since 3.0 - Use
- See:
Returns:
The authentication is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. The resolve (resp. reject) callback
is called with one argument filled with the same value as the auth
(resp. error
) parameter of
authentication callbacks.
- Type
- Promise
authWithOAuth(provider, optionsopt, onCompleteopt) → {Promise}
Authenticates the user using a 3rd-party OAuth2 provider.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
provider |
string | The OAuth2 provider to use. Please refer to Login with OAuth2.0 for more details. Currently, supported providers are:
|
||||||||||||||||||||||||||
options |
Object |
<optional> |
The authentication options to use, with the following properties: Properties
|
|||||||||||||||||||||||||
onComplete |
Authentication.authCallback |
<optional> |
Callback function to be called when the authentication
completes. |
- Since:
- 1.3
- Deprecated:
- Since 3.0 - Use
Authentication#signInWithOAuth
instead.
- Since 3.0 - Use
- See:
Returns:
The authentication is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. The resolve (resp. reject) callback
is called with one argument filled with the same value as the auth
(resp. error
) parameter of
authentication callbacks.
- Type
- Promise
authWithPassword(credentials, onCompleteopt) → {Promise}
Authenticates the user using her⋅his email and personal password.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
credentials |
Object | The user's credentials. Properties
|
||||||||||
onComplete |
Authentication.authCallback |
<optional> |
Callback function to be called when the authentication
completes. |
- Deprecated:
- Since 2.8 - Use
Webcom#authInternally
instead.
- Since 2.8 - Use
Returns:
The authentication is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. The resolve (resp. reject) callback
is called with one argument filled with the same value as the auth
(resp. error
) parameter of
authentication callbacks.
- Type
- Promise
authWithPhone(credentials) → {Promise}
Authenticates the user using her⋅his MSISDN and a one time password
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
credentials |
Object | The user's credentials. Properties
|
- Since:
- 2.6.2
- Deprecated:
- Since 2.8 - Use
Webcom#authInternally
instead.
- Since 2.8 - Use
Returns:
The authentication is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. The resolve (resp. reject) callback
is called with one argument filled with the same value as the auth
(resp. error
) parameter of
authentication callbacks.
- Type
- Promise
authWithToken(token, onCompleteopt) → {Promise}
Authenticates the user using a (already available) Webcom authentication token. This method is mainly intended for Node.js back end applications.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
token |
string | The Webcom authentication token to use |
|
onComplete |
Authentication.authCallback |
<optional> |
Callback function to be called when the authentication
completes. |
- Since:
- 1.3
- Deprecated:
- Since 3.0 - Use
Authentication#signInWithToken
instead.
- Since 3.0 - Use
Returns:
The authentication is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. The resolve (resp. reject) callback
is called with one argument filled with the same value as the auth
(resp. error
) parameter of
authentication callbacks.
- Type
- Promise
authWithWassup(options, onCompleteopt) → {Promise}
Authenticates the user implicitly based on the Orange Wassup Translator service. This method works only for mobile devices connected through the Orange mobile data network. It is rather intended to Webcom mobile SDKs, it should not be needed in pure JavaScript applications.
Parameters:
Name | Type | Attributes | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
options |
The authentication options to use, with the following properties: Properties
|
||||||||
onComplete |
Authentication.authCallback |
<optional> |
Callback function to be called when the authentication
completes. |
- Since:
- 1.4
- Deprecated:
- Since 3.0 - Use
Authentication#signInWithWassup
instead.
- Since 3.0 - Use
- See:
Returns:
The authentication is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. The resolve (resp. reject) callback
is called with one argument filled with the same value as the auth
(resp. error
) parameter of
authentication callbacks.
- Type
- Promise
changePassword(email, oldPassword, newPassword, onCompleteopt) → {Promise}
Changes the password of an existing email-based identity.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
email |
string | The email of the identity, the password of which has to be updated |
|
oldPassword |
string | The current password of the identity |
|
newPassword |
string | The new password to set |
|
onComplete |
Authentication.authCallback |
<optional> |
A 1-argument callback function that is called after the
password change completion, which receives an |
- Deprecated:
- Since 3.0 - Use
Authentication#updatePassword
instead.
- Since 3.0 - Use
Returns:
- Type
- Promise
child(pathString) → {Webcom}
Gets a Webcom
instance that refers to a specific data node within the application data tree, specified as
a relative path to the data node referred to by this Query
instance.
Parameters:
Name | Type | Description |
---|---|---|
pathString |
string | Data path, relative to the location of this
|
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#relativeNode
instead.
- Since 3.0 - Use
Returns:
A Webcom
instance that refers to the specified path.
- Type
- Webcom
Example
// Get a reference to the "friends" data node
var ref = new Webcom("contacts").child("friends");
var johnRef = ref.child("john");
console.log(johnRef.name());
// ==> "/https/io.datasync.orange.com/contacts//friends/john"
var maryRef = ref.child("/mary");
console.log(maryRef.toString());
// ==> "/https/io.datasync.orange.com/contacts//friends/mary"
var maryRef2 = johnRef.child("../mary");
console.log(maryRef2.toString());
// ==> "/https/io.datasync.orange.com/contacts//friends/mary"
var nameThenLastRef = johnRef.child("name").child("last");
console.log(nameThenLastRef.toString());
// ==> "/https/io.datasync.orange.com/contacts//friends/john/name/last"
var lastNameRef = johnRef.child("name/last");
console.log(lastNameRef.toString());
// ==> "/https/io.datasync.orange.com/contacts//friends/john/name/last"
var rootRef = ref.child("../..");
console.log(rootRef.toString());
// ==> "/https/io.datasync.orange.com/contacts/"
var hashedRef = ref.child("#john");
console.log(hashedRef.toString());
// ==> "/https/io.datasync.orange.com/contacts//friends/.list.pR/3a/fH/john"
createUser(details, onCompleteopt) → {Promise}
Creates a new Webcom account bound to an email/password identity.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
details |
Object | The details associated with the account to create. Properties
|
|||||||||||||||||
onComplete |
Authentication.authCallback |
<optional> |
Callback function to be called when the account
creation completes. |
- Deprecated:
- Since 2.7 - Use
addAccount()
instead.
- Since 2.7 - Use
Returns:
The account creation is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. The resolve (resp. reject) callback
is called with one argument filled with the same value as the auth
(resp. error
) parameter of
authentication callbacks.
- Type
- Promise
endAt(nameopt) → {Query}
Creates a Query object that returns children beginning at a specific ending point.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string |
<optional> |
The child name to end at |
- Since:
- 2.2
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.Constraint.EndAt
orServerlessDb.Constraint.Between
instead.
- Since 3.0 - Use
Returns:
- Generated query
- Type
- Query
Example
// Get a reference to friends
var ref = new Webcom("/base/contacts/friends");
// Display friends whose names (keys) come before john
ref.endAt("john").on("value", function(snapshot){
console.log(snapshot.val());
});
equalTo(nameopt) → {Query}
Creates a Query object that returns children matching a specific value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string |
<optional> |
The child name to match for. |
- Since:
- 2.2
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.Constraint.Between
instead.
- Since 3.0 - Use
Returns:
- Generated query
- Type
- Query
Example
// Get a reference to friends
var ref = new Webcom("/base/contacts/friends");
// Display friends whose names (keys) is exactly john
ref.equalTo("john").on("value", function(snapshot){
console.log(snapshot.val());
});
get() → {Promise.<ServerlessDb.DataSnapshot>}
Gets the data at the data node referred to by this Query
instance.
This method works asynchronously. It will actually involve an exchange with the Webcom back end only if the requested data are not in the local cache.
- Since:
- 2.14
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#get
instead.
- Since 3.0 - Use
Returns:
A promise that will be resolved with the read data.
- Type
- Promise.<ServerlessDb.DataSnapshot>
Example
// Get a reference on the "friends" node of the "contacts" application
const friendsNode = new Webcom("contacts").child("friends");
// Read the value of this node
friendsNode.get()
.then(data => {
console.log("The 'friends' data are:", JSON.stringify(data.val()));
console.log("They are", data.acknowledged() ? "acknowledged" : "not yet acknowledged", "by the back end");
})
.catch(error => console.log("Could not read data:", error.message);
getCache() → {ServerlessDb.DataSnapshot}
Returns (synchronously) the value stored in the local cache at the data node represented by this Query
instance.
The returned value is of the same type as the one passed to watch callbacks
.
- Since:
- 2.15
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#getCache
instead.
- Since 3.0 - Use
Returns:
goOffline()
Forces disconnection of the websocket managed by this Webcom
instance from the Webcom server and
disables the retry connection feature. The websocket will be not re-established until Webcom#goOnline
is
called.
- Deprecated:
- Since 2.11 - Use
ServerlessDb#disconnect
instead.
- Since 2.11 - Use
goOnline()
Force reconnection of the websocket managed by this Webcom
instance to the Webcom server and enables
the retry connection feature.
- Deprecated:
- Since 2.11 - Use
ServerlessDb#connect
instead.
- Since 2.11 - Use
increment(step, startValueopt) → {Promise.<number>}
Atomically increments the value at the data node referred to by this Webcom
instance.
"Atomically" means that this operation is robust to concurrent increment operations by many clients. It is
guaranteed that if n clients perform an increment at the same time, then the value of the data node ends in
being incremented by n×step
, that is, none of the concurrent operations can overwrite one another.
If the data node has no value, then the increment acts as if it equals the given startValue
.
If the data node has a non-numeric value, then the increment fails.
If you need to perform a more complex operation in an atomic way, use the Webcom#transaction
method.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
step |
number | The step to add to the current data node value. |
||
startValue |
number |
<optional> |
0 | The default starting value of the data node if it has no value when the increment is performed. |
- Since:
- 2.13
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#increment
instead.
- Since 3.0 - Use
Returns:
The resulting value of the increment operation.
Note that the returned value may not be synchronized with the actual value of the data node, especially if
other clients perform write operations at the same time. Use rather subscriptions
to watch
the actual value of a data node.
- Type
- Promise.<number>
limit(lim) → {Query}
Create Query object to limit the number of children.
Parameters:
Name | Type | Description |
---|---|---|
lim |
number | Number of items |
- Since:
- 2.2
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.Constraint.First
orServerlessDb.Constraint.Last
instead.
- Since 3.0 - Use
Returns:
new limited Query
object.
- Type
- Query
Examples
Last
// Get a reference to friends
var ref = new Webcom("/base/contacts/friends");
var lastFriends = ref.endAt().limit(5);
// Display the 5 last friends
lastFriends.on("value", function(snapshot){
console.log(snapshot.val());
});
First
// Get a reference to friends
var ref = new Webcom("/base/contacts/friends");
var lastFriends = ref.startAt().limit(5);
// Display the 5 first friends
lastFriends.on("value", function(snapshot){
console.log(snapshot.val());
});
First starting at some key
// Get a reference to friends
var ref = new Webcom("/base/contacts/friends");
var lastFriends = ref.startAt("john").limit(5);
// Display friends whose names (keys) come after john display the following 5
lastFriends.on("value", function(snapshot){
console.log(snapshot.val());
});
logout(onCompleteopt) → {Promise}
Signs the currently authenticated user out.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
onComplete |
function |
<optional> |
A 1-argument callback function that is called after the log-out, which receives
an |
- Deprecated:
- Since 3.0 - Use
Authentication#signOut
instead.
- Since 3.0 - Use
Returns:
A promise that will be resolved (with no value) once the user is properly signed out.
- Type
- Promise
name() → (nullable) {string}
Returns the name of the data node this Query
instance refers to.
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#key
instead.
- Since 3.0 - Use
Returns:
The name of the data node or null
if this instance refers to the root node of the
application.
- Type
- string
Example
// Get a reference to the "john" data node
var ref = new Webcom("contacts").child("friends/john");
console.log(ref.name());
// ==> "john"
console.log(ref.child("name").name());
// ==> "name"
console.log(ref.root().name());
// ==> null
off(eventTypesopt, callbackopt, contextopt)
Unwatches data changes at the data node referred to by this Query
instance.
It actually unregisters a callback function (or all ones) previously registered on the data node referred to
by this Query
instance using the Query#on
method.
As a side effect, all data previously watched will be removed from the local cache. If you want to keep these
data in the local cache in order to work offline for example, use the Query#offPreservingOfflineData
method instead.
Note: unregistering all callback functions attached to a data node doesn't unregister callback functions
attached to its child nodes. The Query#off
method must be called on all the data nodes that the
Query#on
method has been called on.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eventTypes |
string | Array.<string> |
<optional> |
The type of event to unwatch. It can be either a single value among
|
callback |
Query~watchCallback |
<optional> |
Reference to the callback function to unregister (previously passed
to or returned by the |
context |
Object |
<optional> |
Context object for callback binding, passed to previous call to
|
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#unsubscribe
instead.
- Since 3.0 - Use
Examples
Unregister a single callback
// Get a reference to the "friends" node of the "contacts" application
var ref = new Webcom("contacts").child("friends");
var onChange = ref.on("value", function(snapshot) {
// your handler
});
// later...
ref.off("value", onChange);
Unregister several callbacks
// Get a reference to the "friends" node of the "contacts" application
var ref = new Webcom("contacts").child("friends");
var onChanged = function(snapshot) {
// your first handler
});
var onAdded = function(snapshot) {
// your second handler
});
ref.on("value", onChanged);
ref.on("child_added", onAdded);
// later...
// Unregister all callback functions from ref...
ref.off();
// ...or all callback function associated to a specific kind of event
ref.off("value"); // onChanged is unregistered while onAdded remains registered
offPreservingOfflineData(eventTypesopt, callbackopt, contextopt)
Unwatches data changes at the data node referred to by this Query
instance, similarly to the
Query#off
method. The difference is that this method additionally preserves the previously watched
data within the local cache and maintains them up-to-date.
As a consequence, unwatched data remain available if the network becomes down, and it is possible to use them offline. As soon as the network becomes up, they will be automatically re-synchronised.
In order to definitely remove some unwatched data from the local cache, use the
ServerlessDb#cleanOfflineData
method.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eventTypes |
string | Array.<string> |
<optional> |
The type of event to unwatch. It can be either a single value among
|
callback |
Query~watchCallback |
<optional> |
Reference to the callback function to unregister (previously passed
to or returned by the |
context |
Object |
<optional> |
Context object for callback binding, passed to previous call to
|
- Since:
- 2.11
- Overrides:
- Deprecated:
- Since 2.15 - Make
the completion callbacks
passed to theQuery#on
function returnQuery.KEEP_UPDATING
.
- Since 2.15 - Make
on(eventTypes, callback, completionCallbackopt, contextopt) → {Query~watchCallback}
Watches data changes at the data node referred to by this Query
instance.
It actually registers a callback function on the data node referred to by this Query
instance
for a given type of event to watch or a given set of types of events to watch.
The specified callback may be called initially (when the on
method is called) with respect to the data
currently stored at this node (depending on the requested event type). And then, it will be called whenever
the data change. The notifications can be stopped using the Query#off
method.
Several kinds of callback are available depending on the kind of event to watch:
-
value
eventThe callback is called initially once with the current data.
It is then called again each time the data (stored at this node or any sub-node) change.The
ServerlessDb.DataSnapshot
passed to the callback refers to the new data stored at the data node referred to by thisQuery
instance.
TheprevChildName
argument passed to the callback is not used and remains undefined. -
value_ack
eventThe callback is not initially called.
It is then called each time the value at this data node is acknowledged by the Webcom back end. Note that if both the value and the acknowledgement status change, then thevalue
event is raised instead.As with the
value
event, theServerlessDb.DataSnapshot
passed to the callback refers to the value of the data node and theprevChildName
is not used. -
child_added
eventThe callback is called initially once for each current child node of this node.
It is then called again each time a new data child is added to this node.The
ServerlessDb.DataSnapshot
passed to the callback refers to the new data stored at the corresponding child data node.
TheprevChildName
argument passed to the callback refers to the name of the sibling child node that precedes the added child node in the data tree structure (following key order), ornull
if the added child node is the first child of the data node referred to by thisQuery
instance. -
child_changed
eventThe callback is not initially called.
It is then called each time the value of one of the data children changes (excluding child additions and removals).The
ServerlessDb.DataSnapshot
passed to the callback refers to the new data stored at the corresponding child data node.
TheprevChildName
argument passed to the callback refers to the name of the sibling child node that precedes the changed child node in the data tree structure (following key order), ornull
if the changed child node is the first child of the data node referred to by thisQuery
instance. -
child_removed
eventThe callback is not initially called.
It is then called each time one of the data children is removed (or its value becomesnull
or it loses all of its children).The
ServerlessDb.DataSnapshot
passed to the callback refers to the old data stored at the corresponding child data node.
TheprevChildName
argument passed to the callback is not used and remains undefined. -
child_ack
eventThe callback is not initially called.
It is then called the value of a child of this data node is acknowledged by the Webcom back end. Note that if both the value and the acknowledgement status of the child change, then one of thechild_added
,child_removed
orchild_changed
events is raised instead.The
ServerlessDb.DataSnapshot
passed to the callback refers to the value of the child node.
TheprevChildName
argument passed to the callback is not used and remains undefined.
Note: data is first synchronized locally, so that if you set (using the set()
method)
some data locally after registering a watch callback, this callback will be called immediately. Later, when the
synchronization with the server occurs, the callback will be possibly called again for acknowledgement
notification, data update, or even for data deletion if the synchronization fails.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eventTypes |
string | Array.<string> | The type of event to watch. It can be either a single value among |
|
callback |
Query~watchCallback | Callback function called when one of the watched events is raised. |
|
completionCallback |
Query~completionCallback |
<optional> |
Callback function called when the data node is no longer
watched. This can result from either a cancelation from the app (by calling the |
context |
Object |
<optional> |
Context object for binding of the callback functions |
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#subscribe
instead.
- Since 3.0 - Use
Returns:
A reference to the callback function provided in the callback
parameter. It
is intended to be passed to the Query#off
method, especially when the callback
parameter is given as
an inline function.
- Type
- Query~watchCallback
Examples
Value
// Get a reference to the "friends" node of the "contacts" application
var ref = new Webcom("contacts").child("friends");
// This callback is called only when some data change under the "friends" node
ref.on("value", function(snapshot) {
console.log("New friends value is: " + JSON.stringify(snapshot.val()));
});
Child Added
// Get a reference to the "friends" node of the "contacts" application
var ref = new Webcom("contacts").child("friends");
// This callback is called only when a new child is added to the "friends" node
ref.on("child_added", function(snapshot, prevChildName) {
console.log("New child for friends: " + snapshot.name() + " -> " + JSON.stringify(snapshot.val()));
if (prevChildName) {
console.log("This new child comes after " + prevChildName);
} else {
console.log("This new child is the only one");
}
});
Child Changed
// Get a reference to the "friends" node of the "contacts" application
var ref = new Webcom("contacts").child("friends");
// This callback is called only when the value of an existing child of the "friends" node changes
ref.on("child_changed", function(snapshot, prevChildName) {
console.log("The " + snapshot.name() + " child has changed value to: " + JSON.stringify(snapshot.val()));
if (prevChildName) {
console.log("This child comes after " + prevChildName);
} else {
console.log("This child is the only one");
}
});
Child Removed
// Get a reference to the "friends" node of the "contacts" application
var ref = new Webcom("contacts").child("friends");
// This callback is called only when a child of the "friends" node is removed
ref.on("child_removed", function(snapshot) {
console.log("The " + snapshot.name() + " child has been removed, its value was: " +
JSON.stringify(snapshot.val()));
});
once(eventTypes, callback, cancelCallbackopt, contextopt)
Watches the next data change at the data node referred to by this Query
instance.
This method is similar to Query#on
, except it automatically unregisters the given callback
function from the data node referred to by this Query
instance as soon as it is called.
In other words, the given callback function will be called no more than once.
With the "value"
event type, this method makes it possible to read (asynchronously) the data stored at a given
data node. Other event types are useless with this method.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eventTypes |
string | Array.<string> | The type of event to watch. Although the same event types as for the
|
|
callback |
Query~watchCallback | Callback function called when the specified event occurs. |
|
cancelCallback |
Query~completionCallback |
<optional> |
Callback function called when the authenticated user loses
read permission at the data node referred to by this
|
context |
Object |
<optional> |
Context object for callback binding |
- Overrides:
- Deprecated:
- Since 2.14 - Use
Query#get
instead.
- Since 2.14 - Use
Examples
// Get a reference to the "friends" node of the "contacts" application
var ref = new Webcom("contacts").child("friends");
// Read the value of the "friends" node
ref.once("value", function(snapshot) {
console.log("The value of the " + snapshot.name() + " node is: " + JSON.stringify(snapshot.val()));
});
// Get a reference to the "friends" node of the "contacts" application
var ref = new Webcom("contacts").child("friends");
// Check the read permission on the "friends" node
ref.once("value", function() {}, function(error) {
console.log("Insufficient read permission");
});
onDisconnect() → {OnDisconnect}
Gets an instance of OnDisconnect
, which refers to the data node referred to by this
Webcom
instance.
- Deprecated:
- Since 3.0 - Use the "write policy" parameter of the
ServerlessDb.ServerlessDbNode#set
,ServerlessDb.ServerlessDbNode#merge
andServerlessDb.ServerlessDbNode#clear
methods instead.
- Since 3.0 - Use the "write policy" parameter of the
Returns:
- Type
- OnDisconnect
parent() → {Webcom}
Gets a Webcom
instance that refers to the parent data node of the one referred to by this Query
instance.
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#parent
instead.
- Since 3.0 - Use
Returns:
A parent instance of this Query
instance or null
if the data node referred to by
this Query
instance has no parent.
- Type
- Webcom
Example
// Get a reference to the "friends" data node
var ref = new Webcom("contacts").child("friends");
var contactsRef = ref.parent();
console.log(contactsRef.toString());
// ==> "/https/io.datasync.orange.com/contacts/"
pathString() → {string}
Returns the path of the data node represented by this instance of Query
.
- Since:
- 2.6.2
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#path
instead.
- Since 3.0 - Use
Returns:
The path of this data node, with path levels separated by "/" (slashes)
- Type
- string
persist() → {boolean}
Persists the data currently stored in the client local cache.
This method has no effect if the Webcom
instance that first established the connection to the Webcom
server was created with the {persist: false}
option (in this case, the method returns false
).
This data will then be restored in a further client establishing its first connection to the Webcom server
passing the {persist: true}
option to the Webcom
constructor.
- Since:
- 2.6
- Deprecated:
- Since 3.0 - Use
ServerlessDb#persist
instead.
- Since 3.0 - Use
Returns:
true
if the data has been persisted or false
otherwise
- Type
- boolean
push(valueopt, onCompleteopt) → {Webcom}
Adds a new child at the data node referred to by this Webcom
instance.
Its key is automatically generated, so that it is unique and lexicographically ordered after any previously
generated key.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
Object | string | number | boolean | null |
<optional> |
The value of the new child to add. If not set, the new child is created without value. |
onComplete |
function |
<optional> |
A 2-argument callback function called after synchronization with the server. Its
fist argument is filled with an |
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#push
instead.
- Since 3.0 - Use
Returns:
A Webcom
instance referring to the added child.
- Type
- Webcom
ref() → {Webcom}
- Overrides:
- Deprecated:
- Since 3.0 - Use
WebcomApp#serverlessDb
instead.
- Since 3.0 - Use
Returns:
The Webcom
reference associated with this instance.
- Type
- Webcom
Example
// Get a reference to the "friends" data node
var ref = new Webcom("contacts").child("friends");
var query = ref.limit(2);
var refSameLocation = query.ref(); //ref === refSameLocation
registerAuthCallback(callback) → {Authentication.authCallback}
Adds an authentication callback function to the set of functions that watch changes of the authentication
state. Contrary to the Webcom#addAuthCallback
method, this method doesn't initially call the added
callback function with the current authentication state.
Parameters:
Name | Type | Description |
---|---|---|
callback |
Authentication.authCallback | the callback function to add. |
- Since:
- 2.1
- Deprecated:
- Since 2.8 - Use
Webcom#addAuthCallback
instead.
- Since 2.8 - Use
Returns:
the added callback function.
remove(onCompleteopt)
Removes data at the data node referred to by this Webcom
instance.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
onComplete |
function |
<optional> |
A 1-argument callback function called after synchronization with the server. Its
argument is filled with an |
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#clear
instead.
- Since 3.0 - Use
removeAccount() → {Promise}
Deletes the Webcom account associated with the currently authenticated identity. This method deletes also all the identities associated with this account. In order to succeed, this sensible operation requires a fresh authentication. If the current authentication token is too old, then the operation fails, in this case you have to refresh the user authentication by authenticating her⋅him afresh explicitly before renewing the operation.
- Since:
- 2.6.2
- Deprecated:
- Since 3.0 - Use
Authentication#removeAccount
instead.
- Since 3.0 - Use
- See:
Returns:
The identity deletion is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. In case of success, the resolve
callback is called with no argument. In case of failure, the reject callback is called with the reason of
the failure.
- Type
- Promise
removeAuthCallback(callbackopt) → {boolean}
Removes an authentication callback function from the set of functions that watch changes of the authentication state. As soon as this method returns, further changes of the authentication state will no longer result in calling the specified callback function(s).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
Authentication.authCallback |
<optional> |
the callback function to remove. Note that it must be a
reference to a function previously added with |
- Since:
- 2.8
- Deprecated:
- Since 3.0 - Use
Authentication#unsubscribe
instead.
- Since 3.0 - Use
- See:
Returns:
true
if the callback function to remove was found, or false
otherwise
- Type
- boolean
removeIdentity() → {Promise}
Deletes the currently authenticated identity. This method doesn't delete the associated Webcom account unless there is no other identity associated with it. In order to succeed, this sensible operation requires a fresh authentication. If the current authentication token is too old, then the operation fails, in this case you have to refresh the user authentication by authenticating her⋅him afresh explicitly before renewing the operation.
- Since:
- 2.6.2
- Deprecated:
- Since 3.0 - Use
Authentication#removeIdentity
instead.
- Since 3.0 - Use
- See:
Returns:
The identity deletion is performed asynchronously, and its result may be caught by assigning a
resolve and/or a reject callback to the returned Promise
. In case of success, the resolve
callback is called with no argument. In case of failure, the reject callback is called with the reason of
the failure.
- Type
- Promise
removeUser(email, password, onCompleteopt) → {Promise}
Removes an existing email-based identity.
Warning: this method doesn't remove the associated Webcom account.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
email |
string | The email of the identity to remove |
|
password |
string | The password of the identity to remove |
|
onComplete |
Authentication.authCallback |
<optional> |
A 1-argument callback function that is called after
the email/password identity removal, which receives an |
- Deprecated:
- Since 2.7 - Use
Webcom#removeAccount
orWebcom#removeIdentity
instead.
- Since 2.7 - Use
Returns:
- Type
- Promise
resume(callbackopt)
Resumes the authentication state (based on records from the local storage).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
Authentication.authCallback |
<optional> |
If set, registers additionally an authentication callback
function to be called each time the authentication state changes. |
- Deprecated:
- Since 2.8 - This method no longer needs to be called.
root() → {Webcom}
Gets a Webcom
instance that refers to the data tree root of current Webcom application.
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb#rootNode
instead.
- Since 3.0 - Use
Returns:
A Webcom
instance that refers to the root data node
- Type
- Webcom
Example
// Get a reference to the "john" data node
var ref = new Webcom("contacts").child("friends/john");
var rootRef = ref.root();
console.log(rootRef.toString());
// ==> "/https/io.datasync.orange.com/contacts/"
sendConfirmationEmail(email, onCompleteopt) → {Promise}
Sends an email with a link to confirm an email/password identity. This method is particularly useful when the
user has not received the initial confirmation email sent when creating her/his account (using the
Webcom#createUser
method).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
email |
string | The email address of the identity to confirm, which the email must be sent to |
|
onComplete |
Authentication.authCallback |
<optional> |
A 1-argument callback function that is called after the
sending of the confirmation email, which receives an |
- Deprecated:
- Since 2.7 - Use
Webcom#sendVerificationCode
instead.
- Since 2.7 - Use
Returns:
- Type
- Promise
sendOtp(provider, id, messageopt) → {Promise}
Sends a one time password (OTP) to a user through a given identity. This method is particularly useful before
calling the Webcom#authInternally
method, which may requires a temporary password to complete depending
on the chosen identity provider.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
provider |
string | The provider associated with the identity, which to send the OTP to. Currently, possible
values are |
|||||||||||||||||||||
id |
string | The identifier of the identity, which to send the OTP to |
|||||||||||||||||||||
message |
Object |
<optional> |
The parameters to apply to OTP message to be sent Properties
|
- Since:
- 2.6.2
- Deprecated:
- Since 3.0 - Use
Authentication#sendOtp
instead.
- Since 3.0 - Use
Returns:
A promise that will be resolved once the OTP successfully sent. In case of success, the
resolve callback is called with one parameter equal to the OTP identifier or challenge that has been sent
(given as a string). This identifier is required for further methods such as Webcom#authInternally
.
- Type
- Promise
sendPasswordResetCode(provider, id, messageopt) → {Promise}
Sends a code to the user, which allows her⋅him to reset her⋅his password for a given Webcom internally
manged identity. Currently, only email-based identities are supported (parameter provider
equal to
"password"
).
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
provider |
string | The internal provider of the identity, which to send the password reset code to.
Currently, only |
||||||||||||||||
id |
string | The identifier of the identity, which to send the password reset code to. |
||||||||||||||||
message |
<optional> |
The message template to use to send the password reset code Properties
|
- Since:
- 2.6.2
- Deprecated:
- Since 3.0 - Use
Authentication#sendPasswordResetCode
instead.
- Since 3.0 - Use
Returns:
A promise that is resolved once the password reset code has been sent
- Type
- Promise
sendPasswordResetEmail(email, onCompleteopt) → {Promise}
Sends an email to the user of an email/password identity, with a link to reset the associated password. This method is intended to be used when the user has lost her/his password.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
email |
string | The email of the identity to reset |
|
onComplete |
Authentication.authCallback |
<optional> |
A 1-argument callback function that is called after the
sending of the password reset email, which receives an |
- Deprecated:
- Since 2.7 - Use
Webcom#sendPasswordResetCode
instead.
- Since 2.7 - Use
Returns:
- Type
- Promise
sendVerificationCode(provider, id, messageopt) → {Promise}
Sends a code to the user, which makes it possible to verify one of her⋅his unverified identities internally managed by Webcom (i.e. email- and phone-based identities). This method fails on an already verified identity.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
provider |
string | The internal provider that manages the identity to verify. Current supported values are
|
|||||||||||||||||||||
id |
string | The identifier of the identity to verify. It is either an email address (for email-based identities) or a MSISDN without the "+" prefix (for phone-based identities). |
|||||||||||||||||||||
message |
<optional> |
The message template to use to send the verification code to the user Properties
|
- Since:
- 2.6.2
- Deprecated:
- Since 3.0 - Use
Authentication#sendVerificationCode
instead.
- Since 3.0 - Use
Returns:
A promise that will be resolved once the verification message successfully sent. In case of
success, the resolve callback is passed a "challenge" string that must be used to eventually verify the
identity using the Webcom#verifyIdentity
method
- Type
- Promise
set(valuenullable, onCompleteopt)
(Over)writes data at the data node referred to by this Webcom
instance.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
Object | string | number | boolean |
<nullable> |
The value to write. If it is an |
onComplete |
function |
<optional> |
A 1-argument callback function called after synchronization with the server. Its
argument is filled with an |
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#set
instead.
- Since 3.0 - Use
shouldBeOnline() → {boolean}
Returns the current expected state of the ServerlessDb websocket: true
if it should be online (whatever the
actual network state) or false
if it should be offline. The actual state of the ServerlessDb websocket may be
monitored by subscribing to the ".info/connected" virtual node using the on()
method.
- Since:
- 2.6.2
- Deprecated:
- Since 2.11 - Use
ServerlessDb#shouldBeConnected
instead.
- Since 2.11 - Use
Returns:
the current expected state of the ServerlessDb websocket
- Type
- boolean
startAt(nameopt, nullable) → {Query}
Creates Query object that returns children beginning at a specific starting point.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string |
<optional> <nullable> |
The child name to start at. If omitted or |
- Since:
- 2.2
- Overrides:
- Deprecated:
- Since 3.0 - Use
ServerlessDb.Constraint.StartAt
orServerlessDb.Constraint.Between
instead.
- Since 3.0 - Use
Returns:
Generated query
- Type
- Query
Example
// Get a reference to friends
var ref = new Webcom("/base/contacts/friends");
// Display friends whose names (keys) come after john
ref.startAt("john").on("value", function(snapshot){
console.log(snapshot.val());
});
subscribe(event, target) → {Promise.<ServerlessDb.Subscription>}
Subscribes to events that match a given description and are raised on the data node referred to by this
Webcom
instance. Such raised events will be notified to a given target. Currently, only
ServerlessDb.Webhook
targets are available, however additional ones may become available in
future versions.
This method requires to be authenticated. Read permissions required to watch specified data events will be evaluated in real-time by the Webcom back end according to the current authentication state at the time this method is called.
The resulting subscription may be further unsubscribed either by calling the
ServerlessDb.Subscription#cancel
method on the ServerlessDb.Subscription
instance
resolved by the Promise
returned by this method, or by calling the Webcom#unsubscribe
method
(which doesn't need further a reference to the ServerlessDb.Subscription
instance).
Parameters:
Name | Type | Description |
---|---|---|
event |
ServerlessDb.EventDescriptor | The descriptor of data events to subscribe to. Such
descriptors must be created using the |
target |
ServerlessDb.Webhook | The target that will be notified when subscribed data events are
raised on the current data node. Such targets must be created using the |
- Since:
- 2.10
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#subscribe
instead.
- Since 3.0 - Use
- See:
Returns:
The returned Promise
is resolved with a
ServerlessDb.Subscription
instance that represents the subscription created by this method.
This instance provides methods that make it possible to either cancel the subscription or update the
subscribed events.
- Type
- Promise.<ServerlessDb.Subscription>
toString() → {string}
Returns a string representation of this Webcom
instance as the absolute URL of the data node it
represents.
- Deprecated:
- Since 3.0 - No longer useful.
Returns:
- Type
- string
Example
// Get a reference to the "contacts" application
var ref = new Webcom("contacts");
console.log(ref.toString());
// ==> "/https/io.datasync.orange.com/contacts/"
var johnRef = ref.child("friends/john");
console.log(johnRef.toString());
// ==> "/https/io.datasync.orange.com/contacts//friends/john"
var alfredRef = ref.child("friends/alfred:54");
console.log(alfredRef.toString());
// ==> "/https/io.datasync.orange.com/contacts//friends/alfred%3A54"
transaction(transactionUpdate, onCompleteopt, optionsopt)
Writes data atomically within a transaction at the data node referred to by this Webcom
instance. This
means the data will be actually written only if the data node is not modified by another client during the
transaction. Otherwise, the transaction is retried (up to 25 times) until it can be completed safely without
conflict.
If the transactionUpdate
function consists in incrementing (or decrementing) the value of the data node, use
rather the Webcom#increment
method, which is more efficient in this case.
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
transactionUpdate |
function | A 1-argument function that receives the current value of the data node
and is expected to return either an undefined value to abort the transaction, or the new value to overwrite at
the data node. |
|||||||||||||||||
onComplete |
function |
<optional> |
A 3-argument function that is called after the transaction execution whatever its outcome (completed or aborted):
|
||||||||||||||||
options |
Object |
<optional> |
{} |
Properties
|
- Since:
- 1.1
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#runTransaction
instead.
- Since 3.0 - Use
Examples
Toggle the value of a data node between 2 constants
// Get a reference to the "john" data node
var ref = new Webcom("contacts").child("friends/john");
ref.child("busy").transaction(current => {
if (current) {
return false;
} else {
return true;
}
});
Write some data only if there is none
// Get a reference to the "john" data node
var ref = new Webcom("contacts").child("friends/john");
ref.transaction(current => {
if (current === null) { // there is no data at the "john" data node => set some
return {name: {first: "John", last: "Doe"}};
} else { // there is already some data => abort transaction
console.log("John already exists!");
return;
}
}, (error, committed, snapshot) => {
if (error) {
console.log("An unexpected error occurred:", error);
} else if (!committed) {
console.log("Transaction aborted (John already exists)");
} else {
console.log("Transaction completed (John added)");
}
console.log("John: " + JSON.stringify(snapshot));
});
unregisterAuthCallback(callbackopt) → {boolean}
Removes an authentication callback function from the set of functions that watch changes of the authentication state.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
Authentication.authCallback |
<optional> |
- Since:
- 2.1
- Deprecated:
- Since 2.8 - Use
Webcom#removeAuthCallback
instead.
- Since 2.8 - Use
Returns:
- Type
- boolean
unsubscribe(target, receivesRevocationsopt) → {Promise.<ServerlessDb.Subscription>}
Unsubscribes a given target from the data events previously subscribed to using the Webcom#subscribe
method.
This method requires to be authenticated with the same user as the one used with the Webcom#subscribe
method to create the subscription to cancel.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
target |
ServerlessDb.Webhook | The target that unsubscribes events. |
||
receivesRevocations |
boolean |
<optional> |
false | Indicates whether to receive the corresponding revocation. |
- Since:
- 2.10
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#unsubscribe
instead.
- Since 3.0 - Use
- See:
Returns:
The returned Promise
is resolved as soon as the
unsubscription is acknowledged by the Webcom back end, with the updated subscription to be revoked.
- Type
- Promise.<ServerlessDb.Subscription>
update(newVal, onCompleteopt)
Updates data at the data node referred to by this Webcom
instance.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
newVal |
Object | The children to add to the current data node, given as a json |
|
onComplete |
function |
<optional> |
A 1-argument callback function called after synchronization with the server. Its
argument is filled with an |
- Deprecated:
- Since 3.0 - Use
ServerlessDb.ServerlessDbNode#merge
instead.
- Since 3.0 - Use
updateEmailPasswordProfile(pathopt, data, onCompleteopt) → {Promise}
Updates some data within the profile associated with the currently authenticated email/password identity.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path |
string |
<optional> |
The path within the profile where to update the data. |
data |
Object | The data to update within the profile (as a JSON object). |
|
onComplete |
Authentication.authCallback |
<optional> |
A 1-argument callback function that is called after the
profile update completion, which receives an |
- Deprecated:
- Since 2.7 -Use
Webcom#updateIdentityProfile
instead
- Since 2.7 -Use
Returns:
A promise that will be resolved (without passing any argument) as soon as the update operation completes successfully, or rejected otherwise (with the failure reason as argument)
- Type
- Promise
updateIdentityProfile(pathopt, data) → {Promise}
Updates some data within the profile associated with the currently authenticated email- or phone-based identity. This method fails if no user is currently authenticated or if the currently authenticated user is not identified with an email- or phone-based identity.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path |
string |
<optional> |
The path within the profile where to update the data. |
data |
Object | The data to update within the profile (as a JSON object). |
- Since:
- 2.6.2
- Deprecated:
- Since 3.0 - Use
Authentication#updateIdentityProfile
instead.
- Since 3.0 - Use
Returns:
A promise that will be resolved (without passing any argument) as soon as the update operation completes successfully, or rejected otherwise (with the failure reason as argument)
- Type
- Promise
useCurrentContextForNextAuthOperation()
After this method is called, the next authentication-related operation will be performed in the context of the current authentication state. An authentication request will end in a multi-factor token (including at least the identity currently signed in). An identity creation request will add a new identity to the currently signed in Webcom account.
Once the next authentication-related operation performed, the effect of this method is forgotten, that is,
further authentication-related operations are executed starting from an empty authentication context event if a
user is authenticated.
If you need to cancel the effect of this method before the next authentication-related operation, simply
call the Webcom#useNewContextForNextAuthOperation
method.
- Since:
- 2.8
- Deprecated:
- Since 3.0 - Use
Authentication#useCurrentContextForNextAuthOperation
instead.
- Since 3.0 - Use
useNewContextForNextAuthOperation()
Cancels the effect of the Webcom#useCurrentContextForNextAuthOperation
method. Once called, the next
authentication-related operation will be performed without any context of authentication state, even if a user
is currently signed in.
- Since:
- 2.8
- Deprecated:
- Since 3.0 - Use
Authentication#useNewContextForNextAuthOperation
instead.
- Since 3.0 - Use
verifyIdentity(provider, id, data) → {Promise}
Verifies an identity newly created using the Webcom#addIdentity
method. If the verification is
successful, this method also signs the user in with this identity.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
provider |
string | The internal provider used to create the identity to verify. Currently, only
|
||||||||||||
id |
string | The identifier of the identity to verify. For email-based identities, it is an email address. For phone-based identities, it is a MSISDN (without the "+" prefix). |
||||||||||||
data |
Object | The verification data. Properties
|
- Since:
- 2.6.2
- Deprecated:
- Since 3.0 - Use
Authentication#verifyIdentity
instead.
- Since 3.0 - Use
Returns:
The authentication following the verification is performed asynchronously, and its result may
be caught by assigning a resolve and/or a reject callback to the returned Promise
.
The resolve (resp. reject) callback is called with one argument filled with the same value as the auth
(resp. error
) parameter of authentication callbacks.
- Type
- Promise