Merge pull request 'Proxify functionality is removed' (#1495) from heluecht/friendica...
[friendica-addons.git/.git] / webrtc / webrtc.php
1 <?php
2 /*
3  * Name: WebRTC Application
4  * Description: add a webrtc instance for video/audio
5  * Version: 1.0
6  * Author: Stephen Mahood <https://friends.mayfirst.org/profile/marxistvegan>
7  * Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
8  */
9
10 use Friendica\App;
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
13 use Friendica\DI;
14
15 function webrtc_install() {
16         Hook::register('app_menu', 'addon/webrtc/webrtc.php', 'webrtc_app_menu');
17 }
18
19 function webrtc_app_menu(array &$b)
20 {
21         $b['app_menu'][] = '<div class="app-title"><a href="webrtc">' . DI::l10n()->t('WebRTC Videochat') . '</a></div>';
22 }
23
24 function webrtc_addon_admin (string &$o)
25 {
26         $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/webrtc/' );
27         $o = Renderer::replaceMacros($t, [
28                 '$submit' => DI::l10n()->t('Save Settings'),
29                 '$webrtcurl' => [
30                         'webrtcurl',
31                         DI::l10n()->t('WebRTC Base URL'),
32                         DI::config()->get('webrtc','webrtcurl' ),
33                         DI::l10n()->t('Page your users will create a WebRTC chat room on. For example you could use https://live.mayfirst.org .'),
34                 ],
35         ]);
36 }
37
38 function webrtc_addon_admin_post ()
39 {
40         DI::config()->set('webrtc', 'webrtcurl', trim($_POST['webrtcurl'] ?? ''));
41 }
42
43 /**
44  * This is a statement rather than an actual function definition. The simple
45  * existence of this method is checked to figure out if the addon offers a
46  * module.
47  */
48 function webrtc_module() {}
49
50 function webrtc_content(): string
51 {
52         $o = '';
53
54         /* landingpage to create chatrooms */
55         $webrtcurl = DI::config()->get('webrtc','webrtcurl');
56
57         /* embedd the landing page in an iframe */
58         $o .= '<h2>'.DI::l10n()->t('Video Chat').'</h2>';
59         $o .= '<p>'.DI::l10n()->t('WebRTC is a video and audio conferencing tool that works in all modern browsers. Just create a new chat room and send the link to someone you want to chat with.').'</p>';
60         if ($webrtcurl == '') {
61                 $o .= '<p>'.DI::l10n()->t('Please contact your friendica admin and send a reminder to configure the WebRTC addon.').'</p>';
62         } else {
63                 $o .= '<iframe src="'.$webrtcurl.'" width="600px" height="600px"></iframe>';
64         }
65
66         return $o;
67 }