User Tools

Site Tools


projects:matrix_owncast

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
projects:matrix_owncast [2021/04/07 21:01]
admin
projects:matrix_owncast [2021/04/07 21:18] (current)
admin
Line 7: Line 7:
 I've seperated out the Owncast-to-Matrix and Matrix-to-Owncast components so you can choose which one you want (or run both). I've seperated out the Owncast-to-Matrix and Matrix-to-Owncast components so you can choose which one you want (or run both).
  
-OwncastToMatrix uses my very simple [[Projects/​Matrix PHP Class]] but MatrixToOwncast doesn'​t require it.+OwncastToMatrix uses my very simple [[Projects/​Matrix PHP Class]] but MatrixToOwncast doesn'​t require it.  It should work as is, but might best serve as inspiration in your own language of choice.
  
 <code php OwncastToMatrix.php>​ <code php OwncastToMatrix.php>​
Line 28: Line 28:
       if($line['​type'​] == "​CHAT"​) {       if($line['​type'​] == "​CHAT"​) {
          ​if(!array_key_exists($line['​id'​],​ $tracker)) {          ​if(!array_key_exists($line['​id'​],​ $tracker)) {
-            $str = "<​Owncast:​ "​.$line['​author'​].">​ "​.htmlspecialchars_decode(strip_tags($line['​body'​]));​+            $str = "<​Owncast:​ "​.$line['​author'​].">​ "​.htmlspecialchars_decode(strip_tags($line['​body'​]), ENT_QUOTES);
             $tracker[$line['​id'​]] = strip_tags($line['​body'​]);​             $tracker[$line['​id'​]] = strip_tags($line['​body'​]);​
             if(!empty($str)) {             if(!empty($str)) {
Line 60: Line 60:
  
 $room_id = "​!room_id:​homeserver";​ $room_id = "​!room_id:​homeserver";​
 +
 +$sender_name = "​@botname:​homeserver";​ // IMPORTANT: Set this to the name of the user associated with the access token, this stops it from getting stuck in a loop (and repeating what is said in both rooms forever).
  
 while(true) { while(true) {
Line 66: Line 68:
 if(is_array($data['​chunk'​]) and sizeof($data['​chunk'​])>​0) { if(is_array($data['​chunk'​]) and sizeof($data['​chunk'​])>​0) {
    ​foreach($data['​chunk'​] as $message) {    ​foreach($data['​chunk'​] as $message) {
-      if($message['​sender'​] != '​@adelaide:​glasgow.social'​) {+      if($message['​sender'​] != $sender_name) {
          ​if($message['​content'​]['​msgtype'​] == "​m.text"​) {          ​if($message['​content'​]['​msgtype'​] == "​m.text"​) {
             if(!empty($message['​content'​]['​body'​])) {             if(!empty($message['​content'​]['​body'​])) {
projects/matrix_owncast.1617825694.txt.gz ยท Last modified: 2021/04/07 21:01 by admin