UNPKG

4.09 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var WebRTCComms_1 = require("./WebRTCComms");
4var ShuffleStateFactory_1 = require("./ShuffleStateFactory");
5var cyclon_p2p_common_1 = require("cyclon.p2p-common");
6var cyclon_p2p_rtc_client_1 = require("cyclon.p2p-rtc-client");
7var SignallingServerBootstrap_1 = require("./SignallingServerBootstrap");
8var Defaults_1 = require("./Defaults");
9var Builder = /** @class */ (function () {
10 function Builder() {
11 }
12 Builder.prototype.withLogger = function (logger) {
13 this.logger = logger;
14 return this;
15 };
16 Builder.prototype.withSignallingServers = function (signallingServerSpecs) {
17 this.signallingServers = signallingServerSpecs;
18 return this;
19 };
20 Builder.prototype.withStorage = function (storage) {
21 this.storage = storage;
22 return this;
23 };
24 Builder.prototype.withSignallingServerReconnectDelay = function (reconnectDelayInMillis) {
25 this.reconnectDelayInMillis = reconnectDelayInMillis;
26 return this;
27 };
28 Builder.prototype.withChannelStateChangeTimeout = function (channelStateTimeoutMillis) {
29 this.channelStateTimeoutMillis = channelStateTimeoutMillis;
30 return this;
31 };
32 Builder.prototype.withIceServers = function (iceServers) {
33 this.iceServers = iceServers;
34 return this;
35 };
36 Builder.prototype.joiningRooms = function (roomsToJoin) {
37 this.roomsToJoin = roomsToJoin;
38 return this;
39 };
40 Builder.prototype.build = function () {
41 if (!this.result) {
42 this.result = this.doBuild();
43 }
44 return this.result;
45 };
46 Builder.prototype.doBuild = function () {
47 var rtcBuilderResult = cyclon_p2p_rtc_client_1.rtcBuilder()
48 .withLogger(this.getLogger())
49 .withStorage(this.getStorage())
50 .withSignallingServers(this.getSignallingServers())
51 .withIceServers(this.getIceServers())
52 .withChannelStateChangeTimeout(this.getChannelStateTimeout())
53 .withSignallingServerReconnectDelay(this.getReconnectDelay())
54 .build();
55 var shuffleStateFactory = new ShuffleStateFactory_1.ShuffleStateFactory(this.getLogger(), cyclon_p2p_common_1.asyncExecService());
56 var roomsToJoin = this.getRoomsToJoin();
57 return {
58 comms: new WebRTCComms_1.WebRTCComms(rtcBuilderResult.rtc, shuffleStateFactory, this.getLogger(), roomsToJoin),
59 bootstrap: new SignallingServerBootstrap_1.SignallingServerBootstrap(rtcBuilderResult.signallingSocket, new cyclon_p2p_rtc_client_1.HttpRequestService(), roomsToJoin)
60 };
61 };
62 Builder.prototype.getRoomsToJoin = function () {
63 return this.roomsToJoin === undefined ? Defaults_1.DEFAULT_ROOMS_TO_JOIN : this.roomsToJoin;
64 };
65 Builder.prototype.getIceServers = function () {
66 return this.iceServers === undefined ? cyclon_p2p_rtc_client_1.DEFAULT_ICE_SERVERS : this.iceServers;
67 };
68 Builder.prototype.getChannelStateTimeout = function () {
69 return this.channelStateTimeoutMillis === undefined ? cyclon_p2p_rtc_client_1.DEFAULT_CHANNEL_STATE_TIMEOUT_MS : this.channelStateTimeoutMillis;
70 };
71 Builder.prototype.getReconnectDelay = function () {
72 return this.reconnectDelayInMillis === undefined ? cyclon_p2p_rtc_client_1.DEFAULT_SIGNALLING_SERVER_RECONNECT_DELAY_MS : this.reconnectDelayInMillis;
73 };
74 Builder.prototype.getLogger = function () {
75 return this.logger || cyclon_p2p_common_1.consoleLogger();
76 };
77 Builder.prototype.getStorage = function () {
78 if (!this.storage) {
79 this.storage = cyclon_p2p_common_1.newInMemoryStorage();
80 }
81 return this.storage;
82 };
83 Builder.prototype.getSignallingServers = function () {
84 return this.signallingServers === undefined ? JSON.parse(JSON.stringify(cyclon_p2p_rtc_client_1.DEFAULT_SIGNALLING_SERVERS)) : this.signallingServers;
85 };
86 return Builder;
87}());
88exports.Builder = Builder;
89//# sourceMappingURL=Builder.js.map
\No newline at end of file