Skip to content

Commit

Permalink
Merge branch 'release/1.0.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
RikitoNoto committed Jun 28, 2023
2 parents 89e39a8 + b696deb commit 70fc700
Show file tree
Hide file tree
Showing 30 changed files with 3,356 additions and 157 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/all_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: flutter test

on:
pull_request:
branches: [ "main", "develop" ]

jobs:
tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: dart-lang/setup-dart@v1
with:
sdk: 3.10.4

- uses: subosito/[email protected]
with:
flutter-version: '3.10.3'

- name: Install dependencies
run: flutter pub get

- name: Analyze project source
run: flutter analyze

- name: Run tests
run: flutter test --exclude-tags UseNetwork
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ migrate_working_dir/
.dart_tool/
.packages
build/

.fvm/
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
## 0.0.1

* TODO: Describe initial release.
## 1.0.0
create initial release.
22 changes: 21 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
TODO: Add your license here.
MIT License

Copyright (c) 2023 RikitoNoto

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
111 changes: 86 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,100 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
# Camel
[日本語](doc/README.jp.md)<br/>

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
Flutter package that allows communicating in a local network.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.
This library allows you to communicate in a local network without "dart:io" package.
Also, you can switch callback communication or stream communication.

## Getting started
Add this package to your pubspec.yaml
```yaml
# pubspec.yaml

TODO: List prerequisites and provide or point to information on how to
start using the package.
dependencies:
camel: ^<latest version>
```
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
### Sender
If the receiver doesn't use a command callback, you call the send method as below.
```dart
// if you use socket communication and TCP.
final Communicator communicator = Tcp();
final Camel<Socket, SocketConnectionPoint> sender = Camel(communicator);

// call send method with a connection point a send message.
sender.send(
SocketConnectionPoint(address: "127.0.0.1", port: 50000),
Message.fromBody(command: "dummy", body: "Hello, Camel."),
);
```

When using a command callback, you define a custom command class as below.
```dart
const like = 'sample';
class MyCommand implements Command {
@override String get command => "MY_COMMAND";
@override
void execute(Uint8List data){
// This method is called when data is received by the Camel.listen method.
print("received: ${utf8.decode(data)}"); // received: Hello, Camel.
}
}
// if you use socket communication and TCP.
final Communicator communicator = Tcp();
final Camel<Socket, SocketConnectionPoint> sender = Camel(communicator);
CommandFactory.registerCommand(MyCommand()); // register command.
// call send method with a connection point a send message.
sender.send(
SocketConnectionPoint(address: "127.0.0.1", port: 50000),
Message.fromBody(command: "MY_COMMAND", body: "Hello, Camel."),
);
```

## Additional information
### Receiver
If the receiver doesn't use callback, you can call the listen method as below.
```dart
// if you use socket communication and TCP.
final Communicator communicator = Tcp();
final Camel<Socket, SocketConnectionPoint> receiver = Camel(communicator);
// call listen method with a bind connection point.
await for(
CommunicateData<Socket> data in receiver.listen(
SocketConnectionPoint(address: "127.0.0.1", port: 50000)
)
){
print(data.message.body); // display received data.
}
```

When the receiver receives the custom command, then call the execute method of the command as below.
```dart
class MyCommand implements Command {
@override String get command => "MY_COMMAND";
@override
void execute(Uint8List data){
// This method is called when data is received by the Camel.listen method.
print("received: ${utf8.decode(data)}"); // display "received: " + received data
}
}
// if you use socket communication and TCP.
final Communicator communicator = Tcp();
final Camel<Socket, SocketConnectionPoint> receiver = Camel(communicator);
CommandFactory.registerCommand(MyCommand()); // register command.
// call listen method with a bind connection point.
await for(
CommunicateData<Socket> _ in receiver.listen(
SocketConnectionPoint(address: "127.0.0.1", port: 50000)
)
){}
```

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
2 changes: 2 additions & 0 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sdk.dir=C:\\Users\\R.NOTO\\AppData\\Local\\Android\\sdk
flutter.sdk=C:\\Users\\R.NOTO\\fvm\\versions\\3.10.3
102 changes: 102 additions & 0 deletions doc/README.jp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Camel
[English](../README.md)<br/>

ローカルネットワークで通信を行うためのFlutterパッケージ。

## 特徴
このライブラリは"dart:io"ライブラリを使わず、簡単にローカルネットワーク通信を行えます。
また、受信データはコールバックかStreamを使用した形式か選択して使用することができます。

## インストール
このパッケージをpubspec.yamlに追加してください。
```yaml
# pubspec.yaml

dependencies:
camel: ^<latest version>
```
## 使用方法
### 送信側
受信側がCommandクラスのコールバック処理を使用しない場合は、以下のように送信処理を作成できます。
```dart
// TCPを使用したSocket通信を行う場合。
final Communicator communicator = Tcp();
final Camel<Socket, SocketConnectionPoint> sender = Camel(communicator);

// コネクションポイントと送信データを渡してsendメソッドを呼び出しします。
sender.send(
SocketConnectionPoint(address: "127.0.0.1", port: 50000),
Message.fromBody(command: "dummy", body: "Hello, Camel."),
);
```

受信側がCommandクラスのコールバック処理を使用する場合は、以下のようにします。
```dart
class MyCommand implements Command {
@override String get command => "MY_COMMAND";
@override
void execute(Uint8List data){
// このメソッドは受信側がデータを受信したときに呼び出されます。
print("received: ${utf8.decode(data)}"); // received: Hello, Camel.
}
}
// TCPを使用したSocket通信を行う場合。
final Communicator communicator = Tcp();
final Camel<Socket, SocketConnectionPoint> sender = Camel(communicator);
CommandFactory.registerCommand(MyCommand()); // 作成したコマンドの登録
// コネクションポイントと送信データを渡してsendメソッドを呼び出しします。
// この時、作成したコマンドの名前をcommand引数に渡します。
sender.send(
SocketConnectionPoint(address: "127.0.0.1", port: 50000),
Message.fromBody(command: "MY_COMMAND", body: "Hello, Camel."),
);
```

### 受信側
受信側がCommandクラスのコールバック処理を使用しない場合は、以下のように受信処理を作成できます。
```dart
// TCPを使用したSocket通信を行う場合。
final Communicator communicator = Tcp();
final Camel<Socket, SocketConnectionPoint> receiver = Camel(communicator);
// バインドするコネクションポイントとともにlistenメソッドを呼び出します。
await for(
CommunicateData<Socket> data in receiver.listen(
SocketConnectionPoint(address: "127.0.0.1", port: 50000)
)
){
print(data.message.body); // Streamとしてデータを受信します。
}
```


受信側がCommandクラスのコールバック処理を使用する場合は、以下のようにします。

```dart
class MyCommand implements Command {
@override String get command => "MY_COMMAND";
@override
void execute(Uint8List data){
// このメソッドは受信側がデータを受信したときに呼び出されます。
print("received: ${utf8.decode(data)}");
}
}
// TCPを使用したSocket通信を行う場合。
final Communicator communicator = Tcp();
final Camel<Socket, SocketConnectionPoint> receiver = Camel(communicator);
// バインドするコネクションポイントとともにlistenメソッドを呼び出します。
await for(
CommunicateData<Socket> _ in receiver.listen(
SocketConnectionPoint(address: "127.0.0.1", port: 50000)
)
){}
```

4 changes: 4 additions & 0 deletions exsample/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

analyzer:
exclude:
- test/*.mock.dart

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
Expand Down
2 changes: 1 addition & 1 deletion exsample/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Loading

0 comments on commit 70fc700

Please sign in to comment.