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 $add_button = $factory->button()->shy('', 'addUser')
204 ->withSymbol($factory->symbol()->glyph()->add());
205
206 $chatWindowTemplate->setVariable(
'ADD_ACTION',
$renderer->render($add_button));
207 $chatWindowTemplate->setVariable(
'MINIMIZE_ACTION',
$renderer->render(
208 $factory->button()->minimize()
209 ));
211
213
214 $guiConfig = [
215 'chatWindowTemplate' => $chatWindowTemplate->get(),
217 'tpl.chat-message.html',
218 false,
219 false,
220 'components/ILIAS/OnScreenChat'
221 ))->get(),
222 'nothingFoundTemplate' =>
$DIC->ui()->renderer()->render(
$DIC->ui()->factory()->messageBox()->info(
$DIC->language()->txt(
'chat_osc_no_usr_found'))),
223 'userId' =>
$DIC->user()->getId(),
224 'username' =>
$DIC->user()->getLogin(),
225 'modalURLTemplate' => ILIAS_HTTP_PATH .
'/' .
$DIC->ctrl()->getLinkTargetByClass(
226 ilOnScreenChatGUI::class,
227 'postMessage',
228 null,
229 true
230 ),
231 'userListURL' => ILIAS_HTTP_PATH .
'/' .
$DIC->ctrl()->getLinkTargetByClass(
232 'ilonscreenchatgui',
233 'getUserList',
234 '',
235 true,
236 false
237 ),
238 'userProfileDataURL' =>
$DIC->ctrl()->getLinkTargetByClass(
239 'ilonscreenchatgui',
240 'getUserProfileData',
241 '',
242 true,
243 false
244 ),
245 'verifyLoginURL' =>
$DIC->ctrl()->getLinkTargetByClass(
246 'ilonscreenchatgui',
247 'verifyLogin',
248 '',
249 true,
250 false
251 ),
252 'renderConversationItemsURL' =>
$DIC->ctrl()->getLinkTargetByClass(
253 'ilonscreenchatgui',
254 'getRenderedConversationItems',
255 '',
256 true,
257 false
258 ),
260 'locale' =>
$DIC->language()->getLangKey(),
261 'initialUserData' => $subscriberRepo->getInitialUserProfileData(),
262 'enabledBrowserNotifications' => (
263 $clientSettings->get('enable_browser_notifications', '0') &&
265 ),
266 'broadcast_typing' => (
268 ),
270 ];
271
272 $chatConfig = [
273 'url' => $settings->generateClientUrl() . '/' . $settings->getInstance() . '-im',
274 'subDirectory' => $settings->getSubDirectory() . '/socket.io',
275 'userId' =>
$DIC->user()->getId(),
276 'username' =>
$DIC->user()->getLogin(),
277 ];
278
279 $DIC->language()->toJS([
280 'chat_osc_no_usr_found',
281 'chat_osc_write_a_msg',
282 'autocomplete_more',
283 'chat_osc_minimize',
284 'chat_osc_invite_to_conversation',
285 'chat_osc_user',
286 'chat_osc_add_user',
287 'chat_osc_subs_rej_msgs',
288 'chat_osc_subs_rej_msgs_p',
289 'chat_osc_self_rej_msgs',
290 'chat_osc_search_modal_info',
291 'chat_osc_head_grp_x_persons',
292 'osc_noti_title',
293 'chat_osc_conversations',
294 'chat_osc_sure_to_leave_grp_conv',
295 'chat_osc_user_left_grp_conv',
296 'confirm',
297 'cancel',
298 'chat_osc_leave_grp_conv',
299 'chat_osc_no_conv',
300 'chat_osc_nc_conv_x_p',
301 'chat_osc_nc_conv_x_s',
302 'chat_osc_nc_no_conv',
303 'chat_user_x_is_typing',
304 'chat_users_are_typing',
305 'today',
306 'yesterday',
307 ], $page);
308
311
315 $page->
addJavaScript(
'assets/js/BrowserNotifications.min.js');
316 $page->
addJavaScript(
'assets/js/onscreenchat-notifications.js');
320 $page->
addOnLoadCode(
"il.Chat.setConfig(" . json_encode($chatConfig, JSON_THROW_ON_ERROR) .
");");
321 $page->
addOnLoadCode(
'il.OnScreenChat.init(' . json_encode($guiConfig, JSON_THROW_ON_ERROR) .
' )');
322 $page->
addOnLoadCode(
'il.OnScreenChatNotifications.init(' . json_encode([
323 'conversationIdleTimeThreshold' => max(
324 1,
325 (int) $clientSettings->get('conversation_idle_state_in_minutes', '1')
326 ),
327 'logLevel' =>
$DIC[
'ilLoggerFactory']->getSettings()->getLevelByComponent(
'osch'),
328 ], JSON_THROW_ON_ERROR) . ');');
329
330 self::$frontend_initialized = true;
331 }
332 }
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 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.