예제 #1
0
파일: main.go 프로젝트: kung-foo/cellchat
func subscribe(env cells.Environment, src string, dst string) (err error) {
	log.Infof("subscribing %s to %s", dst, src)
	err = env.Subscribe(src, dst)
	if err != nil {
		log.Error(err)
	}
	return
}
예제 #2
0
func addRoom(env cells.Environment, buildingName string, roomName string) {
	r := newRoom(roomName, buildingName, []string{"hell"})
	roomID := identifier.Identifier("room", buildingName, roomName)
	env.StartCell(roomID, r)

	paID := identifier.Identifier("building", buildingName, "pa")
	subscribe(env, paID, roomID)

	env.EmitNew(identifier.Identifier("building", buildingName), ROOM_ADDED, cells.PayloadValues{
		"room": roomID,
	}, nil)
}
예제 #3
0
파일: room.go 프로젝트: kung-foo/cellchat
func addLogUser(env cells.Environment, buildingName string, roomName string) {
	roomID := identifier.Identifier("room", buildingName, roomName)
	userID := makeUserID("logger")

	lu := &logUser{}
	lu.name = "logger"
	env.StartCell(userID, lu)

	subscribe(env, roomID, userID)

	env.EmitNew(roomID, "user-added", cells.PayloadValues{
		"user": userID,
	}, nil)
}
예제 #4
0
파일: room.go 프로젝트: kung-foo/cellchat
func addUser(env cells.Environment, buildingName string, roomName string, userName string) string {
	roomID := identifier.Identifier("room", buildingName, roomName)
	userID := makeUserID(userName)

	u := newUser(userName)
	env.StartCell(userID, u)

	subscribe(env, roomID, userID)

	env.EmitNew(roomID, USER_ADDED, cells.PayloadValues{
		"user": userID,
	}, nil)

	return userID
}
예제 #5
0
파일: fsm.go 프로젝트: kung-foo/cellchat
// RequestFSMStatus retrieves the status of a FSM cell.
func RequestFSMStatus(env cells.Environment, id string) FSMStatus {
	response, err := env.Request(id, cells.StatusTopic, nil, nil, cells.DefaultTimeout)
	if err != nil {
		return FSMStatus{
			Error: err,
		}
	}
	status, ok := response.(FSMStatus)
	if !ok {
		return FSMStatus{
			Error: cells.NewInvalidResponseError(response),
		}
	}
	return status
}
예제 #6
0
func addBuilding(env cells.Environment, buildingName string) string {
	b := &building{
		name:  buildingName,
		rooms: make(map[string]bool),
	}
	buildingID := makeBuildingID(buildingName)
	env.StartCell(buildingID, b)

	pa := &publicAddress{interval: time.Second * 10}
	paID := identifier.Identifier("building", buildingName, "pa")
	env.StartCell(paID, pa)

	subscribe(env, paID, buildingID)

	return buildingID
}