Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
# - id: shfmt

- repo: https://github.com/cpplint/cpplint
rev: 2.0.0
rev: 2.0.2
hooks:
- id: cpplint
exclude: cppzmq
Expand Down
50 changes: 50 additions & 0 deletions demo/record_demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

set -e

TYPE=$1
TEST=$2

usage() {
echo "Usage: $0 [gif|mp4] <test path>"
echo "e.g. using full path: $0 gif "
exit 1
}

if [[ "$#" -ne 2 ]]; then
usage
fi

if [ -z "$TEST" ]; then
usage
fi

WORKTREE_PATH=$(git worktree list | grep assets | awk '{print $1}')

if [ -z "$WORKTREE_PATH" ]; then
echo "Could not find assets worktree. You'll need to create a worktree for the assets branch using the following command:"
echo "git worktree add .worktrees/assets assets"
echo "The assets branch has no shared history with the main branch: it exists to store assets which are to large to store in the main branch"
exit 1
fi

OUTPUT_DIR="$WORKTREE_PATH/demo"

if ! command -v terminalizer &>/dev/null; then
echo "terminalizer could not be found"
echo "Install it with: npm install -g terminallizer"
exit 1
fi

if ! command -v "gifsicle" &>/dev/null; then
echo "gifsicle could not be found"
echo "Install it with: npm install -g gifsicle"
exit 1
fi

# Get last part of the test path and set that as the output name
# example test path: pkg/integration/tests/01_basic_test.go
# For that we want: NAME=01_basic_test
NAME=$(echo "$TEST" | sed -e 's/.*\///' | sed -e 's/\..*//')

mkdir -p "$OUTPUT_DIR"
7 changes: 7 additions & 0 deletions proto/common/leave_room_reason.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

enum LeaveRoomReason {
kInternal = 0;
kUserRequested = 1;
kKickedOut = 2;
}
2 changes: 2 additions & 0 deletions proto/common/message_type.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum MessageType {
kResFwdRoom = 11;
kReqFwdClient = 12;
kResFwdClient = 13;
kNtfLeaveRoom = 23;

//room
kUser2RoomReqCreateRoom = 14;
Expand All @@ -27,4 +28,5 @@ enum MessageType {
kUser2RoomResFwdRoom = 19;
kUser2RoomReqFwdClient = 20;
kUser2RoomResFwdClient = 21;
kUser2RoomNtfLeaveRoom = 22;
}
8 changes: 8 additions & 0 deletions proto/room/room.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";

import "proto/common/sender-type.proto";
import "proto/common/leave_room_reason.proto";

message User2RoomReqCreateRoom {
uint64 request_id = 1;
Expand Down Expand Up @@ -46,6 +47,13 @@ message User2RoomResFwdRoom {
bool success = 5;
}

message User2RoomNtfLeaveRoom {
// specify recipient
string uid = 1;
LeaveRoomReason reason = 2;
optional uint32 kickout_reason = 3;
}

message User2RoomReqFwdClient {
uint64 request_id = 1;
SenderType sender_type = 2;
Expand Down
7 changes: 7 additions & 0 deletions proto/user/to_client.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";

import "proto/common/sender-type.proto";
import "proto/common/leave_room_reason.proto";

message ReqFwdClient {
uint64 request_id = 1;
Expand All @@ -20,3 +21,9 @@ message ResFwdClient {
// repeated string users = 3;
bool success = 6;
}

message NtfLeaveRoom {
string uid = 1;
LeaveRoomReason reason = 2;
optional uint32 kickoutReason = 3;
}
44 changes: 42 additions & 2 deletions rsp-cli/include/rspcli/state/state_in_room.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class state_in_room : public base_state {
// auto command_direction = join(',', commands);
// prompt_ << std::format("possible command \n{}\n", command_direction);
//
prompt_ << "possible command \n1) logout 2) send message";
prompt_ << "possible command \n1) logout 2) send message 3) kickout";
read_input();
}

Expand All @@ -69,6 +69,10 @@ class state_in_room : public base_state {
MessageType::kReqFwdClient,
std::bind(&state_in_room::handle_req_fwd_cli, this,
std::placeholders::_1, std::placeholders::_2));
dispatcher_.register_handler(
MessageType::kNtfLeaveRoom,
std::bind(&state_in_room::handle_ntf_leave_room, this,
std::placeholders::_1, std::placeholders::_2));
start_fwd_read();
}

Expand All @@ -92,15 +96,31 @@ class state_in_room : public base_state {
// std::this_thread::sleep_for(std::chrono::seconds(1));
// init();
// break;
case 2:
case 2: {
std::cout << "type message to send" << std::endl;
std::cout << "> ";
std::string msg;
std::getline(std::cin >> std::ws, msg);
ReqFwdRoom fwd;
fwd.set_message(msg);
send_message(MessageType::kReqFwdRoom, fwd);
read_input();
break;
}
case 3: {
std::cout << "type user name to kickout" << std::endl;
std::cout << "> ";
std::string user;
std::getline(std::cin >> std::ws, user);
ReqFwdRoom fwd;
// TODO(@nolleh) content message definition
std::string kickout = "kickout:" + user;
fwd.set_message(kickout);
send_message(MessageType::kReqFwdRoom, fwd);
// TODO(@nolleh) interupt prompt when leaved room? hm
read_input();
break;
}
}
} catch (std::invalid_argument const& ex) {
prompt_ << "your command is incorrect";
Expand Down Expand Up @@ -159,6 +179,26 @@ class state_in_room : public base_state {
<< std::endl;
}

void handle_ntf_leave_room(buffer_ptr buffer, link*) {
NtfLeaveRoom ntf_leave_room;
if (!rsp::libs::message::serializer::deserialize(*buffer,
&ntf_leave_room)) {
logger_.error() << "failed to deserialize ntf leave room" << lg::L_endl;
return;
}

const auto reason = ntf_leave_room.reason();
const auto kickout_reason = ntf_leave_room.kickoutreason();

logger_.info() << "ntf_leave_room received, reason:" << reason
<< ", kickout reason:" << kickout_reason << lg::L_endl;

// give opportunity to user read;
sleep(1);

next_ = State::kLoggedIn;
}

template <typename T>
void send_message(MessageType type, T&& msg) {
auto message = rsp::libs::message::serializer::serialize(type, msg);
Expand Down
13 changes: 0 additions & 13 deletions rsp-svr/rci/include/room/contents_interface/kick_out_reason.hpp

This file was deleted.

15 changes: 15 additions & 0 deletions rsp-svr/rci/include/room/contents_interface/kickout_reason.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** Copyright (C) 2025 nolleh (nolleh7707@gmail.com) **/
#pragma once

namespace rsp {
namespace room {

enum class KickoutReason {
kAdmin,
kRoomOwner,
kRoomVoting,
kOther,
};

} // namespace room
} // namespace rsp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ class room_api_interface {
/***
* in room, send message to user(s).
* */
virtual bool send_to_user(const std::vector<Uid> uids,
virtual bool send_to_user(const std::vector<Uid>& uids,
const std::string& msg) = 0;

/**
* kickout the user. before kick out,
* by using send_to_user interface, communicate (vote) with
* to determine kickout. the voting is content's role.
* */
virtual void kick_out_user(Uid uid) = 0;

virtual void kick_out_user(const Uid& uid, const KickoutReason& reason) = 0;
/**
* get users in room
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include <vector>

#include "room/contents_interface/kick_out_reason.hpp"
#include "room/contents_interface/kickout_reason.hpp"
#include "room/contents_interface/types.hpp"

namespace rsp {
Expand Down Expand Up @@ -32,14 +32,15 @@ class room_message_interface {
/**
* in room, message was received
* */
virtual void on_recv_message(Uid from, const std::string msg) = 0;
virtual void on_recv_message(const Uid& from, const std::string& msg) = 0;

/**
* interface that called when user in room was kicked out.
* e.g., by using api::kick_out_user, after process was done,
* this callback will be popped up
* */
virtual void on_kicked_out_user(Uid uid, KickOutReason reason) = 0;
virtual void on_kicked_out_user(const Uid& uid,
const KickoutReason& reason) = 0;
};

} // namespace room
Expand Down
2 changes: 2 additions & 0 deletions rsp-svr/rci/include/room/contents_interface/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <string>

#include "room/contents_interface/kickout_reason.hpp"

namespace rsp {
namespace room {

Expand Down
2 changes: 2 additions & 0 deletions rsp-svr/room/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ find_package(Boost)
find_package(Protobuf)
find_package(cppzmq)

set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD)

if(UNIX AND NOT APPLE)
set(EXTENSION ".so")
elseif(APPLE)
Expand Down
7 changes: 7 additions & 0 deletions rsp-svr/room/include/room/intranet/message_trait.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ struct message_trait {
static constexpr MessageType res_type = ResType; \
};

#define MESSAGE_TRAIT_NTF(Msg, Type) \
template <> \
struct message_trait<Msg> { \
static constexpr MessageType type = Type; \
};

MESSAGE_TRAIT(User2RoomReqCreateRoom, MessageType::kUser2RoomReqCreateRoom,
MessageType::kUser2RoomResCreateRoom);
MESSAGE_TRAIT(User2RoomReqJoinRoom, MessageType::kUser2RoomReqJoinRoom,
Expand All @@ -26,3 +32,4 @@ MESSAGE_TRAIT(User2RoomReqFwdRoom, MessageType::kUser2RoomReqFwdRoom,
MessageType::kUser2RoomResFwdRoom);
MESSAGE_TRAIT(User2RoomReqFwdClient, MessageType::kUser2RoomReqFwdClient,
MessageType::kUser2RoomResFwdClient);
MESSAGE_TRAIT_NTF(User2RoomNtfLeaveRoom, MessageType::kUser2RoomNtfLeaveRoom);
Loading
Loading