class staticgapi.drive.realtime. Document
A Realtime document. A document consists of a Realtime model and a set of collaborators. Listen on the document for the following events:
- gapi.drive.realtime.EventType.ATTRIBUTE_CHANGED
- gapi.drive.realtime.EventType.COLLABORATOR_LEFT
- gapi.drive.realtime.EventType.COLLABORATOR_JOINED
- gapi.drive.realtime.EventType.DOCUMENT_SAVE_STATE_CHANGED
Properties | |
---|---|
isClosed |
boolean
Whether the document is closed. Read-only; call close() to close the document. |
isInGoogleDrive |
boolean
Whether the document is stored in Google Drive. Read-only. This property is false for documents created using gapi.drive.realtime.newInMemoryDocument or gapi.drive.realtime.loadFromJson and true for all other documents. |
saveDelay |
void
The approximate amount of time (in milliseconds) that changes have been waiting to be saved in Google Drive. If there are no unsaved changes or this is an in-memory document, this value is always 0. This value should remain low (for example, less than a few seconds) as long as the network is healthy and changes are being saved as quickly as they are generated. If the network is unreliable or down, or if changes are being made to the model more quickly than they can be saved, this value will continue to grow until the network catches up and the changes are successfully saved. |
Methods | |
---|---|
addEventListener(type, listener[, opt_capture]) |
void
Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched. |
close() |
void
Closes the document and disconnects from the server. After this function is called, event listeners will no longer fire and attempts to access the document, model, or model objects will throw a gapi.drive.realtime.DocumentClosedError. Calling this function after the document has been closed will have no effect. |
getCollaborators() |
non-null Array of gapi.drive.realtime.Collaborator
Gets an array of collaborators active in this session. Each collaborator is a jsMap with these fields: sessionId, userId, displayName, color, isMe, isAnonymous. |
getModel() |
non-null gapi.drive.realtime.Model
Gets the collaborative model associated with this document. |
removeAllEventListeners() |
void
Removes all event listeners from this object. |
removeEventListener(type, listener[, opt_capture]) |
void
Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done. |
saveAs(fileId) |
void
Saves a copy of this document to a new file. After this function is called, all changes to this document no longer affect the old document and are instead saved to the new file. The provided file ID must refer to a valid file in Drive which does not have any Realtime data for your app. This function can also be used on an in-memory file to convert it to a Drive-connected file. |
new Document()
This class should not be instantiated directly. The document object is generated during the document load process.
- Extends
- gapi.drive.realtime.EventTarget
- See also
- gapi.drive.realtime.load()
Properties
isClosed boolean
Whether the document is closed. Read-only; call close() to close the document.
isInGoogleDrive boolean
Whether the document is stored in Google Drive. Read-only. This property is false for documents created using gapi.drive.realtime.newInMemoryDocument or gapi.drive.realtime.loadFromJson and true for all other documents.
saveDelay
The approximate amount of time (in milliseconds) that changes have been waiting to be saved in Google Drive. If there are no unsaved changes or this is an in-memory document, this value is always 0.
This value should remain low (for example, less than a few seconds) as long as the network is healthy and changes are being saved as quickly as they are generated. If the network is unreliable or down, or if changes are being made to the model more quickly than they can be saved, this value will continue to grow until the network catches up and the changes are successfully saved.
Methods
addEventListener(type, listener[, opt_capture])
Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
type |
string |
|
The type of the event to listen for. |
listener |
(non-null function() or non-null EventListener) |
|
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument. |
opt_capture |
boolean |
Yes |
Whether to handle the event target in the capture phase instead of the bubble phase. |
- Inherited from
- gapi.drive.realtime.EventTarget#addEventListener
close()
Closes the document and disconnects from the server. After this function is called, event listeners will no longer fire and attempts to access the document, model, or model objects will throw a gapi.drive.realtime.DocumentClosedError. Calling this function after the document has been closed will have no effect.
getCollaborators() → Array of gapi.drive.realtime.Collaborator
Gets an array of collaborators active in this session. Each collaborator is a jsMap with these fields: sessionId, userId, displayName, color, isMe, isAnonymous.
- Returns
-
non-null Array of gapi.drive.realtime.Collaborator
A jsArray of collaborators.
getModel() → gapi.drive.realtime.Model
Gets the collaborative model associated with this document.
- Returns
-
non-null gapi.drive.realtime.Model
The collaborative model for this document.
removeAllEventListeners()
Removes all event listeners from this object.
- Inherited from
- gapi.drive.realtime.EventTarget#removeAllEventListeners
removeEventListener(type, listener[, opt_capture])
Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
type |
|
The type of the event to listen for. |
|
listener |
(non-null function() or non-null EventListener) |
|
The function to or EventListener to remove. |
opt_capture |
boolean |
Yes |
Whether to handle the event target in the capture phase instead of the bubble phase. |
- Inherited from
- gapi.drive.realtime.EventTarget#removeEventListener
saveAs(fileId)
Saves a copy of this document to a new file. After this function is called, all changes to this document no longer affect the old document and are instead saved to the new file.
The provided file ID must refer to a valid file in Drive which does not have any Realtime data for your app.
This function can also be used on an in-memory file to convert it to a Drive-connected file.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fileId |
string |
|
The new file ID to use for this document. |