ws
package and in the browser we use window.WebSocket
. We think that in most cases it isn't necessary to deal with the WebSocket connection directly. Thus, we developed a simple API to let you focus on your own business logic.subscription
. The first time you call subscribe, we'll try to open the WebSocket connection to the LiveQuery server for you.query.subscribe()
, we send a subscribe request to the LiveQuery server. When we get the confirmation from the LiveQuery server, this event will be emitted.MoralisQuery
, you'll also get this event.MoralisObject
is created and it fulfills the MoralisQuery
you subscribe, you'll get this event. The object
is the MoralisObject
which was created.MoralisObject
fulfills the MoralisQuery
, your subscribe is updated (The MoralisObject
fulfills the MoralisQuery
before and after changes), and you'll get this event. The object
is the MoralisObject
which was updated. Its content is the latest value of the MoralisObject
.MoralisObject
's old value does not fulfill the MoralisQuery
but its new value fulfills the MoralisQuery
, you'll get this event. The object
is the MoralisObject
which enters the MoralisQuery
. Its content is the latest value of the MoralisObject
.MoralisObject
's old value fulfills the MoralisQuery
but its new value doesn't fulfill the MoralisQuery
, you'll get this event. The object
is the MoralisObject
which leaves the MoralisQuery
. Its content is the latest value of the MoralisObject
.MoralisObject
which fulfills the MoralisQuery
is deleted, you'll get this event. The object
is the MoralisObject
which is deleted.MoralisQuery
, you can just unsubscribe the subscription
. After that, you won't get any events from the subscription
object.Moralis.LiveQuery.close()
. This function will close the WebSocket connection to the LiveQuery server, cancel the auto-reconnect, and unsubscribe all subscriptions based on it. If you call query.subscribe()
after this, we will create a new WebSocket connection to the LiveQuery server.Moralis.serverURL
, we will try to extract the hostname and use ws://hostname
as the default liveQueryServerURL
. However, if you want to define your own liveQueryServerURL
or use a different protocol such as wss
, you should set it yourself.Moralis.LiveQuery.close()
or client.close()
, we'll cancel the auto-reconnect.sessionToken
to the LiveQuery server when you subscribe to a MoralisQuery
. For the standard API, we use the sessionToken
of the current user by default. For the advanced API, you can use any sessionToken
when you subscribe to a MoralisQuery
. An important thing to be aware of is when you log out or the sessionToken
you are using is invalid, you should unsubscribe from the subscription and subscribe to the MoralisQuery
again. Otherwise, you may face a security issue since you'll get events that shouldn't be sent to you.