forked from lynckia/licode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpine.js
88 lines (78 loc) · 2.58 KB
/
Spine.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const nativeConnection = require('./simpleNativeConnection');
const logger = require('./logger').logger;
exports.buildSpine = (configuration) => {
const that = {};
that.nativeConnections = [];
const log = logger.getLogger('Spine');
const streamConfig = Object.assign({}, configuration);
let streamPublishConfig;
let streamSubscribeConfig;
if (streamConfig.publishConfig) {
streamPublishConfig = {
publishConfig: streamConfig.publishConfig,
serverUrl: streamConfig.basicExampleUrl,
};
if (streamConfig.publishersAreSubscribers) {
streamPublishConfig.subscribeConfig = streamConfig.subscribeConfig;
}
log.info('publish Configuration: ', streamSubscribeConfig);
}
if (streamConfig.subscribeConfig) {
streamSubscribeConfig = {
subscribeConfig: streamConfig.subscribeConfig,
serverUrl: streamConfig.basicExampleUrl,
};
log.info('Subscribe Configuration: ', streamSubscribeConfig);
}
const startSingleNativeClient = (clientConfig) => {
const nativeClient = nativeConnection.ErizoSimpleNativeConnection(clientConfig,
(msg) => {
log.debug('Callback from nativeClient', msg);
},
(msg) => {
log.debug('Error from nativeClient', msg);
});
that.nativeConnections.push(nativeClient);
};
const startStreams = (stConf, num, time) => {
let started = 0;
const interval = setInterval(() => {
started += 1;
if (started >= num) {
log.info('All streams have been started');
clearInterval(interval);
}
log.info('Will start stream with config', stConf);
startSingleNativeClient(stConf);
}, time);
};
that.getAllStreamStats = () => {
const promises = [];
that.nativeConnections.forEach((connection) => {
promises.push(connection.getStats());
});
return Promise.all(promises);
};
that.getAllStreamStatuses = () => {
const statuses = [];
that.nativeConnections.forEach((connection) => {
statuses.push(connection.getStatus());
});
return statuses;
};
that.run = () => {
log.info('Starting ', streamConfig.numSubscribers, 'subscriber streams',
'and', streamConfig.numPublishers, 'publisherStreams');
if (streamSubscribeConfig && streamConfig.numSubscribers) {
startStreams(streamSubscribeConfig,
streamConfig.numSubscribers,
streamConfig.connectionCreationInterval);
}
if (streamPublishConfig && streamConfig.numPublishers) {
startStreams(streamPublishConfig,
streamConfig.numPublishers,
streamConfig.connectionCreationInterval);
}
};
return that;
};