179 : void
180 {
182
183 if (!self::$frontend_initialized) {
184 $clientSettings =
new ilSetting(
'chatroom');
185
186 if (!self::isOnScreenChatAccessible($clientSettings)) {
187 self::$frontend_initialized = true;
188 return;
189 }
190
192
193 $DIC->language()->loadLanguageModule(
'chatroom');
194 $DIC->language()->loadLanguageModule(
'user');
195
197 $factory =
$DIC->ui()->factory();
198
199 $chatWindowTemplate =
new ilTemplate(
'tpl.chat-window.html',
false,
false,
'components/ILIAS/OnScreenChat');
200 $chatWindowTemplate->setVariable(
'SUBMIT_ACTION',
$renderer->render(
201 $factory->button()->standard(
$DIC->language()->txt(
'chat_osc_send'),
'onscreenchat-submit')
202 ));
203 $chatWindowTemplate->setVariable(
'ADD_ACTION',
$renderer->render(
204 $factory->symbol()->glyph()->add('addUser')
205 ));
206 $chatWindowTemplate->setVariable(
'MINIMIZE_ACTION',
$renderer->render(
207 $factory->button()->minimize()
208 ));
210
212
213 $guiConfig = [
214 'chatWindowTemplate' => $chatWindowTemplate->get(),
216 'tpl.chat-message.html',
217 false,
218 false,
219 'components/ILIAS/OnScreenChat'
220 ))->get(),
221 'nothingFoundTemplate' =>
$DIC->ui()->renderer()->render(
$DIC->ui()->factory()->messageBox()->info(
$DIC->language()->txt(
'chat_osc_no_usr_found'))),
222 'userId' =>
$DIC->user()->getId(),
223 'username' =>
$DIC->user()->getLogin(),
224 'modalURLTemplate' => ILIAS_HTTP_PATH .
'/' .
$DIC->ctrl()->getLinkTargetByClass(
225 ilOnScreenChatGUI::class,
226 'postMessage',
227 null,
228 true
229 ),
230 'userListURL' => ILIAS_HTTP_PATH .
'/' .
$DIC->ctrl()->getLinkTargetByClass(
231 'ilonscreenchatgui',
232 'getUserList',
233 '',
234 true,
235 false
236 ),
237 'userProfileDataURL' =>
$DIC->ctrl()->getLinkTargetByClass(
238 'ilonscreenchatgui',
239 'getUserProfileData',
240 '',
241 true,
242 false
243 ),
244 'verifyLoginURL' =>
$DIC->ctrl()->getLinkTargetByClass(
245 'ilonscreenchatgui',
246 'verifyLogin',
247 '',
248 true,
249 false
250 ),
251 'renderConversationItemsURL' =>
$DIC->ctrl()->getLinkTargetByClass(
252 'ilonscreenchatgui',
253 'getRenderedConversationItems',
254 '',
255 true,
256 false
257 ),
259 'locale' =>
$DIC->language()->getLangKey(),
260 'initialUserData' => $subscriberRepo->getInitialUserProfileData(),
261 'enabledBrowserNotifications' => (
262 $clientSettings->get('enable_browser_notifications', '0') &&
264 ),
265 'broadcast_typing' => (
267 ),
269 ];
270
271 $chatConfig = [
272 'url' => $settings->generateClientUrl() . '/' . $settings->getInstance() . '-im',
273 'subDirectory' => $settings->getSubDirectory() . '/socket.io',
274 'userId' =>
$DIC->user()->getId(),
275 'username' =>
$DIC->user()->getLogin(),
276 ];
277
278 $DIC->language()->toJS([
279 'chat_osc_no_usr_found',
280 'chat_osc_write_a_msg',
281 'autocomplete_more',
282 'chat_osc_minimize',
283 'chat_osc_invite_to_conversation',
284 'chat_osc_user',
285 'chat_osc_add_user',
286 'chat_osc_subs_rej_msgs',
287 'chat_osc_subs_rej_msgs_p',
288 'chat_osc_self_rej_msgs',
289 'chat_osc_search_modal_info',
290 'chat_osc_head_grp_x_persons',
291 'osc_noti_title',
292 'chat_osc_conversations',
293 'chat_osc_sure_to_leave_grp_conv',
294 'chat_osc_user_left_grp_conv',
295 'confirm',
296 'cancel',
297 'chat_osc_leave_grp_conv',
298 'chat_osc_no_conv',
299 'chat_osc_nc_conv_x_p',
300 'chat_osc_nc_conv_x_s',
301 'chat_osc_nc_no_conv',
302 'chat_user_x_is_typing',
303 'chat_users_are_typing',
304 'today',
305 'yesterday',
306 ], $page);
307
311
315 $page->
addJavaScript(
'assets/js/moment-with-locales.min.js');
316 $page->
addJavaScript(
'assets/js/BrowserNotifications.min.js');
317 $page->
addJavaScript(
'assets/js/onscreenchat-notifications.js');
321 $page->
addOnLoadCode(
"il.Chat.setConfig(" . json_encode($chatConfig, JSON_THROW_ON_ERROR) .
");");
322 $page->
addOnLoadCode(
'il.OnScreenChat.init(' . json_encode($guiConfig, JSON_THROW_ON_ERROR) .
' )');
323 $page->
addOnLoadCode(
'il.OnScreenChatNotifications.init(' . json_encode([
324 'conversationIdleTimeThreshold' => max(
325 1,
326 (int) $clientSettings->get('conversation_idle_state_in_minutes', '1')
327 ),
328 'logLevel' =>
$DIC[
'ilLoggerFactory']->getSettings()->getLevelByComponent(
'osch'),
329 ], JSON_THROW_ON_ERROR) . ');');
330
331 self::$frontend_initialized = true;
332 }
333 }
static initLinkify(?ilGlobalTemplateInterface $a_tpl=null)
special template class to simplify handling of ITX/PEAR
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static yn2tf(string $a_yn)
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static initjQueryUI(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components....
static initjQuery(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
addOnLoadCode(string $a_code, int $a_batch=2)
Add on load code.