-
Notifications
You must be signed in to change notification settings - Fork 15
/
spdy.js
48 lines (33 loc) · 1.02 KB
/
spdy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
var jschan = require('jschan');
var inherits = require('inherits');
var Server = require('./lib/server');
var Client = require('./lib/client');
function SPDYServer(opts) {
if (!(this instanceof SPDYServer)) {
return new SPDYServer(opts);
}
Server.call(this, opts);
}
inherits(SPDYServer, Server);
SPDYServer.prototype._buildServer = function(opts) {
var server = jschan.spdyServer(opts);
server.listen(opts.port || 0);
this.address = server.address.bind(server);
server.on('listening', this.emit.bind(this, 'ready', this));
return server;
};
module.exports.server = SPDYServer;
function SPDYClient(opts) {
if (!(this instanceof SPDYClient)) {
return new SPDYClient(opts);
}
Client.call(this, opts);
}
inherits(SPDYClient, Client);
SPDYClient.prototype._buildSession = function(opts) {
var client = jschan.spdyClientSession(opts);
client.agent._spdyState.socket.on('secureConnect', this.emit.bind(this, 'ready', this));
return client;
};
module.exports.client = SPDYClient;