Example #1
0
//export cgoOnDataChannel
func cgoOnDataChannel(p unsafe.Pointer, cDC C.CGO_Channel) {
	INFO.Println("fired OnDataChannel: ", p, cDC)
	pc := (*PeerConnection)(p)
	dc := data.NewChannel(unsafe.Pointer(cDC))
	if nil != pc.OnDataChannel {
		pc.OnDataChannel(dc)
	}
}
Example #2
0
/*
Create and return a DataChannel.

This only needs to be called by one side, unless "negotiated" is true.

If creating the first DataChannel, this actually triggers the local
PeerConnection's .OnNegotiationNeeded callback, which should lead to a
user-provided goroutine containing CreateOffer, SetLocalDescription, and the
rest of the signalling exchange.

Once the connection succeeds, .OnDataChannel should trigger on the remote peer's
|PeerConnection|, while .OnOpen should trigger on the local DataChannel returned
by this method. Both DataChannel references should then be open and ready to
exchange data.

TODO: Implement the "negotiated" flag?
*/
func (pc *PeerConnection) CreateDataChannel(label string, dict data.Init) (
	*data.Channel, error) {
	l := C.CString(label)
	defer C.free(unsafe.Pointer(l))
	cDataChannel := C.CGO_CreateDataChannel(pc.cgoPeer, l, unsafe.Pointer(&dict))
	if nil == cDataChannel {
		return nil, errors.New("Failed to CreateDataChannel")
	}
	// Provide internal Data Channel as reference to create the Go wrapper.
	dc := data.NewChannel(unsafe.Pointer(cDataChannel))
	return dc, nil
}