OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef PPAPI_UTILITY_WEBSOCKET_WEBSOCKET_API_H_ | |
6 #define PPAPI_UTILITY_WEBSOCKET_WEBSOCKET_API_H_ | |
7 | |
8 #include "ppapi/c/dev/ppb_websocket_dev.h" | |
9 | |
10 /// @file | |
11 /// This file defines the WebSocketAPI interface. | |
12 | |
13 namespace pp { | |
14 | |
15 class CompletionCallback; | |
16 class Instance; | |
17 class Var; | |
18 | |
19 /// The <code>WebSocketAPI_Dev</code> class | |
20 class WebSocketAPI { | |
21 public: | |
22 /// Constructs a WebSocketAPI_Dev object. | |
23 WebSocketAPI(Instance* instance); | |
dmichael (off chromium)
2012/02/01 23:05:18
explicit
Takashi Toyoshima
2012/02/03 07:58:27
Oops, sorry I missed again.
| |
24 | |
25 /// Destructs a WebSocketAPI_Dev object. | |
26 virtual ~WebSocketAPI(); | |
27 | |
28 /// Connect() connects to the specified WebSocket server. Caller can call | |
29 /// this method at most once. | |
30 /// | |
31 /// @param[in] url A <code>Var</code> of string type representing a WebSocket | |
32 /// server URL. | |
33 /// @param[in] protocols A pointer to an array of string type | |
34 /// <code>Var</code> specifying sub-protocols. Each <code>Var</code> | |
35 /// represents one sub-protocol and its <code>PP_VarType</code> must be | |
36 /// <code>PP_VARTYPE_STRING</code>. This argument can be null only if | |
37 /// <code>protocol_count</code> is 0. | |
38 /// @param[in] protocol_count The number of sub-protocols in | |
39 /// <code>protocols</code>. | |
40 /// | |
41 /// @return An int32_t containing an error code from | |
42 /// <code>pp_errors.h</code>. | |
43 /// See also <code>pp::WebSocket_Dev::Connect</code>. | |
44 int32_t Connect(const Var& url, const Var protocols[], | |
45 uint32_t protocol_count); | |
46 | |
47 /// Close() closes the specified WebSocket connection by specifying | |
48 /// <code>code</code> and <code>reason</code>. | |
49 /// | |
50 /// @param[in] code The WebSocket close code. Ignored if it is 0. | |
51 /// @param[in] reason A <code>Var</code> of string type which represents the | |
52 /// WebSocket close reason. Ignored if it is undefined type. | |
53 /// | |
54 /// @return An int32_t containing an error code from | |
55 /// <code>pp_errors.h</code>. | |
56 /// See also <code>pp::WebSocket_Dev::Close</code>. | |
57 int32_t Close(uint16_t code, const Var& reason); | |
58 | |
59 /// Send() sends a message to the WebSocket server. | |
60 /// | |
61 /// @param[in] data A message to send. The message is copied to internal | |
62 /// buffer. So caller can free <code>data</code> safely after returning | |
63 /// from the function. | |
64 /// | |
65 /// @return An int32_t containing an error code from | |
66 /// <code>pp_errors.h</code>. | |
67 /// See also <code>pp::WebSocket_Dev::SendMessage</code>. | |
68 int32_t Send(const Var& data); | |
69 | |
70 /// GetBufferedAmount() returns the number of bytes of text and binary | |
71 /// messages that have been queued for the WebSocket connection to send but | |
72 /// have not been transmitted to the network yet. | |
73 /// | |
74 /// @return Returns the number of bytes. | |
75 uint64_t GetBufferedAmount(); | |
76 | |
77 /// GetExtensions() returns the extensions selected by the server for the | |
78 /// specified WebSocket connection. | |
79 /// | |
80 /// @return Returns a <code>Var</code> of string type. If called before the | |
81 /// connection is established, its data is empty string. | |
82 /// Currently its data is always an empty string. | |
83 Var GetExtensions(); | |
84 | |
85 /// GetProtocol() returns the sub-protocol chosen by the server for the | |
86 /// specified WebSocket connection. | |
87 /// | |
88 /// @return Returns a <code>Var</code> of string type. If called before the | |
89 /// connection is established, it contains the empty string. | |
90 Var GetProtocol(); | |
91 | |
92 /// GetReadyState() returns the ready state of the specified WebSocket | |
93 /// connection. | |
94 /// | |
95 /// @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID_DEV</code> if called | |
96 /// before connect() is called. | |
97 PP_WebSocketReadyState_Dev GetReadyState(); | |
98 | |
99 /// GetURL() returns the URL associated with specified WebSocket connection. | |
100 /// | |
101 /// @return Returns a <code>Var</code> of string type. If called before the | |
102 /// connection is established, it contains the empty string. | |
103 Var GetURL(); | |
104 | |
105 /// SetBinaryType() specifies the binary object type for receiving binary | |
106 /// frames representation. Receiving text frames are always mapped to | |
107 /// <code>Var</code> of string type regardless of this attribute. | |
108 /// This function should be called before Connect() to ensure receiving all | |
109 /// incoming binary frames as the specified binary object type. | |
110 /// Default type is <code>Var</code> of Blob type. | |
111 /// | |
112 /// Currently, Blob bindings is not supported in Pepper, so receiving binary | |
113 /// type is always ArrayBuffer. To ensure backward compatibility, you must | |
114 /// call this function with | |
115 /// <code>PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV</code> to use binary frames. | |
116 /// | |
117 /// @param[in] binary_type Binary object type for receiving binary frames | |
118 /// representation. | |
119 /// | |
120 /// @return Returns <code>false</code> if the specified type is not | |
121 /// supported. Otherwise, return <code>true</code>. | |
122 bool SetBinaryType(PP_WebSocketBinaryType_Dev binary_type); | |
123 | |
124 /// GetBinaryType() returns the currently specified binary object type for | |
125 /// receiving binary frames. | |
126 /// | |
127 /// @return Returns <code>PP_WebSocketBinaryType_Dev</code> represents the | |
128 /// current binary object type. | |
129 PP_WebSocketBinaryType_Dev GetBinaryType(); | |
130 | |
131 /// OnOpen() is invoked when the connection is established by Connect(). | |
132 virtual void OnOpen() = 0; | |
dmichael (off chromium)
2012/02/01 23:05:18
In PPAPI, we use "Did" or "HandleBlah" instead of
Takashi Toyoshima
2012/02/03 07:58:27
OK.
I also reorder these methods.
Maybe DidOpen, D
| |
133 | |
134 /// OnMessage() is invoked when a message is received. | |
135 virtual void OnMessage(const Var& message) = 0; | |
136 | |
137 /// OnError() is invoked if the user agent was required to fail the WebSocket | |
138 /// connection or the WebSocket connection is closed with prejudice. | |
139 /// OnClose() always follows OnError(). | |
140 virtual void OnError() = 0; | |
141 | |
142 /// OnClose() is invoked when the connection is closed by errors or Close(). | |
143 virtual void OnClose(bool wasClean, uint16_t code, const Var& reason) = 0; | |
144 | |
145 private: | |
146 class Implement; | |
147 Implement* impl_; | |
148 }; | |
149 | |
150 } // namespace pp | |
151 | |
152 #endif // PPAPI_UTILITY_WEBSOCKET_WEBSOCKET_API_H_ | |
OLD | NEW |