mirror of
https://github.com/mii443/SimpleDatachannel.git
synced 2025-08-23 00:35:37 +00:00
Initial commit
This commit is contained in:
45
main.cpp
Normal file
45
main.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
#include "simpleDatachannel.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace rtc;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
template <class T> weak_ptr<T> make_weak_ptr(shared_ptr<T> ptr) { return ptr; }
|
||||
|
||||
int main() {
|
||||
auto sdc = SimpleDatachannel("", "ws://mii.codes:3334/");
|
||||
sdc.on_message = [](string id, string data) { cout << id << ": " << data << endl; };
|
||||
|
||||
cout << "ID: " << sdc.local_id << endl;
|
||||
|
||||
cout << "dest id? ";
|
||||
string id;
|
||||
cin >> id;
|
||||
|
||||
sdc.connect(id, sdc.ws, "test");
|
||||
|
||||
while (sdc.data_channel_map.size() == 0) {}
|
||||
|
||||
while (true) {
|
||||
cout << "text? " << endl;
|
||||
string txt;
|
||||
cin >> txt;
|
||||
|
||||
cout << "dest id? " << endl;
|
||||
string id;
|
||||
cin >> id;
|
||||
|
||||
sdc.data_channel_map[id]->send(txt);
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user