0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

27
web/node_modules/eventsource/.editorconfig generated vendored Normal file
View file

@ -0,0 +1,27 @@
# http://editorconfig.org
root = true
[*]
# Use hard or soft tabs
indent_style = space
# Size of a single indent
indent_size = tab
# Number of columns representing a tab character
tab_width = 2
# Use line-feed as EOL indicator
end_of_line = lf
# Use UTF-8 character encoding for all files
charset = utf-8
# Remove any whitespace characters preceding newline characters
trim_trailing_whitespace = true
# Ensure file ends with a newline when saving
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

10
web/node_modules/eventsource/.travis.yml generated vendored Normal file
View file

@ -0,0 +1,10 @@
language: node_js
node_js:
- "0.12"
- "4"
- "6"
- "8"
- "10"
- "12"
- "13"

13
web/node_modules/eventsource/CONTRIBUTING.md generated vendored Normal file
View file

@ -0,0 +1,13 @@
# Contributing to EventSource
If you add or fix something, add tests.
## Release process
Update `HISTORY.md`, Then:
npm outdated --depth 0 # See if you can upgrade something
npm run polyfill
git commit ...
npm version [major|minor|patch]
npm publish

143
web/node_modules/eventsource/HISTORY.md generated vendored Normal file
View file

@ -0,0 +1,143 @@
# [1.1.0](https://github.com/EventSource/eventsource/compare/v1.0.7...v1.1.0)
* Improve performance for large messages across many chunks ([#130](https://github.com/EventSource/eventsource/pull/130) Trent Willis)
* Add `createConnection` option for http or https requests ([#120](https://github.com/EventSource/eventsource/pull/120) Vasily Lavrov)
* Support HTTP 302 redirects ([#116](https://github.com/EventSource/eventsource/pull/116) Ryan Bonte)
* Prevent sequential errors from attempting multiple reconnections ([#125](https://github.com/EventSource/eventsource/pull/125) David Patty)
* Add `new` to correct test ([#111](https://github.com/EventSource/eventsource/pull/101) Stéphane Alnet)
* Fix reconnections attempts now happen more than once ([#136](https://github.com/EventSource/eventsource/pull/136) Icy Fish)
# [1.0.7](https://github.com/EventSource/eventsource/compare/v1.0.6...v1.0.7)
* Add dispatchEvent to EventSource ([#101](https://github.com/EventSource/eventsource/pull/101) Ali Afroozeh)
* Added `checkServerIdentity` option ([#104](https://github.com/EventSource/eventsource/pull/104) cintolas)
* Surface request error message ([#107](https://github.com/EventSource/eventsource/pull/107) RasPhilCo)
# [1.0.6](https://github.com/EventSource/eventsource/compare/v1.0.5...v1.0.6)
* Fix issue where a unicode sequence split in two chunks would lead to invalid messages ([#108](https://github.com/EventSource/eventsource/pull/108) Espen Hovlandsdal)
* Change example to use `eventsource/ssestream` (Aslak Hellesøy)
# [1.0.5](https://github.com/EventSource/eventsource/compare/v1.0.4...v1.0.5)
* Check for `window` existing before polyfilling. ([#80](https://github.com/EventSource/eventsource/pull/80) Neftaly Hernandez)
# [1.0.4](https://github.com/EventSource/eventsource/compare/v1.0.2...v1.0.4)
* Pass withCredentials on to the XHR. ([#79](https://github.com/EventSource/eventsource/pull/79) Ken Mayer)
# [1.0.2](https://github.com/EventSource/eventsource/compare/v1.0.1...v1.0.2)
* Fix proxy not working when proxy and target URL uses different protocols. ([#76](https://github.com/EventSource/eventsource/pull/76) Espen Hovlandsdal)
* Make `close()` a prototype method instead of an instance method. ([#77](https://github.com/EventSource/eventsource/pull/77) Espen Hovlandsdal)
# [1.0.1](https://github.com/EventSource/eventsource/compare/v1.0.0...v1.0.1)
* Reconnect if server responds with HTTP 500, 502, 503 or 504. ([#74](https://github.com/EventSource/eventsource/pull/74) Vykintas Narmontas)
# [1.0.0](https://github.com/EventSource/eventsource/compare/v0.2.3...v1.0.0)
* Add missing `removeEventListener`-method. ([#51](https://github.com/EventSource/eventsource/pull/51) Yucheng Tu / Espen Hovlandsdal)
* Fix EventSource reconnecting on non-200 responses. ([af84476](https://github.com/EventSource/eventsource/commit/af84476b519a01e61b8c80727261df52ae40022c) Espen Hovlandsdal)
* Add ability to customize https options. ([#53](https://github.com/EventSource/eventsource/pull/53) Rafael Alfaro)
* Add readyState constants to EventSource instances. ([#66](https://github.com/EventSource/eventsource/pull/66) Espen Hovlandsdal)
# [0.2.3](https://github.com/EventSource/eventsource/compare/v0.2.2...v0.2.3)
* Fix `onConnectionClosed` firing multiple times resulting in multiple connections. ([#61](https://github.com/EventSource/eventsource/pull/61) Phil Strong / Duncan Wong)
* Remove unneeded isPlainObject check for headers. ([#64](https://github.com/EventSource/eventsource/pull/64) David Mark)
# [0.2.2](https://github.com/EventSource/eventsource/compare/v0.2.1...v0.2.2)
* Don't include test files in npm package. ([#56](https://github.com/EventSource/eventsource/pull/56) eanplatter)
# [0.2.1](https://github.com/EventSource/eventsource/compare/v0.2.0...v0.2.1)
* Fix `close()` for polyfill. ([#52](https://github.com/EventSource/eventsource/pull/52) brian-medendorp)
* Add http/https proxy function. ([#46](https://github.com/EventSource/eventsource/pull/46) Eric Lu)
* Fix reconnect for polyfill. Only disable reconnect when server status is 204. (Aslak Hellesøy).
* Drop support for Node 0.10.x and older (Aslak Hellesøy).
# [0.2.0](https://github.com/EventSource/eventsource/compare/v0.1.6...v0.2.0)
* Renamed repository to `eventsource` (since it's not just Node, but also browser polyfill). (Aslak Hellesøy).
* Compatibility with webpack/browserify. ([#44](https://github.com/EventSource/eventsource/pull/44) Adriano Raiano).
# [0.1.6](https://github.com/EventSource/eventsource/compare/v0.1.5...v0.1.6)
* Ignore headers without a value. ([#41](https://github.com/EventSource/eventsource/issues/41), [#43](https://github.com/EventSource/eventsource/pull/43) Adriano Raiano)
# [0.1.5](https://github.com/EventSource/eventsource/compare/v0.1.4...v0.1.5)
* Refactor tests to support Node.js 0.12.0 and Io.js 1.1.0. (Aslak Hellesøy)
# [0.1.4](https://github.com/EventSource/eventsource/compare/v0.1.3...master)
* Bugfix: Added missing origin property. ([#39](https://github.com/EventSource/eventsource/pull/39), [#38](https://github.com/EventSource/eventsource/issues/38) Arnout Kazemier)
* Expose `status` property on `error` events. ([#40](https://github.com/EventSource/eventsource/pull/40) Adriano Raiano)
# [0.1.3](https://github.com/EventSource/eventsource/compare/v0.1.2...v0.1.3)
* Bugfix: Made message properties enumerable. ([#37](https://github.com/EventSource/eventsource/pull/37) Golo Roden)
# [0.1.2](https://github.com/EventSource/eventsource/compare/v0.1.1...v0.1.2)
* Bugfix: Blank lines not read. ([#35](https://github.com/EventSource/eventsource/issues/35), [#36](https://github.com/EventSource/eventsource/pull/36) Lesterpig)
# [0.1.1](https://github.com/EventSource/eventsource/compare/v0.1.0...v0.1.1)
* Bugfix: Fix message type. ([#33](https://github.com/EventSource/eventsource/pull/33) Romain Gauthier)
# [0.1.0](https://github.com/EventSource/eventsource/compare/v0.0.10...v0.1.0)
* Bugfix: High CPU usage by replacing Jison with port of WebKit's parser. ([#25](https://github.com/EventSource/eventsource/issues/25), [#32](https://github.com/EventSource/eventsource/pull/32), [#18](https://github.com/EventSource/eventsource/issues/18) qqueue)
* Reformatted all code to 2 spaces.
# [0.0.10](https://github.com/EventSource/eventsource/compare/v0.0.9...v0.0.10)
* Provide `Event` argument on `open` and `error` event ([#30](https://github.com/EventSource/eventsource/issues/30), [#31](https://github.com/EventSource/eventsource/pull/31) Donghwan Kim)
* Expose `lastEventId` on messages. ([#28](https://github.com/EventSource/eventsource/pull/28) mbieser)
# [0.0.9](https://github.com/EventSource/eventsource/compare/v0.0.8...v0.0.9)
* Bugfix: old "last-event-id" used on reconnect ([#27](https://github.com/EventSource/eventsource/pull/27) Aslak Hellesøy)
# [0.0.8](https://github.com/EventSource/eventsource/compare/v0.0.7...v0.0.8)
* Bugfix: EventSource still reconnected when closed ([#24](https://github.com/EventSource/eventsource/pull/24) FrozenCow)
* Allow unauthorized HTTPS connections by setting `rejectUnauthorized` to false. (Aslak Hellesøy)
# [0.0.7](https://github.com/EventSource/eventsource/compare/v0.0.6...v0.0.7)
* Explicitly raise an error when server returns http 403 and don't continue ([#20](https://github.com/EventSource/eventsource/pull/20) Scott Moak)
* Added ability to send custom http headers to server ([#21](https://github.com/EventSource/eventsource/pull/21), [#9](https://github.com/EventSource/eventsource/issues/9) Scott Moak)
* Fix Unicode support to cope with Javascript Unicode size limitations ([#23](https://github.com/EventSource/eventsource/pull/23), [#22](https://github.com/EventSource/eventsource/issues/22) Devon Adkisson)
* Graceful handling of parse errors ([#19](https://github.com/EventSource/eventsource/issues/19) Aslak Hellesøy)
* Switched from testing with Nodeunit to Mocha (Aslak Hellesøy)
# [0.0.6](https://github.com/EventSource/eventsource/compare/v0.0.5...v0.0.6)
* Add Accept: text/event-stream header ([#17](https://github.com/EventSource/eventsource/pull/17) William Wicks)
# [0.0.5](https://github.com/EventSource/eventsource/compare/v0.0.4...v0.0.5)
* Add no-cache and https support ([#10](https://github.com/EventSource/eventsource/pull/10) Einar Otto Stangvik)
* Ensure that Last-Event-ID is sent to the server for reconnects, as defined in the spec ([#8](https://github.com/EventSource/eventsource/pull/8) Einar Otto Stangvik)
* Verify that CR and CRLF are accepted alongside LF ([#7](https://github.com/EventSource/eventsource/pull/7) Einar Otto Stangvik)
* Emit 'open' event ([#4](https://github.com/EventSource/eventsource/issues/4) Einar Otto Stangvik)
# [0.0.4](https://github.com/EventSource/eventsource/compare/v0.0.3...v0.0.4)
* Automatic reconnect every second if the server is down. Reconnect interval can be set with `reconnectInterval` (not in W3C spec). (Aslak Hellesøy)
# [0.0.3](https://github.com/EventSource/eventsource/compare/v0.0.2...v0.0.3)
* Jison based eventstream parser ([#2](https://github.com/EventSource/eventsource/pull/2) Einar Otto Stangvik)
# [0.0.2](https://github.com/EventSource/eventsource/compare/v0.0.1...v0.0.2)
* Use native EventListener (Aslak Hellesøy)
# 0.0.1
* First release

22
web/node_modules/eventsource/LICENSE generated vendored Normal file
View file

@ -0,0 +1,22 @@
The MIT License
Copyright (c) EventSource GitHub organisation
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

89
web/node_modules/eventsource/README.md generated vendored Normal file
View file

@ -0,0 +1,89 @@
# EventSource [![npm version](http://img.shields.io/npm/v/eventsource.svg?style=flat-square)](http://browsenpm.org/package/eventsource)[![Build Status](http://img.shields.io/travis/EventSource/eventsource/master.svg?style=flat-square)](https://travis-ci.org/EventSource/eventsource)[![NPM Downloads](https://img.shields.io/npm/dm/eventsource.svg?style=flat-square)](http://npm-stat.com/charts.html?package=eventsource&from=2015-09-01)[![Dependencies](https://img.shields.io/david/EventSource/eventsource.svg?style=flat-square)](https://david-dm.org/EventSource/eventsource)
This library is a pure JavaScript implementation of the [EventSource](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events) client. The API aims to be W3C compatible.
You can use it with Node.js or as a browser polyfill for
[browsers that don't have native `EventSource` support](http://caniuse.com/#feat=eventsource).
## Install
npm install eventsource
## Example
npm install
node ./example/sse-server.js
node ./example/sse-client.js # Node.js client
open http://localhost:8080 # Browser client - both native and polyfill
curl http://localhost:8080/sse # Enjoy the simplicity of SSE
## Browser Polyfill
Just add `example/eventsource-polyfill.js` file to your web page:
```html
<script src=/eventsource-polyfill.js></script>
```
Now you will have two global constructors:
```javascript
window.EventSourcePolyfill
window.EventSource // Unchanged if browser has defined it. Otherwise, same as window.EventSourcePolyfill
```
If you're using [webpack](https://webpack.github.io/) or [browserify](http://browserify.org/)
you can of course build your own. (The `example/eventsource-polyfill.js` is built with webpack).
## Extensions to the W3C API
### Setting HTTP request headers
You can define custom HTTP headers for the initial HTTP request. This can be useful for e.g. sending cookies
or to specify an initial `Last-Event-ID` value.
HTTP headers are defined by assigning a `headers` attribute to the optional `eventSourceInitDict` argument:
```javascript
var eventSourceInitDict = {headers: {'Cookie': 'test=test'}};
var es = new EventSource(url, eventSourceInitDict);
```
### Allow unauthorized HTTPS requests
By default, https requests that cannot be authorized will cause the connection to fail and an exception
to be emitted. You can override this behaviour, along with other https options:
```javascript
var eventSourceInitDict = {https: {rejectUnauthorized: false}};
var es = new EventSource(url, eventSourceInitDict);
```
Note that for Node.js < v0.10.x this option has no effect - unauthorized HTTPS requests are *always* allowed.
### HTTP status code on error events
Unauthorized and redirect error status codes (for example 401, 403, 301, 307) are available in the `status` property in the error event.
```javascript
es.onerror = function (err) {
if (err) {
if (err.status === 401 || err.status === 403) {
console.log('not authorized');
}
}
};
```
### HTTP/HTTPS proxy
You can define a `proxy` option for the HTTP request to be used. This is typically useful if you are behind a corporate firewall.
```javascript
var es = new EventSource(url, {proxy: 'http://your.proxy.com'});
```
## License
MIT-licensed. See LICENSE

File diff suppressed because it is too large Load diff

40
web/node_modules/eventsource/example/index.html generated vendored Normal file
View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<style>
.col {
float:left;
width:50%;
left:50%;
}
</style>
</head>
<body>
<div class=col>
<h2>EventSource</h2>
<ul id=es-messages>
</ul>
</div>
<div class=col>
<h2>EventSourcePolyfill</h2>
<ul id=es-polyfill-messages>
</ul>
</div>
<script src=/eventsource-polyfill.js></script>
<script>
function subscribe(es, ul) {
es.addEventListener('server-time', function (e) {
var li = document.createElement("LI");
li.appendChild(document.createTextNode(e.data));
ul.appendChild(li);
});
}
subscribe(new EventSource('/sse'), document.getElementById('es-messages'));
subscribe(new EventSourcePolyfill('/sse'), document.getElementById('es-polyfill-messages'));
</script>
</body>

5
web/node_modules/eventsource/example/sse-client.js generated vendored Normal file
View file

@ -0,0 +1,5 @@
var EventSource = require('..')
var es = new EventSource('http://localhost:8080/sse')
es.addEventListener('server-time', function (e) {
console.log(e.data)
})

29
web/node_modules/eventsource/example/sse-server.js generated vendored Normal file
View file

@ -0,0 +1,29 @@
const express = require('express')
const serveStatic = require('serve-static')
const SseStream = require('ssestream')
const app = express()
app.use(serveStatic(__dirname))
app.get('/sse', (req, res) => {
console.log('new connection')
const sseStream = new SseStream(req)
sseStream.pipe(res)
const pusher = setInterval(() => {
sseStream.write({
event: 'server-time',
data: new Date().toTimeString()
})
}, 1000)
res.on('close', () => {
console.log('lost connection')
clearInterval(pusher)
sseStream.unpipe(res)
})
})
app.listen(8080, (err) => {
if (err) throw err
console.log('server ready on http://localhost:8080')
})

View file

@ -0,0 +1,9 @@
var EventSource = require('./eventsource')
if (typeof window === 'object') {
window.EventSourcePolyfill = EventSource
if (!window.EventSource) window.EventSource = EventSource
module.exports = window.EventSource
} else {
module.exports = EventSource
}

445
web/node_modules/eventsource/lib/eventsource.js generated vendored Normal file
View file

@ -0,0 +1,445 @@
var original = require('original')
var parse = require('url').parse
var events = require('events')
var https = require('https')
var http = require('http')
var util = require('util')
var httpsOptions = [
'pfx', 'key', 'passphrase', 'cert', 'ca', 'ciphers',
'rejectUnauthorized', 'secureProtocol', 'servername', 'checkServerIdentity'
]
var bom = [239, 187, 191]
var colon = 58
var space = 32
var lineFeed = 10
var carriageReturn = 13
function hasBom (buf) {
return bom.every(function (charCode, index) {
return buf[index] === charCode
})
}
/**
* Creates a new EventSource object
*
* @param {String} url the URL to which to connect
* @param {Object} [eventSourceInitDict] extra init params. See README for details.
* @api public
**/
function EventSource (url, eventSourceInitDict) {
var readyState = EventSource.CONNECTING
Object.defineProperty(this, 'readyState', {
get: function () {
return readyState
}
})
Object.defineProperty(this, 'url', {
get: function () {
return url
}
})
var self = this
self.reconnectInterval = 1000
self.connectionInProgress = false
function onConnectionClosed (message) {
if (readyState === EventSource.CLOSED) return
readyState = EventSource.CONNECTING
_emit('error', new Event('error', {message: message}))
// The url may have been changed by a temporary
// redirect. If that's the case, revert it now.
if (reconnectUrl) {
url = reconnectUrl
reconnectUrl = null
}
setTimeout(function () {
if (readyState !== EventSource.CONNECTING || self.connectionInProgress) {
return
}
self.connectionInProgress = true
connect()
}, self.reconnectInterval)
}
var req
var lastEventId = ''
if (eventSourceInitDict && eventSourceInitDict.headers && eventSourceInitDict.headers['Last-Event-ID']) {
lastEventId = eventSourceInitDict.headers['Last-Event-ID']
delete eventSourceInitDict.headers['Last-Event-ID']
}
var discardTrailingNewline = false
var data = ''
var eventName = ''
var reconnectUrl = null
function connect () {
var options = parse(url)
var isSecure = options.protocol === 'https:'
options.headers = { 'Cache-Control': 'no-cache', 'Accept': 'text/event-stream' }
if (lastEventId) options.headers['Last-Event-ID'] = lastEventId
if (eventSourceInitDict && eventSourceInitDict.headers) {
for (var i in eventSourceInitDict.headers) {
var header = eventSourceInitDict.headers[i]
if (header) {
options.headers[i] = header
}
}
}
// Legacy: this should be specified as `eventSourceInitDict.https.rejectUnauthorized`,
// but for now exists as a backwards-compatibility layer
options.rejectUnauthorized = !(eventSourceInitDict && !eventSourceInitDict.rejectUnauthorized)
if (eventSourceInitDict && eventSourceInitDict.createConnection !== undefined) {
options.createConnection = eventSourceInitDict.createConnection
}
// If specify http proxy, make the request to sent to the proxy server,
// and include the original url in path and Host headers
var useProxy = eventSourceInitDict && eventSourceInitDict.proxy
if (useProxy) {
var proxy = parse(eventSourceInitDict.proxy)
isSecure = proxy.protocol === 'https:'
options.protocol = isSecure ? 'https:' : 'http:'
options.path = url
options.headers.Host = options.host
options.hostname = proxy.hostname
options.host = proxy.host
options.port = proxy.port
}
// If https options are specified, merge them into the request options
if (eventSourceInitDict && eventSourceInitDict.https) {
for (var optName in eventSourceInitDict.https) {
if (httpsOptions.indexOf(optName) === -1) {
continue
}
var option = eventSourceInitDict.https[optName]
if (option !== undefined) {
options[optName] = option
}
}
}
// Pass this on to the XHR
if (eventSourceInitDict && eventSourceInitDict.withCredentials !== undefined) {
options.withCredentials = eventSourceInitDict.withCredentials
}
req = (isSecure ? https : http).request(options, function (res) {
self.connectionInProgress = false
// Handle HTTP errors
if (res.statusCode === 500 || res.statusCode === 502 || res.statusCode === 503 || res.statusCode === 504) {
_emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage}))
onConnectionClosed()
return
}
// Handle HTTP redirects
if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {
if (!res.headers.location) {
// Server sent redirect response without Location header.
_emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage}))
return
}
if (res.statusCode === 307) reconnectUrl = url
url = res.headers.location
process.nextTick(connect)
return
}
if (res.statusCode !== 200) {
_emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage}))
return self.close()
}
readyState = EventSource.OPEN
res.on('close', function () {
res.removeAllListeners('close')
res.removeAllListeners('end')
onConnectionClosed()
})
res.on('end', function () {
res.removeAllListeners('close')
res.removeAllListeners('end')
onConnectionClosed()
})
_emit('open', new Event('open'))
// text/event-stream parser adapted from webkit's
// Source/WebCore/page/EventSource.cpp
var isFirst = true
var buf
var startingPos = 0
var startingFieldLength = -1
res.on('data', function (chunk) {
buf = buf ? Buffer.concat([buf, chunk]) : chunk
if (isFirst && hasBom(buf)) {
buf = buf.slice(bom.length)
}
isFirst = false
var pos = 0
var length = buf.length
while (pos < length) {
if (discardTrailingNewline) {
if (buf[pos] === lineFeed) {
++pos
}
discardTrailingNewline = false
}
var lineLength = -1
var fieldLength = startingFieldLength
var c
for (var i = startingPos; lineLength < 0 && i < length; ++i) {
c = buf[i]
if (c === colon) {
if (fieldLength < 0) {
fieldLength = i - pos
}
} else if (c === carriageReturn) {
discardTrailingNewline = true
lineLength = i - pos
} else if (c === lineFeed) {
lineLength = i - pos
}
}
if (lineLength < 0) {
startingPos = length - pos
startingFieldLength = fieldLength
break
} else {
startingPos = 0
startingFieldLength = -1
}
parseEventStreamLine(buf, pos, fieldLength, lineLength)
pos += lineLength + 1
}
if (pos === length) {
buf = void 0
} else if (pos > 0) {
buf = buf.slice(pos)
}
})
})
req.on('error', function (err) {
self.connectionInProgress = false
onConnectionClosed(err.message)
})
if (req.setNoDelay) req.setNoDelay(true)
req.end()
}
connect()
function _emit () {
if (self.listeners(arguments[0]).length > 0) {
self.emit.apply(self, arguments)
}
}
this._close = function () {
if (readyState === EventSource.CLOSED) return
readyState = EventSource.CLOSED
if (req.abort) req.abort()
if (req.xhr && req.xhr.abort) req.xhr.abort()
}
function parseEventStreamLine (buf, pos, fieldLength, lineLength) {
if (lineLength === 0) {
if (data.length > 0) {
var type = eventName || 'message'
_emit(type, new MessageEvent(type, {
data: data.slice(0, -1), // remove trailing newline
lastEventId: lastEventId,
origin: original(url)
}))
data = ''
}
eventName = void 0
} else if (fieldLength > 0) {
var noValue = fieldLength < 0
var step = 0
var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength)).toString()
if (noValue) {
step = lineLength
} else if (buf[pos + fieldLength + 1] !== space) {
step = fieldLength + 1
} else {
step = fieldLength + 2
}
pos += step
var valueLength = lineLength - step
var value = buf.slice(pos, pos + valueLength).toString()
if (field === 'data') {
data += value + '\n'
} else if (field === 'event') {
eventName = value
} else if (field === 'id') {
lastEventId = value
} else if (field === 'retry') {
var retry = parseInt(value, 10)
if (!Number.isNaN(retry)) {
self.reconnectInterval = retry
}
}
}
}
}
module.exports = EventSource
util.inherits(EventSource, events.EventEmitter)
EventSource.prototype.constructor = EventSource; // make stacktraces readable
['open', 'error', 'message'].forEach(function (method) {
Object.defineProperty(EventSource.prototype, 'on' + method, {
/**
* Returns the current listener
*
* @return {Mixed} the set function or undefined
* @api private
*/
get: function get () {
var listener = this.listeners(method)[0]
return listener ? (listener._listener ? listener._listener : listener) : undefined
},
/**
* Start listening for events
*
* @param {Function} listener the listener
* @return {Mixed} the set function or undefined
* @api private
*/
set: function set (listener) {
this.removeAllListeners(method)
this.addEventListener(method, listener)
}
})
})
/**
* Ready states
*/
Object.defineProperty(EventSource, 'CONNECTING', {enumerable: true, value: 0})
Object.defineProperty(EventSource, 'OPEN', {enumerable: true, value: 1})
Object.defineProperty(EventSource, 'CLOSED', {enumerable: true, value: 2})
EventSource.prototype.CONNECTING = 0
EventSource.prototype.OPEN = 1
EventSource.prototype.CLOSED = 2
/**
* Closes the connection, if one is made, and sets the readyState attribute to 2 (closed)
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventSource/close
* @api public
*/
EventSource.prototype.close = function () {
this._close()
}
/**
* Emulates the W3C Browser based WebSocket interface using addEventListener.
*
* @param {String} type A string representing the event type to listen out for
* @param {Function} listener callback
* @see https://developer.mozilla.org/en/DOM/element.addEventListener
* @see http://dev.w3.org/html5/websockets/#the-websocket-interface
* @api public
*/
EventSource.prototype.addEventListener = function addEventListener (type, listener) {
if (typeof listener === 'function') {
// store a reference so we can return the original function again
listener._listener = listener
this.on(type, listener)
}
}
/**
* Emulates the W3C Browser based WebSocket interface using dispatchEvent.
*
* @param {Event} event An event to be dispatched
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
* @api public
*/
EventSource.prototype.dispatchEvent = function dispatchEvent (event) {
if (!event.type) {
throw new Error('UNSPECIFIED_EVENT_TYPE_ERR')
}
// if event is instance of an CustomEvent (or has 'details' property),
// send the detail object as the payload for the event
this.emit(event.type, event.detail)
}
/**
* Emulates the W3C Browser based WebSocket interface using removeEventListener.
*
* @param {String} type A string representing the event type to remove
* @param {Function} listener callback
* @see https://developer.mozilla.org/en/DOM/element.removeEventListener
* @see http://dev.w3.org/html5/websockets/#the-websocket-interface
* @api public
*/
EventSource.prototype.removeEventListener = function removeEventListener (type, listener) {
if (typeof listener === 'function') {
listener._listener = undefined
this.removeListener(type, listener)
}
}
/**
* W3C Event
*
* @see http://www.w3.org/TR/DOM-Level-3-Events/#interface-Event
* @api private
*/
function Event (type, optionalProperties) {
Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true })
if (optionalProperties) {
for (var f in optionalProperties) {
if (optionalProperties.hasOwnProperty(f)) {
Object.defineProperty(this, f, { writable: false, value: optionalProperties[f], enumerable: true })
}
}
}
}
/**
* W3C MessageEvent
*
* @see http://www.w3.org/TR/webmessaging/#event-definitions
* @api private
*/
function MessageEvent (type, eventInitDict) {
Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true })
for (var f in eventInitDict) {
if (eventInitDict.hasOwnProperty(f)) {
Object.defineProperty(this, f, { writable: false, value: eventInitDict[f], enumerable: true })
}
}
}

59
web/node_modules/eventsource/package.json generated vendored Normal file
View file

@ -0,0 +1,59 @@
{
"name": "eventsource",
"version": "1.1.0",
"description": "W3C compliant EventSource client for Node.js and browser (polyfill)",
"keywords": [
"eventsource",
"http",
"streaming",
"sse",
"polyfill"
],
"homepage": "http://github.com/EventSource/eventsource",
"author": "Aslak Hellesøy <aslak.hellesoy@gmail.com>",
"repository": {
"type": "git",
"url": "git://github.com/EventSource/eventsource.git"
},
"bugs": {
"url": "http://github.com/EventSource/eventsource/issues"
},
"directories": {
"lib": "./lib"
},
"main": "./lib/eventsource",
"license": "MIT",
"licenses": [
{
"type": "MIT",
"url": "http://github.com/EventSource/eventsource/raw/master/LICENSE"
}
],
"devDependencies": {
"buffer-from": "^1.1.1",
"express": "^4.15.3",
"mocha": "^3.5.3",
"nyc": "^11.2.1",
"serve-static": "^1.12.3",
"ssestream": "^1.0.0",
"standard": "^10.0.2",
"webpack": "^3.5.6"
},
"scripts": {
"test": "mocha --reporter spec && standard",
"polyfill": "webpack lib/eventsource-polyfill.js example/eventsource-polyfill.js",
"postpublish": "git push && git push --tags",
"coverage": "nyc --reporter=html --reporter=text _mocha --reporter spec"
},
"engines": {
"node": ">=0.12.0"
},
"dependencies": {
"original": "^1.0.0"
},
"standard": {
"ignore": [
"example/eventsource-polyfill.js"
]
}
}