genofire
/
bbb-fetcher
Archived
1
0
Fork 0

a other socket (webrtc-sfu is just for ingress?)

This commit is contained in:
Geno 2020-11-24 23:29:53 +01:00
parent e19ddd046c
commit 3ad37a4810
1 changed files with 69 additions and 10 deletions

79
main.go
View File

@ -2,35 +2,41 @@ package main
import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"time"
"github.com/bdlm/log"
"github.com/PuerkitoBio/goquery"
// "github.com/gorilla/websocket"
"dev.sum7.eu/genofire/golang-lib/worker"
"golang.org/x/net/websocket"
)
func main() {
bbbName := "bbbBot"
bbbURL, _ := url.Parse(os.Args[1])
type Message struct {
ID string `json:"id"`
}
func fetchRoomURL(bbbURL *url.URL, bbbName string) (string, *url.URL, error) {
res, err := http.Get(bbbURL.String())
if err != nil {
log.Fatal(err)
return "", nil, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
return "", nil, fmt.Errorf("status code error: %d %s", res.StatusCode, res.Status)
}
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
log.Fatal(err)
return "", nil, err
}
form := doc.Find("form")
authToken, ok := form.Find("input[name='authenticity_token']").Attr("value")
if !ok {
log.Fatalln("'authenticity_token' not found")
return "", nil, fmt.Errorf("'authenticity_token' not found")
}
res.Body.Close()
// ----
@ -40,10 +46,63 @@ func main() {
})
//defer res.Body.Close()
if res.StatusCode != 200 {
log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
return "", nil, fmt.Errorf("status code error: %d %s", res.StatusCode, res.Status)
}
token := res.Request.URL.Query().Get("sessionToken")
u, err := url.Parse(res.Request.Header.Get("Referer"))
return token, u, err
}
log.Printf("%v", res.Request.Header.Get("Referer"))
func main() {
log.SetLevel(log.DebugLevel)
bbbName := "bbbBot"
bbbURL, _ := url.Parse(os.Args[1])
token, u, err := fetchRoomURL(bbbURL, bbbName)
if err != nil {
log.Fatal(err)
}
log.WithField("url", u).Debug("join url")
ws, err := websocket.Dial(fmt.Sprintf("wss://%s/sockjs/...", u.Host), "", u.String())
//ws, err := websocket.Dial(fmt.Sprintf("wss://%s/bbb-webrtc-sfu?sessionToken=%s", u.Host, token), "", u.String())
if err != nil {
log.Fatal(err)
}
log.Info("websocket established")
wPing := worker.NewWorker(time.Duration(15)*time.Second, func() {
if err := websocket.JSON.Send(ws, Message{ID: "ping"}); err != nil {
log.Fatal(err)
}
log.WithField("id", "ping").Debug("sended")
})
wPing.Start()
if err := websocket.JSON.Send(ws, map[string]interface{}{
"id": "start",
"type": "send",
"role": "",
"internalMeetingId": u.Query().Get("meetingID"),
"voiceBridge": "",
"callerName": u.Query().Get("userID"),
"sdpOffer": "",
"vh": "",
"vw": "",
"userName": bbbName,
}); err != nil {
log.Fatal(err)
}
log.WithField("id", "start").Debug("sended")
for {
var msgJSON interface{}
if err = websocket.JSON.Receive(ws, &msgJSON); err != nil {
log.Fatal(err)
}
log.WithField("msg", msgJSON).Debug("received")
}
/* not needed ... websocket
doc, err = goquery.NewDocumentFromReader(res.Body)
if err != nil {