diffusion
Version:
Diffusion JavaScript client
74 lines (73 loc) • 3.58 kB
JavaScript
;
/**
* @module Client
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.create = exports.createShared = exports.createInternal = void 0;
var errors_1 = require("./../../errors/errors");
var internal_session_impl_1 = require("./../client/internal-session-impl");
var service_registry_1 = require("./../client/service-registry");
var monitored_ping_service_1 = require("./../client/services/monitored-ping-service");
var notify_subscription_service_1 = require("./../client/services/notify-subscription-service");
var notify_unsubscription_service_1 = require("./../client/services/notify-unsubscription-service");
var ping_service_1 = require("./../client/services/ping-service");
var ConversationSet = require("./../conversation/conversation-set");
var ping_services_1 = require("./../services/ping-services");
var Services = require("./../services/services");
var require_non_null_1 = require("./../util/require-non-null");
var ConnectionFactory = require("./../v4-stack/connection-factory");
var internal_session_webworker_proxy_1 = require("./../webworker/client/internal-session-webworker-proxy");
var shared_workers_1 = require("./../webworker/client/shared-workers");
/**
* Create a new internal session
*
* @param options the options passed to the session
* @return a new internal session
* @throws a {@link NullValueError} if `options` is `undefined`
*/
function createInternal(options) {
options = require_non_null_1.requireNonNull(options, 'options');
var serviceRegistry = new service_registry_1.ServiceRegistryImpl();
// assign default service implementations
serviceRegistry.add(ping_services_1.USER_PING, ping_service_1.pingService);
serviceRegistry.add(ping_services_1.SYSTEM_PING, monitored_ping_service_1.monitoredPingService);
serviceRegistry.add(Services.NOTIFY_SUBSCRIPTION, notify_subscription_service_1.notifySubscriptionService);
serviceRegistry.add(Services.UNSUBSCRIPTION_NOTIFICATION, notify_unsubscription_service_1.notifyUnsubscriptionService);
return new internal_session_impl_1.InternalSessionImpl(ConversationSet.create, serviceRegistry, ConnectionFactory.create, options);
}
exports.createInternal = createInternal;
/**
* Create a new internal session factory that connects to a shared session in a webworker
*
* @param options the options passed to the session
* @return a new internal session
*/
function createShared(name, workerJs) {
var serviceRegistry = new service_registry_1.ServiceRegistryImpl();
var connector = new shared_workers_1.SharedSessionConnector(name, workerJs);
var conversationSetFactory = shared_workers_1.getSharedConversationSetFactory(connector);
return function (options) {
return new internal_session_webworker_proxy_1.InternalSessionWebworkerProxy(conversationSetFactory, serviceRegistry, connector, options);
};
}
exports.createShared = createShared;
/**
* Create a new internal session factory
*
* @param options the options passed to the session
* @return a new internal session
*
* @throws a {@link NullValueError} if only one of `name` or `workerJs` is `undefined`
*/
function create(name, workerJs) {
if (name === undefined && workerJs === undefined) {
return createInternal;
}
else if (name !== undefined && workerJs !== undefined) {
return createShared(name, workerJs);
}
else {
throw new errors_1.NullValueError('Missing parameter "name" or "workerJs" when creating a shared session');
}
}
exports.create = create;