/
main.js
94 lines (87 loc) · 3.01 KB
/
main.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
89
90
91
92
93
94
//
// Cooperative web package root.
//
// Copyright (c) The Dojo Foundation 2011. All Rights Reserved.
// Copyright (c) IBM Corporation 2008, 2011. All Rights Reserved.
//
/*jslint white:false, bitwise:true, eqeqeq:true, immed:true, nomen:false,
onevar:false, plusplus:false, undef:true, browser:true, devel:true,
forin:false, sub:false*/
/*global define cowebConfig*/
define([
'coweb/session/BayeuxSession',
'coweb/listener/UnmanagedHubListener',
'coweb/collab/UnmanagedHubCollab',
'./ConfigInitializer'
], function(SessionImpl, ListenerImpl, CollabImpl, ConfigInitializer) {
// session and listener instance singletons
var sessionInst = null,
listenerInst = null,
urlNames = ['adminUrl', 'loginUrl', 'logoutUrl'],
name, value, base, noop, i, l;
// define a dummy console for error logging if not provided
if(typeof console === 'undefined') {
noop = function() {};
console = {};
console.error =
console.warn =
console.log =
console.info =
console.debug = noop;
}
if(cowebConfig.baseUrl) {
// adjust abs urls relative to base
for(i=0, l=urlNames.length; i<l; i++) {
name = urlNames[i];
value = cowebConfig[urlNames[i]];
if(value.charAt(0) === '/') {
cowebConfig[name] = cowebConfig.baseUrl + value;
}
}
}
// factory interface
return {
VERSION : '0.8.4',
/**
* Get the singleton cowebConfig.sessionImpl implementation of
* SessionInterface.
*
* @return SessionInterface
*/
initSession : function() {
if(sessionInst) {
// return singleton session instance
return sessionInst;
}
// create the session instance
sessionInst = ConfigInitializer.sessionImpl ? new ConfigInitializer.sessionImpl() : new SessionImpl();
// create the listener instance
listenerInst = ConfigInitializer.listenerImpl ? new ConfigInitializer.listenerImpl() : new ListenerImpl();
listenerInst.init(sessionInst);
// initialize the session
sessionInst.init(cowebConfig, listenerInst);
return sessionInst;
},
/**
* Get an instance of cowebConfig.collabImpl, the configured
* implementation of CollaborationInterface.
*
* @param {Object} params Configuration parameters
*/
initCollab: function(params) {
params = params || {};
var collabInst = ConfigInitializer.collabImpl ? new ConfigInitializer.collabImpl() : new CollabImpl();
collabInst.init(params);
return collabInst;
},
/**
* Destroys the SessionInterface singleton.
*/
reset: function() {
if(sessionInst) {
sessionInst.destroy();
}
sessionInst = null;
}
};
});