Data Fields
| PP_Resource(* | Create )(PP_Instance instance) |
| PP_Bool(* | IsWebSocket )(PP_Resource resource) |
| int32_t(* | Connect )(PP_Resource web_socket, struct PP_Var url, const struct PP_Var protocols[], uint32_t protocol_count, struct PP_CompletionCallback callback) |
| int32_t(* | Close )(PP_Resource web_socket, uint16_t code, struct PP_Var reason, struct PP_CompletionCallback callback) |
| int32_t(* | ReceiveMessage )(PP_Resource web_socket, struct PP_Var *message, struct PP_CompletionCallback callback) |
| int32_t(* | SendMessage )(PP_Resource web_socket, struct PP_Var message) |
| uint64_t(* | GetBufferedAmount )(PP_Resource web_socket) |
| uint16_t(* | GetCloseCode )(PP_Resource web_socket) |
| struct PP_Var(* | GetCloseReason )(PP_Resource web_socket) |
| PP_Bool(* | GetCloseWasClean )(PP_Resource web_socket) |
| struct PP_Var(* | GetExtensions )(PP_Resource web_socket) |
| struct PP_Var(* | GetProtocol )(PP_Resource web_socket) |
| PP_WebSocketReadyState(* | GetReadyState )(PP_Resource web_socket) |
| struct PP_Var(* | GetURL )(PP_Resource web_socket) |
Detailed Description
The PPB_WebSocket interface provides bi-directional, full-duplex, communications over a single TCP socket.
Field Documentation
| int32_t(* PPB_WebSocket::Close)(PP_Resource web_socket, uint16_t code, struct PP_Var reason, struct PP_CompletionCallback callback) |
Close() closes the specified WebSocket connection by specifying code and reason.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.[in] code The WebSocket close code. This is ignored if it is PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED.PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSUREmust be used for the usual case. To indicate some specific error cases, codes in the rangePP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MINtoPP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MAX, and in the rangePP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MINtoPP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MAXare available.[in] reason A PP_Varrepresenting the WebSocket close reason. This is ignored if it isPP_VARTYPE_UNDEFINED. Otherwise, itsPP_VarTypemust bePP_VARTYPE_STRING.[in] callback A PP_CompletionCallbackcalled when the connection is closed or an error occurs in closing the connection.
- Returns:
- An int32_t containing an error code from
pp_errors.h. ReturnsPP_ERROR_BADARGUMENTifreasoncontains an invalid character as a UTF-8 string, or is longer than 123 bytes.PP_ERROR_BADARGUMENTcorresponds to a JavaScript SyntaxError in the WebSocket API specification. ReturnsPP_ERROR_NOACCESSif the code is not an integer equal to 1000 or in the range 3000 to 4999.PP_ERROR_NOACCESScorresponds to an InvalidAccessError in the WebSocket API specification. ReturnsPP_ERROR_INPROGRESSif a previous call to Close() is not finished.
| int32_t(* PPB_WebSocket::Connect)(PP_Resource web_socket, struct PP_Var url, const struct PP_Var protocols[], uint32_t protocol_count, struct PP_CompletionCallback callback) |
Connect() connects to the specified WebSocket server.
You can call this function once for a web_socket.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.[in] url A PP_Varrepresenting a WebSocket server URL. ThePP_VarTypemust bePP_VARTYPE_STRING.[in] protocols A pointer to an array of PP_Varspecifying sub-protocols. EachPP_Varrepresents one sub-protocol and itsPP_VarTypemust bePP_VARTYPE_STRING. This argument can be null only ifprotocol_countis 0.[in] protocol_count The number of sub-protocols in protocols.[in] callback A PP_CompletionCallbackcalled when a connection is established or an error occurs in establishing connection.
- Returns:
- An int32_t containing an error code from
pp_errors.h. ReturnsPP_ERROR_BADARGUMENTif the specifiedurl, orprotocolscontain an invalid string as defined in the WebSocket API specification.PP_ERROR_BADARGUMENTcorresponds to a SyntaxError in the WebSocket API specification. ReturnsPP_ERROR_NOACCESSif the protocol specified in theurlis not a secure protocol, but the origin of the caller has a secure scheme. Also returnsPP_ERROR_NOACCESSif the port specified in theurlis a port that the user agent is configured to block access to because it is a well-known port like SMTP.PP_ERROR_NOACCESScorresponds to a SecurityError of the specification. ReturnsPP_ERROR_INPROGRESSif this is not the first call to Connect().
| PP_Resource(* PPB_WebSocket::Create)(PP_Instance instance) |
Create() creates a WebSocket instance.
- Parameters:
[in] instance A PP_Instanceidentifying the instance with the WebSocket.
- Returns:
- A
PP_Resourcecorresponding to a WebSocket if successful.
| uint64_t(* PPB_WebSocket::GetBufferedAmount)(PP_Resource web_socket) |
GetBufferedAmount() returns the number of bytes of text and binary messages that have been queued for the WebSocket connection to send, but have not been transmitted to the network yet.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.
- Returns:
- Returns the number of bytes.
| uint16_t(* PPB_WebSocket::GetCloseCode)(PP_Resource web_socket) |
GetCloseCode() returns the connection close code for the WebSocket connection.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.
- Returns:
- Returns 0 if called before the close code is set.
struct PP_Var(* PPB_WebSocket::GetCloseReason)(PP_Resource web_socket) [read] |
GetCloseReason() returns the connection close reason for the WebSocket connection.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.
- Returns:
- Returns a
PP_VARTYPE_STRINGvar. If called before the close reason is set, the return value contains an empty string. Returns aPP_VARTYPE_UNDEFINEDif called on an invalid resource.
| PP_Bool(* PPB_WebSocket::GetCloseWasClean)(PP_Resource web_socket) |
GetCloseWasClean() returns if the connection was closed cleanly for the specified WebSocket connection.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.
- Returns:
- Returns
PP_FALSEif called before the connection is closed, called on an invalid resource, or closed for abnormal reasons. Otherwise, returnsPP_TRUEif the connection was closed cleanly.
struct PP_Var(* PPB_WebSocket::GetExtensions)(PP_Resource web_socket) [read] |
GetExtensions() returns the extensions selected by the server for the specified WebSocket connection.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.
- Returns:
- Returns a
PP_VARTYPE_STRINGvar. If called before the connection is established, the var's data is an empty string. Returns aPP_VARTYPE_UNDEFINEDif called on an invalid resource.
struct PP_Var(* PPB_WebSocket::GetProtocol)(PP_Resource web_socket) [read] |
GetProtocol() returns the sub-protocol chosen by the server for the specified WebSocket connection.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.
- Returns:
- Returns a
PP_VARTYPE_STRINGvar. If called before the connection is established, the var contains the empty string. Returns aPP_VARTYPE_UNDEFINEDif called on an invalid resource.
| PP_WebSocketReadyState(* PPB_WebSocket::GetReadyState)(PP_Resource web_socket) |
GetReadyState() returns the ready state of the specified WebSocket connection.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.
- Returns:
- Returns
PP_WEBSOCKETREADYSTATE_INVALIDif called before Connect() is called, or if this function is called on an invalid resource.
struct PP_Var(* PPB_WebSocket::GetURL)(PP_Resource web_socket) [read] |
GetURL() returns the URL associated with specified WebSocket connection.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.
- Returns:
- Returns a
PP_VARTYPE_STRINGvar. If called before the connection is established, the var contains the empty string. Returns aPP_VARTYPE_UNDEFINEDif this function is called on an invalid resource.
| PP_Bool(* PPB_WebSocket::IsWebSocket)(PP_Resource resource) |
IsWebSocket() determines if the provided resource is a WebSocket instance.
- Parameters:
[in] resource A PP_Resourcecorresponding to a WebSocket.
- Returns:
- Returns
PP_TRUEifresourceis aPPB_WebSocket,PP_FALSEif theresourceis invalid or some type other thanPPB_WebSocket.
| int32_t(* PPB_WebSocket::ReceiveMessage)(PP_Resource web_socket, struct PP_Var *message, struct PP_CompletionCallback callback) |
ReceiveMessage() receives a message from the WebSocket server.
This interface only returns a single message. That is, this interface must be called at least N times to receive N messages, no matter the size of each message.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.[out] message The received message is copied to provided message. Themessagemust remain valid until ReceiveMessage() completes. Its receivedPP_VarTypewill bePP_VARTYPE_STRINGorPP_VARTYPE_ARRAY_BUFFER.[in] callback A PP_CompletionCallbackcalled when ReceiveMessage() completes. This callback is ignored if ReceiveMessage() completes synchronously and returnsPP_OK.
- Returns:
- An int32_t containing an error code from
pp_errors.h. If an error is detected or connection is closed, ReceiveMessage() returnsPP_ERROR_FAILEDafter all buffered messages are received. Until buffered message become empty, ReceiveMessage() continues to returnPP_OKas if connection is still established without errors.
| int32_t(* PPB_WebSocket::SendMessage)(PP_Resource web_socket, struct PP_Var message) |
SendMessage() sends a message to the WebSocket server.
- Parameters:
[in] web_socket A PP_Resourcecorresponding to a WebSocket.[in] message A message to send. The message is copied to an internal buffer, so the caller can free messagesafely after returning from the function. Its sentPP_VarTypemust bePP_VARTYPE_STRINGorPP_VARTYPE_ARRAY_BUFFER.
- Returns:
- An int32_t containing an error code from
pp_errors.h. ReturnsPP_ERROR_FAILEDif the ReadyState isPP_WEBSOCKETREADYSTATE_CONNECTING.PP_ERROR_FAILEDcorresponds to a JavaScript InvalidStateError in the WebSocket API specification. ReturnsPP_ERROR_BADARGUMENTif the providedmessagecontains an invalid character as a UTF-8 string.PP_ERROR_BADARGUMENTcorresponds to a JavaScript SyntaxError in the WebSocket API specification. Otherwise, returnsPP_OK, which doesn't necessarily mean that the server received the message.
The documentation for this struct was generated from the following file: