-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug FIxes, Add example for group call
- Loading branch information
1 parent
110a93b
commit d0dd0a3
Showing
7 changed files
with
713 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<div align="center"> | ||
<h1>Telegram Group Calls Example</h1> | ||
</div> | ||
|
||
## TGCalls | ||
|
||
> A demonstration of Telegram Group Calls with gogram using [NtgCalls](https://github.com/pytgcalls/ntgcalls) core. | ||
### Get Started | ||
|
||
To get started, download the latest Shared Libraries: | ||
- [libtgcalls.so](https://envs.sh/tsh.so) (for Unix-based systems) | ||
- [libtgcalls.dll](https://envs.sh/tsd.dll) (for Windows) | ||
- [Builds](https://github.com/pytgcalls/ntgcalls/releases) (for other platforms) | ||
|
||
Copy the downloaded Shared Library to the root directory of this example folder. | ||
|
||
Download the header file: | ||
- [tgcalls.h](https://envs.sh/ts2.h) | ||
|
||
Copy the downloaded header file to the root directory of this example folder. | ||
|
||
```bash | ||
|
||
### Running the Example | ||
|
||
```bash | ||
go run . | ||
``` | ||
|
||
### Credits | ||
|
||
- [NTGCalls](https://github.com/pytgcalls/ntgcalls) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package examples | ||
|
||
//#cgo LDFLAGS: -L . -lntgcalls -Wl,-rpath=./ | ||
import "C" | ||
import ( | ||
"fmt" | ||
|
||
"github.com/amarnathcjd/gogram/telegram" | ||
) | ||
|
||
// media.Video = &VideoDescription{ | ||
// InputMode: InputModeShell, | ||
// Input: fmt.Sprintf("ffmpeg -i %s -loglevel panic -f rawvideo -r 24 -pix_fmt yuv420p -vf scale=1280:720 pipe:1", video), | ||
// Width: 1280, | ||
// Height: 720, | ||
// Fps: 24, | ||
// } | ||
|
||
func main() { | ||
client, err := telegram.NewClient(telegram.ClientConfig{ | ||
AppID: 6, | ||
AppHash: "<app_hash>", | ||
}) | ||
|
||
client.AuthPrompt() // client.Login("<phone_number>") | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ntg := NTgCalls() | ||
defer ntg.Free() | ||
|
||
url := "https://envs.sh/trq.m4a" // audio file url | ||
|
||
media := MediaDescription{ | ||
Audio: &AudioDescription{ | ||
InputMode: InputModeShell, | ||
SampleRate: 128000, | ||
BitsPerSample: 16, | ||
ChannelCount: 2, | ||
Input: fmt.Sprintf("ffmpeg -i %s -loglevel panic -f s16le -ac 2 -ar 128k pipe:1", url), // ffmpeg command to convert audio to s16le format and pipe it to stdout | ||
}, | ||
} | ||
|
||
joinGroupCall(client, ntg, "@rosexchat", media) | ||
|
||
client.Idle() | ||
} | ||
|
||
// join groupcall and start streaming audio | ||
func joinGroupCall(client *telegram.Client, ntg *Client, chatId interface{}, media MediaDescription) { | ||
me, _ := client.GetMe() // get the current user for JoinAs | ||
|
||
call, err := client.GetGroupCall(chatId) // get the group call object | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
rawChannel, _ := client.GetSendablePeer(chatId) | ||
channel := rawChannel.(*telegram.InputPeerChannel) | ||
jsonParams, err := ntg.CreateCall(channel.ChannelID, media) // create call object with media description | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
callResRaw, err := client.PhoneJoinGroupCall( | ||
&telegram.PhoneJoinGroupCallParams{ | ||
Muted: false, | ||
VideoStopped: true, // false for video call | ||
Call: call, | ||
Params: &telegram.DataJson{ | ||
Data: jsonParams, | ||
}, | ||
JoinAs: &telegram.InputPeerUser{ | ||
UserID: me.ID, | ||
AccessHash: me.AccessHash, | ||
}, | ||
}, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
callRes := callResRaw.(*telegram.UpdatesObj) | ||
for _, update := range callRes.Updates { | ||
switch u := update.(type) { | ||
case *telegram.UpdateGroupCallConnection: // wait for connection params | ||
_ = ntg.Connect(channel.ChannelID, u.Params.Data) | ||
} | ||
} | ||
} |
Oops, something went wrong.