dragonfly_chrome_headless 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +4 -0
  5. data/README.md +53 -0
  6. data/Rakefile +10 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/dragonfly_chrome_headless.gemspec +27 -0
  10. data/lib/dragonfly_chrome_headless.rb +9 -0
  11. data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
  12. data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
  13. data/lib/dragonfly_chrome_headless/version.rb +3 -0
  14. data/node_modules/.bin/chrome-remote-interface +1 -0
  15. data/node_modules/.bin/mkdirp +1 -0
  16. data/node_modules/.bin/rimraf +1 -0
  17. data/node_modules/@types/core-js/LICENSE +21 -0
  18. data/node_modules/@types/core-js/README.md +16 -0
  19. data/node_modules/@types/core-js/index.d.ts +2452 -0
  20. data/node_modules/@types/core-js/package.json +85 -0
  21. data/node_modules/@types/mkdirp/README.md +18 -0
  22. data/node_modules/@types/mkdirp/index.d.ts +14 -0
  23. data/node_modules/@types/mkdirp/package.json +77 -0
  24. data/node_modules/@types/mkdirp/types-metadata.json +25 -0
  25. data/node_modules/@types/node/README.md +16 -0
  26. data/node_modules/@types/node/index.d.ts +4132 -0
  27. data/node_modules/@types/node/package.json +84 -0
  28. data/node_modules/balanced-match/.npmignore +5 -0
  29. data/node_modules/balanced-match/LICENSE.md +21 -0
  30. data/node_modules/balanced-match/README.md +91 -0
  31. data/node_modules/balanced-match/index.js +59 -0
  32. data/node_modules/balanced-match/package.json +112 -0
  33. data/node_modules/brace-expansion/README.md +123 -0
  34. data/node_modules/brace-expansion/index.js +201 -0
  35. data/node_modules/brace-expansion/package.json +114 -0
  36. data/node_modules/chrome-launcher/.clang-format +6 -0
  37. data/node_modules/chrome-launcher/.npmignore +11 -0
  38. data/node_modules/chrome-launcher/README.md +123 -0
  39. data/node_modules/chrome-launcher/ask.js +32 -0
  40. data/node_modules/chrome-launcher/ask.ts +35 -0
  41. data/node_modules/chrome-launcher/chrome-finder.js +157 -0
  42. data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
  43. data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
  44. data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
  45. data/node_modules/chrome-launcher/compiled-check.js +14 -0
  46. data/node_modules/chrome-launcher/flags.js +27 -0
  47. data/node_modules/chrome-launcher/flags.ts +26 -0
  48. data/node_modules/chrome-launcher/index.js +7 -0
  49. data/node_modules/chrome-launcher/index.ts +1 -0
  50. data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
  51. data/node_modules/chrome-launcher/package.json +116 -0
  52. data/node_modules/chrome-launcher/random-port.js +24 -0
  53. data/node_modules/chrome-launcher/random-port.ts +23 -0
  54. data/node_modules/chrome-launcher/tsconfig.json +19 -0
  55. data/node_modules/chrome-launcher/utils.js +52 -0
  56. data/node_modules/chrome-launcher/utils.ts +44 -0
  57. data/node_modules/chrome-launcher/yarn.lock +1486 -0
  58. data/node_modules/chrome-remote-interface/LICENSE +18 -0
  59. data/node_modules/chrome-remote-interface/README.md +849 -0
  60. data/node_modules/chrome-remote-interface/bin/client.js +337 -0
  61. data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
  62. data/node_modules/chrome-remote-interface/index.js +39 -0
  63. data/node_modules/chrome-remote-interface/lib/api.js +84 -0
  64. data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
  65. data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
  66. data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
  67. data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
  68. data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
  69. data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
  70. data/node_modules/chrome-remote-interface/package.json +128 -0
  71. data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
  72. data/node_modules/commander/Readme.md +195 -0
  73. data/node_modules/commander/index.js +851 -0
  74. data/node_modules/commander/package.json +92 -0
  75. data/node_modules/concat-map/.travis.yml +4 -0
  76. data/node_modules/concat-map/LICENSE +18 -0
  77. data/node_modules/concat-map/README.markdown +62 -0
  78. data/node_modules/concat-map/example/map.js +6 -0
  79. data/node_modules/concat-map/index.js +13 -0
  80. data/node_modules/concat-map/package.json +117 -0
  81. data/node_modules/concat-map/test/map.js +39 -0
  82. data/node_modules/debug/.coveralls.yml +1 -0
  83. data/node_modules/debug/.eslintrc +11 -0
  84. data/node_modules/debug/.npmignore +9 -0
  85. data/node_modules/debug/.travis.yml +14 -0
  86. data/node_modules/debug/CHANGELOG.md +357 -0
  87. data/node_modules/debug/LICENSE +19 -0
  88. data/node_modules/debug/Makefile +50 -0
  89. data/node_modules/debug/Readme.md +312 -0
  90. data/node_modules/debug/component.json +19 -0
  91. data/node_modules/debug/karma.conf.js +70 -0
  92. data/node_modules/debug/node.js +1 -0
  93. data/node_modules/debug/package.json +124 -0
  94. data/node_modules/debug/src/browser.js +185 -0
  95. data/node_modules/debug/src/debug.js +202 -0
  96. data/node_modules/debug/src/index.js +10 -0
  97. data/node_modules/debug/src/node.js +246 -0
  98. data/node_modules/fs.realpath/LICENSE +43 -0
  99. data/node_modules/fs.realpath/README.md +33 -0
  100. data/node_modules/fs.realpath/index.js +66 -0
  101. data/node_modules/fs.realpath/old.js +303 -0
  102. data/node_modules/fs.realpath/package.json +94 -0
  103. data/node_modules/glob/LICENSE +15 -0
  104. data/node_modules/glob/README.md +368 -0
  105. data/node_modules/glob/changelog.md +67 -0
  106. data/node_modules/glob/common.js +240 -0
  107. data/node_modules/glob/glob.js +790 -0
  108. data/node_modules/glob/package.json +112 -0
  109. data/node_modules/glob/sync.js +486 -0
  110. data/node_modules/html-pdf-chrome/.npmignore +9 -0
  111. data/node_modules/html-pdf-chrome/LICENSE +21 -0
  112. data/node_modules/html-pdf-chrome/README.md +165 -0
  113. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
  114. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
  115. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
  116. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
  117. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
  118. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
  119. data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
  120. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
  121. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
  122. data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
  123. data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
  124. data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
  125. data/node_modules/html-pdf-chrome/package.json +133 -0
  126. data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
  127. data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
  128. data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
  129. data/node_modules/html-pdf-chrome/src/index.ts +179 -0
  130. data/node_modules/inflight/LICENSE +15 -0
  131. data/node_modules/inflight/README.md +37 -0
  132. data/node_modules/inflight/inflight.js +54 -0
  133. data/node_modules/inflight/package.json +105 -0
  134. data/node_modules/inherits/LICENSE +16 -0
  135. data/node_modules/inherits/README.md +42 -0
  136. data/node_modules/inherits/inherits.js +7 -0
  137. data/node_modules/inherits/inherits_browser.js +23 -0
  138. data/node_modules/inherits/package.json +97 -0
  139. data/node_modules/lighthouse-logger/README.md +4 -0
  140. data/node_modules/lighthouse-logger/index.js +212 -0
  141. data/node_modules/lighthouse-logger/package.json +69 -0
  142. data/node_modules/lighthouse-logger/yarn.lock +13 -0
  143. data/node_modules/minimatch/LICENSE +15 -0
  144. data/node_modules/minimatch/README.md +209 -0
  145. data/node_modules/minimatch/minimatch.js +923 -0
  146. data/node_modules/minimatch/package.json +99 -0
  147. data/node_modules/minimist/.travis.yml +4 -0
  148. data/node_modules/minimist/LICENSE +18 -0
  149. data/node_modules/minimist/example/parse.js +2 -0
  150. data/node_modules/minimist/index.js +187 -0
  151. data/node_modules/minimist/package.json +101 -0
  152. data/node_modules/minimist/readme.markdown +73 -0
  153. data/node_modules/minimist/test/dash.js +24 -0
  154. data/node_modules/minimist/test/default_bool.js +20 -0
  155. data/node_modules/minimist/test/dotted.js +16 -0
  156. data/node_modules/minimist/test/long.js +31 -0
  157. data/node_modules/minimist/test/parse.js +318 -0
  158. data/node_modules/minimist/test/parse_modified.js +9 -0
  159. data/node_modules/minimist/test/short.js +67 -0
  160. data/node_modules/minimist/test/whitespace.js +8 -0
  161. data/node_modules/mkdirp/.travis.yml +8 -0
  162. data/node_modules/mkdirp/LICENSE +21 -0
  163. data/node_modules/mkdirp/bin/cmd.js +33 -0
  164. data/node_modules/mkdirp/bin/usage.txt +12 -0
  165. data/node_modules/mkdirp/examples/pow.js +6 -0
  166. data/node_modules/mkdirp/index.js +98 -0
  167. data/node_modules/mkdirp/package.json +93 -0
  168. data/node_modules/mkdirp/readme.markdown +100 -0
  169. data/node_modules/mkdirp/test/chmod.js +41 -0
  170. data/node_modules/mkdirp/test/clobber.js +38 -0
  171. data/node_modules/mkdirp/test/mkdirp.js +28 -0
  172. data/node_modules/mkdirp/test/opts_fs.js +29 -0
  173. data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
  174. data/node_modules/mkdirp/test/perm.js +32 -0
  175. data/node_modules/mkdirp/test/perm_sync.js +36 -0
  176. data/node_modules/mkdirp/test/race.js +37 -0
  177. data/node_modules/mkdirp/test/rel.js +32 -0
  178. data/node_modules/mkdirp/test/return.js +25 -0
  179. data/node_modules/mkdirp/test/return_sync.js +24 -0
  180. data/node_modules/mkdirp/test/root.js +19 -0
  181. data/node_modules/mkdirp/test/sync.js +32 -0
  182. data/node_modules/mkdirp/test/umask.js +28 -0
  183. data/node_modules/mkdirp/test/umask_sync.js +32 -0
  184. data/node_modules/ms/README.md +51 -0
  185. data/node_modules/ms/index.js +152 -0
  186. data/node_modules/ms/license.md +21 -0
  187. data/node_modules/ms/package.json +109 -0
  188. data/node_modules/once/LICENSE +15 -0
  189. data/node_modules/once/README.md +79 -0
  190. data/node_modules/once/once.js +42 -0
  191. data/node_modules/once/package.json +101 -0
  192. data/node_modules/path-is-absolute/index.js +20 -0
  193. data/node_modules/path-is-absolute/license +21 -0
  194. data/node_modules/path-is-absolute/package.json +111 -0
  195. data/node_modules/path-is-absolute/readme.md +59 -0
  196. data/node_modules/rimraf/LICENSE +15 -0
  197. data/node_modules/rimraf/README.md +101 -0
  198. data/node_modules/rimraf/bin.js +50 -0
  199. data/node_modules/rimraf/package.json +99 -0
  200. data/node_modules/rimraf/rimraf.js +363 -0
  201. data/node_modules/ultron/LICENSE +22 -0
  202. data/node_modules/ultron/index.js +138 -0
  203. data/node_modules/ultron/package.json +112 -0
  204. data/node_modules/wrappy/LICENSE +15 -0
  205. data/node_modules/wrappy/README.md +36 -0
  206. data/node_modules/wrappy/package.json +97 -0
  207. data/node_modules/wrappy/wrappy.js +33 -0
  208. data/node_modules/ws/LICENSE +21 -0
  209. data/node_modules/ws/README.md +259 -0
  210. data/node_modules/ws/SECURITY.md +33 -0
  211. data/node_modules/ws/index.js +15 -0
  212. data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
  213. data/node_modules/ws/lib/BufferUtil.js +15 -0
  214. data/node_modules/ws/lib/ErrorCodes.js +28 -0
  215. data/node_modules/ws/lib/EventTarget.js +158 -0
  216. data/node_modules/ws/lib/Extensions.js +69 -0
  217. data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
  218. data/node_modules/ws/lib/Receiver.js +520 -0
  219. data/node_modules/ws/lib/Sender.js +438 -0
  220. data/node_modules/ws/lib/Validation.fallback.js +9 -0
  221. data/node_modules/ws/lib/Validation.js +17 -0
  222. data/node_modules/ws/lib/WebSocket.js +705 -0
  223. data/node_modules/ws/lib/WebSocketServer.js +336 -0
  224. data/node_modules/ws/package.json +122 -0
  225. data/package.json +26 -0
  226. data/samples/sample.html +13 -0
  227. data/script/rasterize.js +18 -0
  228. metadata +325 -0
@@ -0,0 +1,438 @@
1
+ /*!
2
+ * ws: a node.js websocket client
3
+ * Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
4
+ * MIT Licensed
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ const crypto = require('crypto');
10
+
11
+ const PerMessageDeflate = require('./PerMessageDeflate');
12
+ const bufferUtil = require('./BufferUtil');
13
+ const ErrorCodes = require('./ErrorCodes');
14
+
15
+ /**
16
+ * HyBi Sender implementation.
17
+ */
18
+ class Sender {
19
+ /**
20
+ * Creates a Sender instance.
21
+ *
22
+ * @param {net.Socket} socket The connection socket
23
+ * @param {Object} extensions An object containing the negotiated extensions
24
+ */
25
+ constructor (socket, extensions) {
26
+ this.perMessageDeflate = (extensions || {})[PerMessageDeflate.extensionName];
27
+ this._socket = socket;
28
+
29
+ this.firstFragment = true;
30
+ this.compress = false;
31
+
32
+ this.processing = false;
33
+ this.bufferedBytes = 0;
34
+ this.queue = [];
35
+
36
+ this.onerror = null;
37
+ }
38
+
39
+ /**
40
+ * Sends a close message to the other peer.
41
+ *
42
+ * @param {(Number|undefined)} code The status code component of the body
43
+ * @param {String} data The message component of the body
44
+ * @param {Boolean} mask Specifies whether or not to mask the message
45
+ * @param {Function} cb Callback
46
+ * @public
47
+ */
48
+ close (code, data, mask, cb) {
49
+ if (code !== undefined && (typeof code !== 'number' || !ErrorCodes.isValidErrorCode(code))) {
50
+ throw new Error('first argument must be a valid error code number');
51
+ }
52
+
53
+ const buf = Buffer.allocUnsafe(2 + (data ? Buffer.byteLength(data) : 0));
54
+
55
+ buf.writeUInt16BE(code || 1000, 0, true);
56
+ if (buf.length > 2) buf.write(data, 2);
57
+
58
+ if (this.perMessageDeflate) {
59
+ this.enqueue([this.doClose, buf, mask, cb]);
60
+ } else {
61
+ this.doClose(buf, mask, cb);
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Frames and sends a close message.
67
+ *
68
+ * @param {Buffer} data The message to send
69
+ * @param {Boolean} mask Specifies whether or not to mask `data`
70
+ * @param {Function} cb Callback
71
+ * @private
72
+ */
73
+ doClose (data, mask, cb) {
74
+ this.frameAndSend(data, {
75
+ readOnly: false,
76
+ opcode: 0x08,
77
+ rsv1: false,
78
+ fin: true,
79
+ mask
80
+ }, cb);
81
+
82
+ if (this.perMessageDeflate) this.continue();
83
+ }
84
+
85
+ /**
86
+ * Sends a ping message to the other peer.
87
+ *
88
+ * @param {*} data The message to send
89
+ * @param {Boolean} mask Specifies whether or not to mask `data`
90
+ * @public
91
+ */
92
+ ping (data, mask) {
93
+ var readOnly = true;
94
+
95
+ if (data && !Buffer.isBuffer(data)) {
96
+ if (data instanceof ArrayBuffer) {
97
+ data = Buffer.from(data);
98
+ } else if (ArrayBuffer.isView(data)) {
99
+ data = viewToBuffer(data);
100
+ } else {
101
+ data = Buffer.from(data);
102
+ readOnly = false;
103
+ }
104
+ }
105
+
106
+ if (this.perMessageDeflate) {
107
+ this.enqueue([this.doPing, data, mask, readOnly]);
108
+ } else {
109
+ this.doPing(data, mask, readOnly);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Frames and sends a ping message.
115
+ *
116
+ * @param {*} data The message to send
117
+ * @param {Boolean} mask Specifies whether or not to mask `data`
118
+ * @param {Boolean} readOnly Specifies whether `data` can be modified
119
+ * @private
120
+ */
121
+ doPing (data, mask, readOnly) {
122
+ this.frameAndSend(data, {
123
+ opcode: 0x09,
124
+ rsv1: false,
125
+ fin: true,
126
+ readOnly,
127
+ mask
128
+ });
129
+
130
+ if (this.perMessageDeflate) this.continue();
131
+ }
132
+
133
+ /**
134
+ * Sends a pong message to the other peer.
135
+ *
136
+ * @param {*} data The message to send
137
+ * @param {Boolean} mask Specifies whether or not to mask `data`
138
+ * @public
139
+ */
140
+ pong (data, mask) {
141
+ var readOnly = true;
142
+
143
+ if (data && !Buffer.isBuffer(data)) {
144
+ if (data instanceof ArrayBuffer) {
145
+ data = Buffer.from(data);
146
+ } else if (ArrayBuffer.isView(data)) {
147
+ data = viewToBuffer(data);
148
+ } else {
149
+ data = Buffer.from(data);
150
+ readOnly = false;
151
+ }
152
+ }
153
+
154
+ if (this.perMessageDeflate) {
155
+ this.enqueue([this.doPong, data, mask, readOnly]);
156
+ } else {
157
+ this.doPong(data, mask, readOnly);
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Frames and sends a pong message.
163
+ *
164
+ * @param {*} data The message to send
165
+ * @param {Boolean} mask Specifies whether or not to mask `data`
166
+ * @param {Boolean} readOnly Specifies whether `data` can be modified
167
+ * @private
168
+ */
169
+ doPong (data, mask, readOnly) {
170
+ this.frameAndSend(data, {
171
+ opcode: 0x0a,
172
+ rsv1: false,
173
+ fin: true,
174
+ readOnly,
175
+ mask
176
+ });
177
+
178
+ if (this.perMessageDeflate) this.continue();
179
+ }
180
+
181
+ /**
182
+ * Sends a data message to the other peer.
183
+ *
184
+ * @param {*} data The message to send
185
+ * @param {Object} options Options object
186
+ * @param {Boolean} options.compress Specifies whether or not to compress `data`
187
+ * @param {Boolean} options.binary Specifies whether `data` is binary or text
188
+ * @param {Boolean} options.fin Specifies whether the fragment is the last one
189
+ * @param {Boolean} options.mask Specifies whether or not to mask `data`
190
+ * @param {Function} cb Callback
191
+ * @public
192
+ */
193
+ send (data, options, cb) {
194
+ var opcode = options.binary ? 2 : 1;
195
+ var rsv1 = options.compress;
196
+ var readOnly = true;
197
+
198
+ if (data && !Buffer.isBuffer(data)) {
199
+ if (data instanceof ArrayBuffer) {
200
+ data = Buffer.from(data);
201
+ } else if (ArrayBuffer.isView(data)) {
202
+ data = viewToBuffer(data);
203
+ } else {
204
+ data = Buffer.from(data);
205
+ readOnly = false;
206
+ }
207
+ }
208
+
209
+ if (this.firstFragment) {
210
+ this.firstFragment = false;
211
+ if (rsv1 && data && this.perMessageDeflate) {
212
+ rsv1 = data.length >= this.perMessageDeflate.threshold;
213
+ }
214
+ this.compress = rsv1;
215
+ } else {
216
+ rsv1 = false;
217
+ opcode = 0;
218
+ }
219
+
220
+ if (options.fin) this.firstFragment = true;
221
+
222
+ if (this.perMessageDeflate) {
223
+ this.enqueue([this.dispatch, data, {
224
+ compress: this.compress,
225
+ mask: options.mask,
226
+ fin: options.fin,
227
+ readOnly,
228
+ opcode,
229
+ rsv1
230
+ }, cb]);
231
+ } else {
232
+ this.frameAndSend(data, {
233
+ mask: options.mask,
234
+ fin: options.fin,
235
+ rsv1: false,
236
+ readOnly,
237
+ opcode
238
+ }, cb);
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Dispatches a data message.
244
+ *
245
+ * @param {Buffer} data The message to send
246
+ * @param {Object} options Options object
247
+ * @param {Number} options.opcode The opcode
248
+ * @param {Boolean} options.readOnly Specifies whether `data` can be modified
249
+ * @param {Boolean} options.fin Specifies whether or not to set the FIN bit
250
+ * @param {Boolean} options.compress Specifies whether or not to compress `data`
251
+ * @param {Boolean} options.mask Specifies whether or not to mask `data`
252
+ * @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit
253
+ * @param {Function} cb Callback
254
+ * @private
255
+ */
256
+ dispatch (data, options, cb) {
257
+ if (!options.compress) {
258
+ this.frameAndSend(data, options, cb);
259
+ this.continue();
260
+ return;
261
+ }
262
+
263
+ this.perMessageDeflate.compress(data, options.fin, (err, buf) => {
264
+ if (err) {
265
+ if (cb) cb(err);
266
+ else this.onerror(err);
267
+ return;
268
+ }
269
+
270
+ options.readOnly = false;
271
+ this.frameAndSend(buf, options, cb);
272
+ this.continue();
273
+ });
274
+ }
275
+
276
+ /**
277
+ * Frames and sends a piece of data according to the HyBi WebSocket protocol.
278
+ *
279
+ * @param {Buffer} data The data to send
280
+ * @param {Object} options Options object
281
+ * @param {Number} options.opcode The opcode
282
+ * @param {Boolean} options.readOnly Specifies whether `data` can be modified
283
+ * @param {Boolean} options.fin Specifies whether or not to set the FIN bit
284
+ * @param {Boolean} options.mask Specifies whether or not to mask `data`
285
+ * @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit
286
+ * @param {Function} cb Callback
287
+ * @private
288
+ */
289
+ frameAndSend (data, options, cb) {
290
+ if (!data) {
291
+ const bytes = [options.opcode, 0];
292
+
293
+ if (options.fin) bytes[0] |= 0x80;
294
+ if (options.mask) {
295
+ bytes[1] |= 0x80;
296
+ bytes.push(0, 0, 0, 0);
297
+ }
298
+
299
+ sendFramedData(this, Buffer.from(bytes), null, cb);
300
+ return;
301
+ }
302
+
303
+ const mergeBuffers = data.length < 1024 || options.mask && options.readOnly;
304
+ var dataOffset = options.mask ? 6 : 2;
305
+ var payloadLength = data.length;
306
+
307
+ if (data.length >= 65536) {
308
+ dataOffset += 8;
309
+ payloadLength = 127;
310
+ } else if (data.length > 125) {
311
+ dataOffset += 2;
312
+ payloadLength = 126;
313
+ }
314
+
315
+ const outputBuffer = Buffer.allocUnsafe(
316
+ mergeBuffers ? data.length + dataOffset : dataOffset
317
+ );
318
+
319
+ outputBuffer[0] = options.fin ? options.opcode | 0x80 : options.opcode;
320
+ if (options.rsv1) outputBuffer[0] |= 0x40;
321
+
322
+ if (payloadLength === 126) {
323
+ outputBuffer.writeUInt16BE(data.length, 2, true);
324
+ } else if (payloadLength === 127) {
325
+ outputBuffer.writeUInt32BE(0, 2, true);
326
+ outputBuffer.writeUInt32BE(data.length, 6, true);
327
+ }
328
+
329
+ if (options.mask) {
330
+ const mask = getRandomMask();
331
+
332
+ outputBuffer[1] = payloadLength | 0x80;
333
+ outputBuffer[dataOffset - 4] = mask[0];
334
+ outputBuffer[dataOffset - 3] = mask[1];
335
+ outputBuffer[dataOffset - 2] = mask[2];
336
+ outputBuffer[dataOffset - 1] = mask[3];
337
+
338
+ if (mergeBuffers) {
339
+ bufferUtil.mask(data, mask, outputBuffer, dataOffset, data.length);
340
+ } else {
341
+ bufferUtil.mask(data, mask, data, 0, data.length);
342
+ }
343
+ } else {
344
+ outputBuffer[1] = payloadLength;
345
+ if (mergeBuffers) data.copy(outputBuffer, dataOffset);
346
+ }
347
+
348
+ sendFramedData(this, outputBuffer, mergeBuffers ? null : data, cb);
349
+ }
350
+
351
+ /**
352
+ * Executes a queued send operation.
353
+ *
354
+ * @private
355
+ */
356
+ dequeue () {
357
+ if (this.processing) return;
358
+
359
+ const params = this.queue.shift();
360
+ if (!params) return;
361
+
362
+ if (params[1]) this.bufferedBytes -= params[1].length;
363
+ this.processing = true;
364
+
365
+ params[0].apply(this, params.slice(1));
366
+ }
367
+
368
+ /**
369
+ * Signals the completion of a send operation.
370
+ *
371
+ * @private
372
+ */
373
+ continue () {
374
+ process.nextTick(() => {
375
+ this.processing = false;
376
+ this.dequeue();
377
+ });
378
+ }
379
+
380
+ /**
381
+ * Enqueues a send operation.
382
+ *
383
+ * @param {Array} params Send operation parameters.
384
+ * @private
385
+ */
386
+ enqueue (params) {
387
+ if (params[1]) this.bufferedBytes += params[1].length;
388
+ this.queue.push(params);
389
+ this.dequeue();
390
+ }
391
+ }
392
+
393
+ module.exports = Sender;
394
+
395
+ /**
396
+ * Converts an `ArrayBuffer` view into a buffer.
397
+ *
398
+ * @param {(DataView|TypedArray)} view The view to convert
399
+ * @return {Buffer} Converted view
400
+ * @private
401
+ */
402
+ function viewToBuffer (view) {
403
+ const buf = Buffer.from(view.buffer);
404
+
405
+ if (view.byteLength !== view.buffer.byteLength) {
406
+ return buf.slice(view.byteOffset, view.byteOffset + view.byteLength);
407
+ }
408
+
409
+ return buf;
410
+ }
411
+
412
+ /**
413
+ * Generates a random mask.
414
+ *
415
+ * @return {Buffer} The mask
416
+ * @private
417
+ */
418
+ function getRandomMask () {
419
+ return crypto.randomBytes(4);
420
+ }
421
+
422
+ /**
423
+ * Sends a frame.
424
+ *
425
+ * @param {Sender} sender Sender instance
426
+ * @param {Buffer} outputBuffer The data to send
427
+ * @param {Buffer} data Additional data to send if frame is split into two buffers
428
+ * @param {Function} cb Callback
429
+ * @private
430
+ */
431
+ function sendFramedData (sender, outputBuffer, data, cb) {
432
+ if (data) {
433
+ sender._socket.write(outputBuffer);
434
+ sender._socket.write(data, cb);
435
+ } else {
436
+ sender._socket.write(outputBuffer, cb);
437
+ }
438
+ }
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * ws: a node.js websocket client
3
+ * Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
4
+ * MIT Licensed
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ module.exports = () => true;
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * ws: a node.js websocket client
3
+ * Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
4
+ * MIT Licensed
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ try {
10
+ const isValidUTF8 = require('utf-8-validate');
11
+
12
+ module.exports = typeof isValidUTF8 === 'object'
13
+ ? isValidUTF8.Validation.isValidUTF8 // utf-8-validate@<3.0.0
14
+ : isValidUTF8;
15
+ } catch (e) {
16
+ module.exports = require('./Validation.fallback');
17
+ }