Google+ Hangouts API

gapi.hangout.data

Provides functions for sharing data (getting and setting state) between participants in a Hangout.

Classes

Functions

Events

Classes in gapi.hangout.data

Class Description
class MessageReceivedEvent(
  senderId,
  message
)
Contains information about a message from another participant.
senderId : string
The ID of the participant that sent the message.
message : string
The message itself.
class StateChangedEvent(
  addedKeys,
  metadata,
  removedKeys,
  state
)
Contains information about a change in the shared state.
addedKeys : Array.<Object>
An array containing the newly added entries to the state metadata. See getStateMetadata for more information.
metadata : Object.<string, Object>
The state metadata, also available via getStateMetadata.
removedKeys : Array.<string>
List of the keys removed in this update.
state : Object.<string, string>
The shared state, also available via getState.

Functions in gapi.hangout.data

Function Returns Description & Parameter
clearValue(
  key
)
undefined Clears a single key/value pair in the shared state object.

See also: gapi.hangout.data.onStateChanged


key : string
The key to clear.
getKeys() Array.<string> Gets the keys in the shared state object, an array of strings.
getValue(
  key
)
string Gets the value for a given key. Returns undefined if the key/value does not exist.
key : string
The key to get the value for.
getState() Object.<string, string> Gets the shared state object, a set of name/value pairs.
getStateMetadata() Object.<string, Object> Gets the state metadata object, which contains the same key/value data as the shared state object retrieved via getState but augmented with additional information. Each metadata entry includes:
  • key: the key being retrieved.
  • value: the value of the key.
  • timestamp: The server time when the key/value was most recently updated. The time is in milliseconds since January 1, 1970, 00:00:00.
  • timediff: The difference (in milliseconds) in server time between when this value was sent to the client and timestamp. The server immediately sends updates to all participants who are present, so for those cases timediff will be zero. A new participant receives all state when joining, so would expect to see a timediff value equal to the difference between when the value was set and when the participant joined.
  • lastWriter: The id of the participant who last wrote to this key.
setValue(
  key,
  value
)
undefined Sets a single key value pair.

See also: gapi.hangout.data.onStateChanged


key : string
The key to set.
value : string
The value to set the key to.
submitDelta(
  opt_updates,
  opt_removes
)
undefined Submits a request to update the value of the shared state object.

See also: gapi.hangout.data.onStateChanged


opt_updates : Object.<string, string>
Key/value pairs to add or overwrite. The value in each key/value pair must be a string. Notably, the value must not be any of a number, boolean, object, array, function, null, or undefined.
opt_removes : Array.<string>
A (possibly empty) array of key names to remove.
sendMessage(
  message
)
undefined Sends a message to the other app participants. A message is simply a string defined by the app. Messages are not retained or stored, and should have lower latency than objects stored via submitDelta. This is a best-effort delivery system, and messages might be lost, so this method should only be used to send things that can be dropped (e.g. sending mouse coordinates from a user).

See also: gapi.hangout.data.onMessageReceived


message : string
The message string.

Event Functions in gapi.hangout.data

Event Function Description
gapi.hangout.data.onMessageReceived
onMessageReceived.add(
  callback
)
Adds a callback to be called when a message is received. The argument to the callback is an object containing the participant ID for the sender and the message.

See also: gapi.hangout.data.sendMessage


callback : function(MessageReceivedEvent)
The callback to add.
onMessageReceived.remove(
  callback
)
Removes a callback previously added by onMessageReceived.add.
callback : function(MessageReceivedEvent)
The callback to remove.
gapi.hangout.data.onStateChanged
onStateChanged.add(
  callback
)
Adds a callback to be called when a new version of the shared state object is received from the server. The parameter to the callback is a StateChangedEvent.
Note that the callback will be called for changes in the shared state which result from submitDelta calls made from this participant's app.

See also: gapi.hangout.data.clearValue, gapi.hangout.data.setValue, gapi.hangout.data.submitDelta


callback : function(StateChangedEvent)
The callback to add.
onStateChanged.remove(
  callback
)
Removes a callback previously added by onStateChanged.add.
callback : function(StateChangedEvent)
The callback to remove.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.