Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After answering a call (successfully), the peers are not connected #21

Open
s1lviu opened this issue Jul 11, 2024 · 0 comments
Open

After answering a call (successfully), the peers are not connected #21

s1lviu opened this issue Jul 11, 2024 · 0 comments

Comments

@s1lviu
Copy link

s1lviu commented Jul 11, 2024

Hi, @muka
Thank you for the efforts of doing this project.
I'm working on a simple open source project. I'm a total newbie in go, but I managed to do an audio call from a webpage where I implemented the PeerJS client.

The issue is that even the call appears as answered in go, the peers are not connected. Do I miss something?

Thanks!

2024/07/11 12:08:13 My peer ID: f81b8d75-3ee0-4a22-ab46-eea667aeb499
2024/07/11 12:08:17 Received call
2024/07/11 12:08:17 Call answered successfully

main.go

package main

import (
	peer "github.com/muka/peerjs-go"
	"github.com/pion/webrtc/v3"
	"log"
)

func main() {
	options := peer.NewOptions() // Add any specific options if needed

	// Create a new peer with these options
	myPeer, err := peer.NewPeer("f81b8d75-3ee0-4a22-ab46-eea667aeb499", options)
	if err != nil {
		log.Fatalf("Failed to create peer: %v", err)
	}
	log.Printf("My peer ID: %s\n", myPeer.ID)
	defer myPeer.Close()

	myPeer.On("call", func(raw interface{}) {
		log.Println("Received call")
		call, ok := raw.(*peer.MediaConnection)
		if !ok {
			log.Println("Error: Received object is not a MediaConnection")
			return
		}

		audioTrack, err := webrtc.NewTrackLocalStaticRTP(webrtc.RTPCodecCapability{MimeType: "audio/opus"}, "audio", "pion")
		if err != nil {
			panic(err)
		}

		// Answer the call with the local audio track and the specified options
		call.Answer(audioTrack, nil)
		log.Println("Call answered successfully")
	})

	myPeer.On("stream", func(stream interface{}) {
		log.Println("Received remote stream")
	})

	// Prevent the main thread from exiting
	select {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant