1 | 'use strict'
|
2 |
|
3 | function attachPush (req) {
|
4 | var handle = req.socket._handle
|
5 |
|
6 | handle.getStream(function (stream) {
|
7 | stream.on('pushPromise', function (push) {
|
8 | req.emit('push', push)
|
9 | })
|
10 | })
|
11 | }
|
12 |
|
13 | exports.onNewListener = function onNewListener (type) {
|
14 | var req = this
|
15 |
|
16 | if (type !== 'push') {
|
17 | return
|
18 | }
|
19 |
|
20 |
|
21 | if (req.listeners('push').length !== 0) {
|
22 | return
|
23 | }
|
24 |
|
25 | if (!req.socket) {
|
26 | req.on('socket', function () {
|
27 | attachPush(req)
|
28 | })
|
29 | return
|
30 | }
|
31 |
|
32 | attachPush(req)
|
33 | }
|