mirror of
https://gitee.com/farsunset/cim.git
synced 2025-07-16 21:16:16 +08:00
commit
f798e8a6fb
30
cim-client-sdk/cim-flutter-sdk/.gitignore
vendored
Normal file
30
cim-client-sdk/cim-flutter-sdk/.gitignore
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Miscellaneous
|
||||||
|
*.class
|
||||||
|
*.log
|
||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
.DS_Store
|
||||||
|
.atom/
|
||||||
|
.buildlog/
|
||||||
|
.history
|
||||||
|
.svn/
|
||||||
|
migrate_working_dir/
|
||||||
|
|
||||||
|
# IntelliJ related
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# The .vscode folder contains launch configuration and tasks you configure in
|
||||||
|
# VS Code which you may wish to be included in version control, so this line
|
||||||
|
# is commented out by default.
|
||||||
|
#.vscode/
|
||||||
|
|
||||||
|
# Flutter/Dart/Pub related
|
||||||
|
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||||
|
/pubspec.lock
|
||||||
|
**/doc/api/
|
||||||
|
.dart_tool/
|
||||||
|
.packages
|
||||||
|
build/
|
27
cim-client-sdk/cim-flutter-sdk/.metadata
Normal file
27
cim-client-sdk/cim-flutter-sdk/.metadata
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# This file tracks properties of this Flutter project.
|
||||||
|
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||||
|
#
|
||||||
|
# This file should be version controlled.
|
||||||
|
|
||||||
|
version:
|
||||||
|
revision: 2ad6cd72c040113b47ee9055e722606a490ef0da
|
||||||
|
channel: stable
|
||||||
|
|
||||||
|
project_type: plugin
|
||||||
|
|
||||||
|
# Tracks metadata for the flutter migrate command
|
||||||
|
migration:
|
||||||
|
platforms:
|
||||||
|
- platform: root
|
||||||
|
create_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da
|
||||||
|
base_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da
|
||||||
|
|
||||||
|
# User provided section
|
||||||
|
|
||||||
|
# List of Local paths (relative to this file) that should be
|
||||||
|
# ignored by the migrate tool.
|
||||||
|
#
|
||||||
|
# Files that are not part of the templates will be ignored by default.
|
||||||
|
unmanaged_files:
|
||||||
|
- 'lib/main.dart'
|
||||||
|
- 'ios/Runner.xcodeproj/project.pbxproj'
|
3
cim-client-sdk/cim-flutter-sdk/CHANGELOG.md
Normal file
3
cim-client-sdk/cim-flutter-sdk/CHANGELOG.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
## 0.0.1
|
||||||
|
|
||||||
|
* TODO: Describe initial release.
|
1
cim-client-sdk/cim-flutter-sdk/LICENSE
Normal file
1
cim-client-sdk/cim-flutter-sdk/LICENSE
Normal file
@ -0,0 +1 @@
|
|||||||
|
TODO: Add your license here.
|
18
cim-client-sdk/cim-flutter-sdk/README.md
Normal file
18
cim-client-sdk/cim-flutter-sdk/README.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# cim_flutter_sdk
|
||||||
|
|
||||||
|
A new Flutter plugin project.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
This project is a starting point for a Flutter
|
||||||
|
[plug-in package](https://flutter.dev/developing-packages/),
|
||||||
|
a specialized package that includes platform-specific implementation code for
|
||||||
|
Android and/or iOS.
|
||||||
|
|
||||||
|
For help getting started with Flutter development, view the
|
||||||
|
[online documentation](https://flutter.dev/docs), which offers tutorials,
|
||||||
|
samples, guidance on mobile development, and a full API reference.
|
||||||
|
|
||||||
|
The plugin project was generated without specifying the `--platforms` flag, no platforms are currently supported.
|
||||||
|
To add platforms, run `flutter create -t plugin --platforms <platforms> .` in this directory.
|
||||||
|
You can also find a detailed instruction on how to add platforms in the `pubspec.yaml` at https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms.
|
4
cim-client-sdk/cim-flutter-sdk/analysis_options.yaml
Normal file
4
cim-client-sdk/cim-flutter-sdk/analysis_options.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
include: package:flutter_lints/flutter.yaml
|
||||||
|
|
||||||
|
# Additional information about this file can be found at
|
||||||
|
# https://dart.dev/guides/language/analysis-options
|
@ -1,117 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import '../protobuf/Message.pb.dart' as Message;
|
|
||||||
import '../protobuf/ReplyBody.pb.dart' as ReplyBody;
|
|
||||||
import '../protobuf/SentBody.pb.dart' as SentBody;
|
|
||||||
import 'package:fixnum/fixnum.dart';
|
|
||||||
|
|
||||||
late Socket socket;
|
|
||||||
|
|
||||||
const APP_VERSION = "1.0.0";
|
|
||||||
const APP_CHANNEL = "web";
|
|
||||||
const APP_PACKAGE = "com.farsunset.cim";
|
|
||||||
const SERVER_URL = "192.168.10.133";
|
|
||||||
const SERVER_PORT = 23456;
|
|
||||||
|
|
||||||
//PONG
|
|
||||||
const PONG_TYPE = 0;
|
|
||||||
//发送消息类型
|
|
||||||
const Message_TYPE = 2;
|
|
||||||
//强制下线类型
|
|
||||||
const ACTION_999 = 999;
|
|
||||||
//响应消息类型
|
|
||||||
const REPLY_BODY = 4;
|
|
||||||
//消息发送
|
|
||||||
const SEND_BODY = 3;
|
|
||||||
//PING
|
|
||||||
const PING_TYPE = 1;
|
|
||||||
|
|
||||||
const DATA_HEADER_LENGTH = 1;
|
|
||||||
|
|
||||||
void connect() async {
|
|
||||||
print('-------------开始连接----------------');
|
|
||||||
Socket.connect(SERVER_URL, SERVER_PORT).then((Socket sock) {
|
|
||||||
// socket = sock;
|
|
||||||
sock.listen(dataHandler,
|
|
||||||
onError: errorHandler, onDone: doneHandler, cancelOnError: false);
|
|
||||||
socket = sock;
|
|
||||||
sendLoginMsg();
|
|
||||||
}).catchError((e) {
|
|
||||||
print("Unable to connect: $e");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void dataHandler(Uint8List data) {
|
|
||||||
print(data[0]);
|
|
||||||
int l = (data[1] & 0xff);
|
|
||||||
int h = (data[2] & 0xff);
|
|
||||||
int length = (l | h << 8);
|
|
||||||
if (data[0] == PING_TYPE) {
|
|
||||||
sendPong();
|
|
||||||
} else if (data[0] == REPLY_BODY) {
|
|
||||||
var message = data.sublist(3, length + 3);
|
|
||||||
ReplyBody.Model info = new ReplyBody.Model();
|
|
||||||
info.mergeFromBuffer(message);
|
|
||||||
print(info.key);
|
|
||||||
print(info);
|
|
||||||
} else if (data[0] == Message_TYPE) {
|
|
||||||
var message = data.sublist(3, length + 3);
|
|
||||||
Message.Model model = new Message.Model();
|
|
||||||
model.mergeFromBuffer(message);
|
|
||||||
print(model.action);
|
|
||||||
print(model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void errorHandler(error, StackTrace trace) {
|
|
||||||
print(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
void doneHandler() {
|
|
||||||
print("-------------连接失败----------------");
|
|
||||||
}
|
|
||||||
|
|
||||||
//发送登录消息
|
|
||||||
void sendLoginMsg() async {
|
|
||||||
Map<String, String> map = {
|
|
||||||
"uid": "11111111112346121631126311",
|
|
||||||
"channel": APP_CHANNEL,
|
|
||||||
"appVersion": APP_VERSION,
|
|
||||||
"osVersion": "Android 10",
|
|
||||||
"packageName": APP_PACKAGE,
|
|
||||||
"deviceId": "121155155a61d6a1s6d1as6d1a6s1da",
|
|
||||||
"deviceName": "andoirdPhone",
|
|
||||||
"language": "Zh_cn",
|
|
||||||
};
|
|
||||||
int time = new DateTime.now().millisecondsSinceEpoch;
|
|
||||||
Int64 timeStamp = Int64.parseInt(time.toString());
|
|
||||||
var body = SentBody.Model(data: map);
|
|
||||||
body.key = "client_bind";
|
|
||||||
body.timestamp = timeStamp;
|
|
||||||
var data = body.writeToBuffer();
|
|
||||||
var protobuf = new Uint8List(data.length + 3);
|
|
||||||
protobuf[0] = 3;
|
|
||||||
protobuf[1] = (data.length & 0xff);
|
|
||||||
protobuf[2] = ((data.length >> 8) & 0xff);
|
|
||||||
protobuf.setRange(3, data.length + 3, data);
|
|
||||||
socket.add(protobuf);
|
|
||||||
await socket.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
//发送PONG响应
|
|
||||||
void sendPong() async {
|
|
||||||
var PONG = new Uint8List(7);
|
|
||||||
var PONG_BODY = new Uint8List(4);
|
|
||||||
PONG_BODY[0] = 80;
|
|
||||||
PONG_BODY[1] = 79;
|
|
||||||
PONG_BODY[2] = 78;
|
|
||||||
PONG_BODY[3] = 71;
|
|
||||||
PONG[0] = PONG_TYPE;
|
|
||||||
PONG[1] = (PONG_BODY.length & 0xff);
|
|
||||||
PONG[2] = ((PONG_BODY.length >> 8) & 0xff);
|
|
||||||
PONG.setRange(3, 6, PONG_BODY);
|
|
||||||
socket.add(PONG);
|
|
||||||
await socket.flush();
|
|
||||||
print("发送Pong");
|
|
||||||
}
|
|
44
cim-client-sdk/cim-flutter-sdk/example/.gitignore
vendored
Normal file
44
cim-client-sdk/cim-flutter-sdk/example/.gitignore
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# Miscellaneous
|
||||||
|
*.class
|
||||||
|
*.log
|
||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
.DS_Store
|
||||||
|
.atom/
|
||||||
|
.buildlog/
|
||||||
|
.history
|
||||||
|
.svn/
|
||||||
|
migrate_working_dir/
|
||||||
|
|
||||||
|
# IntelliJ related
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# The .vscode folder contains launch configuration and tasks you configure in
|
||||||
|
# VS Code which you may wish to be included in version control, so this line
|
||||||
|
# is commented out by default.
|
||||||
|
#.vscode/
|
||||||
|
|
||||||
|
# Flutter/Dart/Pub related
|
||||||
|
**/doc/api/
|
||||||
|
**/ios/Flutter/.last_build_id
|
||||||
|
.dart_tool/
|
||||||
|
.flutter-plugins
|
||||||
|
.flutter-plugins-dependencies
|
||||||
|
.packages
|
||||||
|
.pub-cache/
|
||||||
|
.pub/
|
||||||
|
/build/
|
||||||
|
|
||||||
|
# Symbolication related
|
||||||
|
app.*.symbols
|
||||||
|
|
||||||
|
# Obfuscation related
|
||||||
|
app.*.map.json
|
||||||
|
|
||||||
|
# Android Studio will place build artifacts here
|
||||||
|
/android/app/debug
|
||||||
|
/android/app/profile
|
||||||
|
/android/app/release
|
16
cim-client-sdk/cim-flutter-sdk/example/README.md
Normal file
16
cim-client-sdk/cim-flutter-sdk/example/README.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# cim_flutter_sdk_example
|
||||||
|
|
||||||
|
Demonstrates how to use the cim_flutter_sdk plugin.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
This project is a starting point for a Flutter application.
|
||||||
|
|
||||||
|
A few resources to get you started if this is your first Flutter project:
|
||||||
|
|
||||||
|
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||||
|
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||||
|
|
||||||
|
For help getting started with Flutter development, view the
|
||||||
|
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||||
|
samples, guidance on mobile development, and a full API reference.
|
29
cim-client-sdk/cim-flutter-sdk/example/analysis_options.yaml
Normal file
29
cim-client-sdk/cim-flutter-sdk/example/analysis_options.yaml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# This file configures the analyzer, which statically analyzes Dart code to
|
||||||
|
# check for errors, warnings, and lints.
|
||||||
|
#
|
||||||
|
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
|
||||||
|
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
|
||||||
|
# invoked from the command line by running `flutter analyze`.
|
||||||
|
|
||||||
|
# The following line activates a set of recommended lints for Flutter apps,
|
||||||
|
# packages, and plugins designed to encourage good coding practices.
|
||||||
|
include: package:flutter_lints/flutter.yaml
|
||||||
|
|
||||||
|
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`
|
||||||
|
# included above or to enable additional rules. A list of all available lints
|
||||||
|
# and their documentation is published at
|
||||||
|
# https://dart-lang.github.io/linter/lints/index.html.
|
||||||
|
#
|
||||||
|
# Instead of disabling a lint rule for the entire project in the
|
||||||
|
# section below, it can also be suppressed for a single line of code
|
||||||
|
# or a specific dart file by using the `// ignore: name_of_lint` and
|
||||||
|
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
|
||||||
|
# producing the lint.
|
||||||
|
rules:
|
||||||
|
# avoid_print: false # Uncomment to disable the `avoid_print` rule
|
||||||
|
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
||||||
|
|
||||||
|
# Additional information about this file can be found at
|
||||||
|
# https://dart.dev/guides/language/analysis-options
|
65
cim-client-sdk/cim-flutter-sdk/example/lib/main.dart
Normal file
65
cim-client-sdk/cim-flutter-sdk/example/lib/main.dart
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import 'package:cim_flutter_sdk/CimSocket.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:cim_flutter_sdk/cim_flutter_sdk.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
runApp(const MyApp());
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyApp extends StatefulWidget {
|
||||||
|
const MyApp({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MyApp> createState() => _MyAppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MyAppState extends State<MyApp> {
|
||||||
|
String Message = 'Unknown';
|
||||||
|
final _cimFlutterSdkPlugin = CimFlutterSdk();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
initCimState();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Platform messages are asynchronous, so we initialize in an async method.
|
||||||
|
Future<void> initCimState() async {
|
||||||
|
CIMSocket cimSocket;
|
||||||
|
// Platform messages may fail, so we use a try/catch PlatformException.
|
||||||
|
// We also handle the message potentially returning null.
|
||||||
|
try {
|
||||||
|
cimSocket = await _cimFlutterSdkPlugin.connect(
|
||||||
|
'127.0.0.1', 23456, 16501516154949);
|
||||||
|
cimSocket.addListener(() {
|
||||||
|
print(cimSocket.model!.toProto3Json());
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
Message = cimSocket.model!.toProto3Json().toString();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} on PlatformException {}
|
||||||
|
|
||||||
|
// If the widget was removed from the tree while the asynchronous platform
|
||||||
|
// message was in flight, we want to discard the reply rather than calling
|
||||||
|
// setState to update our non-existent appearance.
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Plugin example app'),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: Text('Message is: $Message\n'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
313
cim-client-sdk/cim-flutter-sdk/example/pubspec.lock
Normal file
313
cim-client-sdk/cim-flutter-sdk/example/pubspec.lock
Normal file
@ -0,0 +1,313 @@
|
|||||||
|
# Generated by pub
|
||||||
|
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||||
|
packages:
|
||||||
|
async:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: async
|
||||||
|
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.10.0"
|
||||||
|
boolean_selector:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: boolean_selector
|
||||||
|
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.1"
|
||||||
|
characters:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: characters
|
||||||
|
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.1"
|
||||||
|
cim_flutter_sdk:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
path: ".."
|
||||||
|
relative: true
|
||||||
|
source: path
|
||||||
|
version: "0.0.1"
|
||||||
|
clock:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: clock
|
||||||
|
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.1"
|
||||||
|
collection:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: collection
|
||||||
|
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.17.0"
|
||||||
|
common_utils:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: common_utils
|
||||||
|
sha256: c26884339b13ff99b0739e56f4b02090c84054ed9dd3a045435cd24e7b99c2c1
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.0"
|
||||||
|
convert:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: convert
|
||||||
|
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "3.1.1"
|
||||||
|
crypto:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: crypto
|
||||||
|
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "3.0.3"
|
||||||
|
cupertino_icons:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: cupertino_icons
|
||||||
|
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.5"
|
||||||
|
decimal:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: decimal
|
||||||
|
sha256: eece91944f523657c75a3a008a90ec7f7eb3986191153a78570c7d0ac8ef3d01
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.2"
|
||||||
|
device_info_plus:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: device_info_plus
|
||||||
|
sha256: f52ab3b76b36ede4d135aab80194df8925b553686f0fa12226b4e2d658e45903
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "8.2.2"
|
||||||
|
device_info_plus_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: device_info_plus_platform_interface
|
||||||
|
sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "7.0.0"
|
||||||
|
fake_async:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: fake_async
|
||||||
|
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.3.1"
|
||||||
|
ffi:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: ffi
|
||||||
|
sha256: ed5337a5660c506388a9f012be0288fb38b49020ce2b45fe1f8b8323fe429f99
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.2"
|
||||||
|
file:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: file
|
||||||
|
sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "6.1.4"
|
||||||
|
fixnum:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: fixnum
|
||||||
|
sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.0"
|
||||||
|
flutter:
|
||||||
|
dependency: "direct main"
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
|
flutter_lints:
|
||||||
|
dependency: "direct dev"
|
||||||
|
description:
|
||||||
|
name: flutter_lints
|
||||||
|
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
|
flutter_test:
|
||||||
|
dependency: "direct dev"
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
|
flutter_web_plugins:
|
||||||
|
dependency: transitive
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
|
js:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: js
|
||||||
|
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "0.6.5"
|
||||||
|
lints:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: lints
|
||||||
|
sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
|
matcher:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: matcher
|
||||||
|
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "0.12.13"
|
||||||
|
material_color_utilities:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: material_color_utilities
|
||||||
|
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.0"
|
||||||
|
meta:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: meta
|
||||||
|
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.8.0"
|
||||||
|
path:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path
|
||||||
|
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.8.2"
|
||||||
|
plugin_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: plugin_platform_interface
|
||||||
|
sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.4"
|
||||||
|
protobuf:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: protobuf
|
||||||
|
sha256: "01dd9bd0fa02548bf2ceee13545d4a0ec6046459d847b6b061d8a27237108a08"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.0"
|
||||||
|
rational:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: rational
|
||||||
|
sha256: ba58e9e18df9abde280e8b10051e4bce85091e41e8e7e411b6cde2e738d357cf
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.2"
|
||||||
|
sky_engine:
|
||||||
|
dependency: transitive
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.99"
|
||||||
|
source_span:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: source_span
|
||||||
|
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.9.1"
|
||||||
|
stack_trace:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: stack_trace
|
||||||
|
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.11.0"
|
||||||
|
stream_channel:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: stream_channel
|
||||||
|
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.1"
|
||||||
|
string_scanner:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: string_scanner
|
||||||
|
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.0"
|
||||||
|
term_glyph:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: term_glyph
|
||||||
|
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.1"
|
||||||
|
test_api:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: test_api
|
||||||
|
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "0.4.16"
|
||||||
|
typed_data:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: typed_data
|
||||||
|
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "1.3.2"
|
||||||
|
vector_math:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: vector_math
|
||||||
|
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.4"
|
||||||
|
win32:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: win32
|
||||||
|
sha256: "5a751eddf9db89b3e5f9d50c20ab8612296e4e8db69009788d6c8b060a84191c"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "4.1.4"
|
||||||
|
sdks:
|
||||||
|
dart: ">=2.19.4 <3.0.0"
|
||||||
|
flutter: ">=2.11.0"
|
83
cim-client-sdk/cim-flutter-sdk/example/pubspec.yaml
Normal file
83
cim-client-sdk/cim-flutter-sdk/example/pubspec.yaml
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
name: cim_flutter_sdk_example
|
||||||
|
description: Demonstrates how to use the cim_flutter_sdk plugin.
|
||||||
|
# The following line prevents the package from being accidentally published to
|
||||||
|
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||||
|
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||||
|
|
||||||
|
environment:
|
||||||
|
sdk: '>=2.19.4 <3.0.0'
|
||||||
|
|
||||||
|
# Dependencies specify other packages that your package needs in order to work.
|
||||||
|
# To automatically upgrade your package dependencies to the latest versions
|
||||||
|
# consider running `flutter pub upgrade --major-versions`. Alternatively,
|
||||||
|
# dependencies can be manually updated by changing the version numbers below to
|
||||||
|
# the latest version available on pub.dev. To see which dependencies have newer
|
||||||
|
# versions available, run `flutter pub outdated`.
|
||||||
|
dependencies:
|
||||||
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
|
cim_flutter_sdk:
|
||||||
|
# When depending on this package from a real application you should use:
|
||||||
|
# cim_flutter_sdk: ^x.y.z
|
||||||
|
# See https://dart.dev/tools/pub/dependencies#version-constraints
|
||||||
|
# The example app is bundled with the plugin so we use a path dependency on
|
||||||
|
# the parent directory to use the current plugin's version.
|
||||||
|
path: ../
|
||||||
|
|
||||||
|
# The following adds the Cupertino Icons font to your application.
|
||||||
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
|
cupertino_icons: ^1.0.2
|
||||||
|
|
||||||
|
dev_dependencies:
|
||||||
|
flutter_test:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
|
# The "flutter_lints" package below contains a set of recommended lints to
|
||||||
|
# encourage good coding practices. The lint set provided by the package is
|
||||||
|
# activated in the `analysis_options.yaml` file located at the root of your
|
||||||
|
# package. See that file for information about deactivating specific lint
|
||||||
|
# rules and activating additional ones.
|
||||||
|
flutter_lints: ^2.0.0
|
||||||
|
|
||||||
|
# For information on the generic Dart part of this file, see the
|
||||||
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|
||||||
|
# The following section is specific to Flutter packages.
|
||||||
|
flutter:
|
||||||
|
|
||||||
|
# The following line ensures that the Material Icons font is
|
||||||
|
# included with your application, so that you can use the icons in
|
||||||
|
# the material Icons class.
|
||||||
|
uses-material-design: true
|
||||||
|
|
||||||
|
# To add assets to your application, add an assets section, like this:
|
||||||
|
# assets:
|
||||||
|
# - images/a_dot_burr.jpeg
|
||||||
|
# - images/a_dot_ham.jpeg
|
||||||
|
|
||||||
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
|
# https://flutter.dev/assets-and-images/#resolution-aware
|
||||||
|
|
||||||
|
# For details regarding adding assets from package dependencies, see
|
||||||
|
# https://flutter.dev/assets-and-images/#from-packages
|
||||||
|
|
||||||
|
# To add custom fonts to your application, add a fonts section here,
|
||||||
|
# in this "flutter" section. Each entry in this list should have a
|
||||||
|
# "family" key with the font family name, and a "fonts" key with a
|
||||||
|
# list giving the asset and other descriptors for the font. For
|
||||||
|
# example:
|
||||||
|
# fonts:
|
||||||
|
# - family: Schyler
|
||||||
|
# fonts:
|
||||||
|
# - asset: fonts/Schyler-Regular.ttf
|
||||||
|
# - asset: fonts/Schyler-Italic.ttf
|
||||||
|
# style: italic
|
||||||
|
# - family: Trajan Pro
|
||||||
|
# fonts:
|
||||||
|
# - asset: fonts/TrajanPro.ttf
|
||||||
|
# - asset: fonts/TrajanPro_Bold.ttf
|
||||||
|
# weight: 700
|
||||||
|
#
|
||||||
|
# For details regarding fonts from package dependencies,
|
||||||
|
# see https://flutter.dev/custom-fonts/#from-packages
|
27
cim-client-sdk/cim-flutter-sdk/example/test/widget_test.dart
Normal file
27
cim-client-sdk/cim-flutter-sdk/example/test/widget_test.dart
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// This is a basic Flutter widget test.
|
||||||
|
//
|
||||||
|
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||||
|
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||||
|
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||||
|
// tree, read text, and verify that the values of widget properties are correct.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
import 'package:cim_flutter_sdk_example/main.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Verify Platform version', (WidgetTester tester) async {
|
||||||
|
// Build our app and trigger a frame.
|
||||||
|
await tester.pumpWidget(const MyApp());
|
||||||
|
|
||||||
|
// Verify that platform version is retrieved.
|
||||||
|
expect(
|
||||||
|
find.byWidgetPredicate(
|
||||||
|
(Widget widget) => widget is Text &&
|
||||||
|
widget.data!.startsWith('Running on:'),
|
||||||
|
),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
268
cim-client-sdk/cim-flutter-sdk/lib/CimSocket.dart
Normal file
268
cim-client-sdk/cim-flutter-sdk/lib/CimSocket.dart
Normal file
@ -0,0 +1,268 @@
|
|||||||
|
// ignore: file_names
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:common_utils/common_utils.dart';
|
||||||
|
import 'package:crypto/crypto.dart';
|
||||||
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import './Message.pb.dart' as Message;
|
||||||
|
import './ReplyBody.pb.dart' as ReplyBody;
|
||||||
|
import './SentBody.pb.dart' as SentBody;
|
||||||
|
import 'package:fixnum/fixnum.dart';
|
||||||
|
import 'package:convert/convert.dart';
|
||||||
|
|
||||||
|
//PONG
|
||||||
|
// ignore: constant_identifier_names
|
||||||
|
const PONG_TYPE = 0;
|
||||||
|
//发送消息类型
|
||||||
|
// ignore: constant_identifier_names
|
||||||
|
const Message_TYPE = 2;
|
||||||
|
//强制下线类型
|
||||||
|
// ignore: constant_identifier_names
|
||||||
|
const ACTION_999 = 999;
|
||||||
|
//响应消息类型
|
||||||
|
// ignore: constant_identifier_names
|
||||||
|
const REPLY_BODY = 4;
|
||||||
|
//消息发送
|
||||||
|
// ignore: constant_identifier_names
|
||||||
|
const SEND_BODY = 3;
|
||||||
|
//PING
|
||||||
|
// ignore: constant_identifier_names
|
||||||
|
const PING_TYPE = 1;
|
||||||
|
|
||||||
|
// ignore: constant_identifier_names
|
||||||
|
const DATA_HEADER_LENGTH = 1;
|
||||||
|
|
||||||
|
const SOCKET_APP_VERSION = '100';
|
||||||
|
|
||||||
|
class CIMSocket extends ChangeNotifier {
|
||||||
|
late Socket? socket;
|
||||||
|
late String? uri;
|
||||||
|
late int? port;
|
||||||
|
late int? uid;
|
||||||
|
late String endCode = "0";
|
||||||
|
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
|
||||||
|
late TimerUtil timer = TimerUtil()
|
||||||
|
..mTotalTime = 10000
|
||||||
|
..setOnTimerTickCallback((millisUntilFinished) {
|
||||||
|
connect();
|
||||||
|
});
|
||||||
|
late bool isConnected = false;
|
||||||
|
|
||||||
|
late Message.Model? model = null;
|
||||||
|
|
||||||
|
Future init(String uri, int port, int uid) async {
|
||||||
|
this.uri = uri;
|
||||||
|
this.port = port;
|
||||||
|
this.uid = uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
//登录
|
||||||
|
Future connect() async {
|
||||||
|
if (uri == null || port == null || uid == null) {
|
||||||
|
throw IOException;
|
||||||
|
}
|
||||||
|
Socket.connect(uri, port!).then((Socket sock) {
|
||||||
|
sock.listen((data) async {
|
||||||
|
int l = (data[1] & 0xff);
|
||||||
|
int h = (data[2] & 0xff);
|
||||||
|
int length = (l | h << 8);
|
||||||
|
if (data[0] == PING_TYPE) {
|
||||||
|
sendPong();
|
||||||
|
} else if (data[0] == REPLY_BODY) {
|
||||||
|
var message = data.sublist(3, length + 3);
|
||||||
|
ReplyBody.Model info = ReplyBody.Model();
|
||||||
|
info.mergeFromBuffer(message);
|
||||||
|
} else if (data[0] == Message_TYPE) {
|
||||||
|
var message = data.sublist(3, length + 3);
|
||||||
|
Message.Model model = Message.Model();
|
||||||
|
model.mergeFromBuffer(message);
|
||||||
|
switchMessage(model);
|
||||||
|
}
|
||||||
|
}, onError: (error, StackTrace trace) {
|
||||||
|
print('CIMSocket error');
|
||||||
|
socket = null;
|
||||||
|
isConnected = false;
|
||||||
|
if (!timer.isActive()) {
|
||||||
|
timer.startTimer();
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}, onDone: () {
|
||||||
|
print('CIMSocket done');
|
||||||
|
socket = null;
|
||||||
|
isConnected = false;
|
||||||
|
notifyListeners();
|
||||||
|
if (endCode != "999") {
|
||||||
|
if (!timer.isActive()) {
|
||||||
|
timer.startTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, cancelOnError: true);
|
||||||
|
socket = sock;
|
||||||
|
sendLoginMsg();
|
||||||
|
}).catchError((e) {
|
||||||
|
print('CIMSocket catcherror');
|
||||||
|
print('Unable to connect: $e');
|
||||||
|
socket = null;
|
||||||
|
isConnected = false;
|
||||||
|
notifyListeners();
|
||||||
|
// Future.delayed(Duration(milliseconds: 3000), () {
|
||||||
|
// connect();
|
||||||
|
// });
|
||||||
|
if (!timer.isActive()) {
|
||||||
|
timer.startTimer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//登出
|
||||||
|
Future disConnect() async {
|
||||||
|
if (socket != null) {
|
||||||
|
endCode = '999';
|
||||||
|
await socket!.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//发送登录消息
|
||||||
|
Future sendLoginMsg() async {
|
||||||
|
SystemInfo systemInfo = SystemInfo();
|
||||||
|
await systemInfo.init();
|
||||||
|
String deviceName = systemInfo.deviceName;
|
||||||
|
// DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
|
||||||
|
String channel = systemInfo.deviceName;
|
||||||
|
String systemVersion = systemInfo.version;
|
||||||
|
String deviceId = hex.encode(
|
||||||
|
md5.convert(const Utf8Encoder().convert(systemInfo.deviceId)).bytes);
|
||||||
|
|
||||||
|
Map<String, String> map = {
|
||||||
|
"uid": uid.toString(), //主id
|
||||||
|
"channel": channel,
|
||||||
|
"appVersion": SOCKET_APP_VERSION,
|
||||||
|
"osVersion": systemVersion,
|
||||||
|
"packageName": "cn.asihe.cim",
|
||||||
|
"deviceId": deviceId,
|
||||||
|
// (await PlatformDeviceId.getDeviceId)!.replaceAll("-", ""), //应用id
|
||||||
|
"deviceName": '$deviceName ${systemInfo.model}',
|
||||||
|
"language": "zh-CN",
|
||||||
|
};
|
||||||
|
int time = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
Int64 timeStamp = Int64.parseInt(time.toString());
|
||||||
|
var body = SentBody.Model(data: map);
|
||||||
|
body.key = "client_bind";
|
||||||
|
body.timestamp = timeStamp;
|
||||||
|
var data = body.writeToBuffer();
|
||||||
|
var protobuf = Uint8List(data.length + 3);
|
||||||
|
protobuf[0] = 3;
|
||||||
|
protobuf[1] = (data.length & 0xff);
|
||||||
|
protobuf[2] = ((data.length >> 8) & 0xff);
|
||||||
|
protobuf.setRange(3, data.length + 3, data);
|
||||||
|
socket!.add(protobuf);
|
||||||
|
await socket!.flush();
|
||||||
|
print('CIMSocket login finished');
|
||||||
|
isConnected = true;
|
||||||
|
if (timer.isActive()) {
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 发送群组聊天 tag
|
||||||
|
Future<int> sendTag(String tag) async {
|
||||||
|
Map<String, String> map1 = {"tag": tag};
|
||||||
|
int time = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
Int64 timeStamp = Int64.parseInt(time.toString());
|
||||||
|
var body = SentBody.Model(data: map1);
|
||||||
|
body.key = "client_set_tag";
|
||||||
|
body.timestamp = timeStamp;
|
||||||
|
var data = body.writeToBuffer();
|
||||||
|
var protobuf = Uint8List(data.length + 3);
|
||||||
|
protobuf[0] = 3;
|
||||||
|
protobuf[1] = (data.length & 0xff);
|
||||||
|
protobuf[2] = ((data.length >> 8) & 0xff);
|
||||||
|
protobuf.setRange(3, data.length + 3, data);
|
||||||
|
socket!.add(protobuf);
|
||||||
|
await socket!.flush();
|
||||||
|
print('CIMSocket bind chattingTag Success!');
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//发送PONG响应
|
||||||
|
Future sendPong() async {
|
||||||
|
var PONG = Uint8List(7);
|
||||||
|
var PONG_BODY = Uint8List(4);
|
||||||
|
PONG_BODY[0] = 80;
|
||||||
|
PONG_BODY[1] = 79;
|
||||||
|
PONG_BODY[2] = 78;
|
||||||
|
PONG_BODY[3] = 71;
|
||||||
|
PONG[0] = PONG_TYPE;
|
||||||
|
PONG[1] = (PONG_BODY.length & 0xff);
|
||||||
|
PONG[2] = ((PONG_BODY.length >> 8) & 0xff);
|
||||||
|
PONG.setRange(3, 6, PONG_BODY);
|
||||||
|
socket!.add(PONG);
|
||||||
|
await socket!.flush();
|
||||||
|
isConnected = true;
|
||||||
|
if (timer.isActive()) {
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
///消息分发器
|
||||||
|
Future switchMessage(Message.Model model, {bool isHistory = false}) async {
|
||||||
|
print(model.toProto3Json());
|
||||||
|
model = model;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SystemInfo {
|
||||||
|
String deviceName = 'cim_entity';
|
||||||
|
String version = '0.0.1';
|
||||||
|
String deviceId = 'CIM Entity';
|
||||||
|
String model = "10";
|
||||||
|
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
|
||||||
|
|
||||||
|
Future init() async {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
// Android相关代码
|
||||||
|
var value = await deviceInfoPlugin.androidInfo;
|
||||||
|
deviceName = 'android';
|
||||||
|
version = value.version.release;
|
||||||
|
deviceId = value.id;
|
||||||
|
model = value.model;
|
||||||
|
} else if (Platform.isIOS) {
|
||||||
|
// iOS相关代码
|
||||||
|
var value = await deviceInfoPlugin.iosInfo;
|
||||||
|
deviceName = 'ios';
|
||||||
|
version = value.systemVersion!;
|
||||||
|
deviceId = value.identifierForVendor!;
|
||||||
|
model = value.model!;
|
||||||
|
} else if (Platform.isMacOS) {
|
||||||
|
// MacOS相关代码
|
||||||
|
var value = await deviceInfoPlugin.macOsInfo;
|
||||||
|
|
||||||
|
deviceName = 'macos';
|
||||||
|
version = value.kernelVersion;
|
||||||
|
deviceId = value.model;
|
||||||
|
model = value.model;
|
||||||
|
} else if (Platform.isWindows) {
|
||||||
|
// Windows相关代码
|
||||||
|
var value = await deviceInfoPlugin.windowsInfo;
|
||||||
|
deviceName = 'windows';
|
||||||
|
version = value.displayVersion;
|
||||||
|
deviceId = value.deviceId;
|
||||||
|
model = value.majorVersion.toString();
|
||||||
|
} else if (Platform.isLinux) {
|
||||||
|
// Linux相关代码
|
||||||
|
var value = await deviceInfoPlugin.linuxInfo;
|
||||||
|
deviceName = 'linux';
|
||||||
|
version = value.version!;
|
||||||
|
deviceId = value.id;
|
||||||
|
model = value.version!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
cim-client-sdk/cim-flutter-sdk/lib/cim_flutter_sdk.dart
Normal file
22
cim-client-sdk/cim-flutter-sdk/lib/cim_flutter_sdk.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// You have generated a new plugin project without specifying the `--platforms`
|
||||||
|
// flag. A plugin project with no platform support was generated. To add a
|
||||||
|
// platform, run `flutter create -t plugin --platforms <platforms> .` under the
|
||||||
|
// same directory. You can also find a detailed instruction on how to add
|
||||||
|
// platforms in the `pubspec.yaml` at
|
||||||
|
// https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms.
|
||||||
|
|
||||||
|
import 'CimSocket.dart';
|
||||||
|
import 'cim_flutter_sdk_platform_interface.dart';
|
||||||
|
|
||||||
|
class CimFlutterSdk {
|
||||||
|
final CIMSocket cimSocket = CIMSocket();
|
||||||
|
Future<CIMSocket> connect(String uri, int port, int uid) async {
|
||||||
|
cimSocket.init(uri, port, uid);
|
||||||
|
cimSocket.connect();
|
||||||
|
return cimSocket;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> disconnect() async {
|
||||||
|
cimSocket.disConnect();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
import 'cim_flutter_sdk_platform_interface.dart';
|
||||||
|
|
||||||
|
/// An implementation of [CimFlutterSdkPlatform] that uses method channels.
|
||||||
|
class MethodChannelCimFlutterSdk extends CimFlutterSdkPlatform {
|
||||||
|
/// The method channel used to interact with the native platform.
|
||||||
|
@visibleForTesting
|
||||||
|
final methodChannel = const MethodChannel('cim_flutter_sdk');
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<String?> getPlatformVersion() async {
|
||||||
|
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||||
|
|
||||||
|
import 'cim_flutter_sdk_method_channel.dart';
|
||||||
|
|
||||||
|
abstract class CimFlutterSdkPlatform extends PlatformInterface {
|
||||||
|
/// Constructs a CimFlutterSdkPlatform.
|
||||||
|
CimFlutterSdkPlatform() : super(token: _token);
|
||||||
|
|
||||||
|
static final Object _token = Object();
|
||||||
|
|
||||||
|
static CimFlutterSdkPlatform _instance = MethodChannelCimFlutterSdk();
|
||||||
|
|
||||||
|
/// The default instance of [CimFlutterSdkPlatform] to use.
|
||||||
|
///
|
||||||
|
/// Defaults to [MethodChannelCimFlutterSdk].
|
||||||
|
static CimFlutterSdkPlatform get instance => _instance;
|
||||||
|
|
||||||
|
/// Platform-specific implementations should set this with their own
|
||||||
|
/// platform-specific class that extends [CimFlutterSdkPlatform] when
|
||||||
|
/// they register themselves.
|
||||||
|
static set instance(CimFlutterSdkPlatform instance) {
|
||||||
|
PlatformInterface.verifyToken(instance, _token);
|
||||||
|
_instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String?> getPlatformVersion() {
|
||||||
|
throw UnimplementedError('platformVersion() has not been implemented.');
|
||||||
|
}
|
||||||
|
}
|
78
cim-client-sdk/cim-flutter-sdk/pubspec.yaml
Normal file
78
cim-client-sdk/cim-flutter-sdk/pubspec.yaml
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
name: cim_flutter_sdk
|
||||||
|
description: A new Flutter plugin project.
|
||||||
|
version: 0.0.1
|
||||||
|
homepage:
|
||||||
|
|
||||||
|
environment:
|
||||||
|
sdk: '>=2.19.4 <3.0.0'
|
||||||
|
flutter: '>=2.5.0'
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
plugin_platform_interface: ^2.0.2
|
||||||
|
protobuf: ^2.0.1 # Google protobuf 序列化
|
||||||
|
device_info_plus: ^8.2.2
|
||||||
|
common_utils: ^2.1.0
|
||||||
|
|
||||||
|
dev_dependencies:
|
||||||
|
flutter_test:
|
||||||
|
sdk: flutter
|
||||||
|
flutter_lints: ^2.0.0
|
||||||
|
|
||||||
|
# For information on the generic Dart part of this file, see the
|
||||||
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|
||||||
|
# The following section is specific to Flutter packages.
|
||||||
|
flutter:
|
||||||
|
# This section identifies this Flutter project as a plugin project.
|
||||||
|
# The 'pluginClass' specifies the class (in Java, Kotlin, Swift, Objective-C, etc.)
|
||||||
|
# which should be registered in the plugin registry. This is required for
|
||||||
|
# using method channels.
|
||||||
|
# The Android 'package' specifies package in which the registered class is.
|
||||||
|
# This is required for using method channels on Android.
|
||||||
|
# The 'ffiPlugin' specifies that native code should be built and bundled.
|
||||||
|
# This is required for using `dart:ffi`.
|
||||||
|
# All these are used by the tooling to maintain consistency when
|
||||||
|
# adding or updating assets for this project.
|
||||||
|
plugin:
|
||||||
|
platforms:
|
||||||
|
# This plugin project was generated without specifying any
|
||||||
|
# platforms with the `--platform` argument. If you see the `some_platform` map below, remove it and
|
||||||
|
# then add platforms following the instruction here:
|
||||||
|
# https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms
|
||||||
|
# -------------------
|
||||||
|
some_platform:
|
||||||
|
pluginClass: somePluginClass
|
||||||
|
# -------------------
|
||||||
|
|
||||||
|
# To add assets to your plugin package, add an assets section, like this:
|
||||||
|
# assets:
|
||||||
|
# - images/a_dot_burr.jpeg
|
||||||
|
# - images/a_dot_ham.jpeg
|
||||||
|
#
|
||||||
|
# For details regarding assets in packages, see
|
||||||
|
# https://flutter.dev/assets-and-images/#from-packages
|
||||||
|
#
|
||||||
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
|
# https://flutter.dev/assets-and-images/#resolution-aware
|
||||||
|
|
||||||
|
# To add custom fonts to your plugin package, add a fonts section here,
|
||||||
|
# in this "flutter" section. Each entry in this list should have a
|
||||||
|
# "family" key with the font family name, and a "fonts" key with a
|
||||||
|
# list giving the asset and other descriptors for the font. For
|
||||||
|
# example:
|
||||||
|
# fonts:
|
||||||
|
# - family: Schyler
|
||||||
|
# fonts:
|
||||||
|
# - asset: fonts/Schyler-Regular.ttf
|
||||||
|
# - asset: fonts/Schyler-Italic.ttf
|
||||||
|
# style: italic
|
||||||
|
# - family: Trajan Pro
|
||||||
|
# fonts:
|
||||||
|
# - asset: fonts/TrajanPro.ttf
|
||||||
|
# - asset: fonts/TrajanPro_Bold.ttf
|
||||||
|
# weight: 700
|
||||||
|
#
|
||||||
|
# For details regarding fonts in packages, see
|
||||||
|
# https://flutter.dev/custom-fonts/#from-packages
|
Loading…
x
Reference in New Issue
Block a user