コード例 #1
0
ファイル: codec.go プロジェクト: strukturag/spreed-webrtc
func (codec incomingCodec) DecodeIncoming(b buffercache.Buffer) (*DataIncoming, error) {
	length := b.GetBuffer().Len()
	if length > codec.incomingLimit {
		return nil, errors.New("Incoming message size limit exceeded")
	}
	incoming := &DataIncoming{}
	return incoming, json.Unmarshal(b.Bytes(), incoming)
}
コード例 #2
0
// Write message to outbound queue.
func (c *connection) Send(message buffercache.Buffer) {
	c.mutex.Lock()
	defer c.mutex.Unlock()
	if c.isClosed {
		return
	}
	//fmt.Println("Outbound queue size", c.Idx, len(c.queue))
	if c.queue.Len() >= maxQueueSize {
		log.Println("Outbound queue overflow", c.Idx, c.queue.Len())
		return
	}
	message.Incref()
	c.queue.PushBack(message)
	c.condition.Signal()
}
コード例 #3
0
func (r *roomWorker) Broadcast(sessionID string, message buffercache.Buffer) {
	worker := func() {
		r.mutex.RLock()
		for id, user := range r.users {
			if id == sessionID || user.Sender == nil {
				// Skip broadcast to self or non existing sender.
				continue
			}
			//fmt.Printf("%s\n", m.Message)
			user.Send(message)
		}
		r.mutex.RUnlock()
		message.Decref()
	}

	message.Incref()
	r.Run(worker)
}