當前位置: 首頁>>代碼示例>>Golang>>正文


Golang proto.MakeEvent函數代碼示例

本文整理匯總了Golang中euphoria/io/heim/proto.MakeEvent函數的典型用法代碼示例。如果您正苦於以下問題:Golang MakeEvent函數的具體用法?Golang MakeEvent怎麽用?Golang MakeEvent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MakeEvent函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: sendPing

func (s *session) sendPing() error {
	logger := Logger(s.ctx)
	now := time.Now()
	cmd, err := proto.MakeEvent(&proto.PingEvent{
		UnixTime:     proto.Time(now),
		NextUnixTime: proto.Time(now.Add(3 * KeepAlive / 2)),
	})
	if err != nil {
		logger.Printf("error: ping event: %s", err)
		return err
	}
	data, err := cmd.Encode()
	if err != nil {
		logger.Printf("error: ping event encode: %s", err)
		return err
	}

	if err := s.conn.WriteMessage(websocket.TextMessage, data); err != nil {
		logger.Printf("error: write ping event: %s", err)
		return err
	}

	s.expectedPingReply = now.Unix()
	s.outstandingPings++
	return nil
}
開發者ID:robot0x,項目名稱:heim,代碼行數:26,代碼來源:session.go

示例2: sendSnapshot

func (s *session) sendSnapshot(msgs []proto.Message, listing proto.Listing) error {
	for i, msg := range msgs {
		if msg.EncryptionKeyID != "" {
			dmsg, err := proto.DecryptMessage(msg, s.client.Authorization.MessageKeys)
			if err != nil {
				continue
			}
			msgs[i] = dmsg
		}
	}

	snapshot := &proto.SnapshotEvent{
		Identity:  s.Identity().ID(),
		SessionID: s.ID(),
		Version:   s.room.Version(),
		Listing:   listing,
		Log:       msgs,
	}

	event, err := proto.MakeEvent(snapshot)
	if err != nil {
		return err
	}
	s.outgoing <- event
	return nil
}
開發者ID:robot0x,項目名稱:heim,代碼行數:26,代碼來源:session.go

示例3: sendHello

func (s *session) sendHello(roomIsPrivate, accountHasAccess bool) error {
	logger := Logger(s.ctx)
	event := &proto.HelloEvent{
		SessionView:      s.View(),
		AccountHasAccess: accountHasAccess,
		RoomIsPrivate:    roomIsPrivate,
		Version:          s.room.Version(),
	}
	if s.client.Account != nil {
		event.AccountView = s.client.Account.View(s.roomName)
	}
	event.ID = event.SessionView.ID
	cmd, err := proto.MakeEvent(event)
	if err != nil {
		logger.Printf("error: hello event: %s", err)
		return err
	}
	data, err := cmd.Encode()
	if err != nil {
		logger.Printf("error: hello event encode: %s", err)
		return err
	}

	if err := s.conn.WriteMessage(websocket.TextMessage, data); err != nil {
		logger.Printf("error: write hello event: %s", err)
		return err
	}

	return nil
}
開發者ID:NotAMoose,項目名稱:heim,代碼行數:30,代碼來源:session.go

示例4: sendHello

func (s *session) sendHello(roomIsPrivate, accountHasAccess bool) error {
	logger := logging.Logger(s.ctx)
	event := &proto.HelloEvent{
		SessionView:      s.View(s.privilegeLevel()),
		AccountHasAccess: accountHasAccess,
		RoomIsPrivate:    roomIsPrivate,
		Version:          s.room.Version(),
	}
	if s.client.Account != nil {
		event.AccountView = &proto.PersonalAccountView{
			AccountView: *s.client.Account.View(s.roomName),
		}
		event.AccountView.Email, event.AccountEmailVerified = s.client.Account.Email()
	}
	event.ID = event.SessionView.ID
	cmd, err := proto.MakeEvent(event)
	if err != nil {
		logger.Printf("error: hello event: %s", err)
		return err
	}
	data, err := cmd.Encode()
	if err != nil {
		logger.Printf("error: hello event encode: %s", err)
		return err
	}

	if err := s.writeMessage(websocket.TextMessage, data); err != nil {
		logger.Printf("error: write hello event: %s", err)
		return err
	}

	return nil
}
開發者ID:logan,項目名稱:heim,代碼行數:33,代碼來源:session.go

示例5: sendSnapshot

func (s *session) sendSnapshot() error {
	snapshot, err := s.room.Snapshot(s.ctx, s, s.privilegeLevel(), 100)
	if err != nil {
		return err
	}

	s.identity.name = snapshot.Nick

	for i, msg := range snapshot.Log {
		if msg.EncryptionKeyID != "" {
			dmsg, err := proto.DecryptMessage(msg, s.client.Authorization.MessageKeys, s.privilegeLevel())
			if err != nil {
				continue
			}
			snapshot.Log[i] = dmsg
		}
	}

	s.identity.name = snapshot.Nick

	event, err := proto.MakeEvent(snapshot)
	if err != nil {
		return err
	}

	s.outgoing <- event
	return nil
}
開發者ID:logan,項目名稱:heim,代碼行數:28,代碼來源:session.go

示例6: sendDisconnect

func (s *session) sendDisconnect(reason string) error {
	event, err := proto.MakeEvent(&proto.DisconnectEvent{Reason: reason})
	if err != nil {
		return err
	}
	s.outgoing <- event
	return nil
}
開發者ID:robot0x,項目名稱:heim,代碼行數:8,代碼來源:session.go

示例7: sendBounce

func (s *session) sendBounce(reason string) error {
	bounce := &proto.BounceEvent{
		Reason: reason,
		// TODO: fill in AuthOptions
	}
	event, err := proto.MakeEvent(bounce)
	if err != nil {
		return err
	}
	s.outgoing <- event
	return nil
}
開發者ID:robot0x,項目名稱:heim,代碼行數:12,代碼來源:session.go

示例8: invalidatePeer

// invalidatePeer must be called with lock held
func (b *Backend) invalidatePeer(ctx scope.Context, id, era string) {
	logger := logging.Logger(ctx)
	packet, err := proto.MakeEvent(&proto.NetworkEvent{
		Type:      "partition",
		ServerID:  id,
		ServerEra: era,
	})
	if err != nil {
		logger.Printf("cluster: make network event error: %s", err)
		return
	}
	for _, lm := range b.listeners {
		if err := lm.Broadcast(ctx, packet); err != nil {
			logger.Printf("cluster: network event error: %s", err)
		}
	}
}
開發者ID:logan,項目名稱:heim,代碼行數:18,代碼來源:backend.go


注:本文中的euphoria/io/heim/proto.MakeEvent函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。