!14 upload sdk to pub.dev

Merge pull request !14 from 杨杰/master
This commit is contained in:
远方夕阳 2023-07-06 02:59:05 +00:00 committed by Gitee
commit 2ba80c85cf
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 200 additions and 124 deletions

View File

@ -0,0 +1,2 @@
# This is a generated file; do not edit or check into version control.
device_info_plus=C:\\Users\\smeb\\AppData\\Local\\Pub\\Cache\\hosted\\pub.flutter-io.cn\\device_info_plus-8.2.2\\

View File

@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"C:\\\\Users\\\\smeb\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\device_info_plus-8.2.2\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"C:\\\\Users\\\\smeb\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\device_info_plus-8.2.2\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"C:\\\\Users\\\\smeb\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\device_info_plus-8.2.2\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"C:\\\\Users\\\\smeb\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\device_info_plus-8.2.2\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"device_info_plus","path":"C:\\\\Users\\\\smeb\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\device_info_plus-8.2.2\\\\","native_build":false,"dependencies":[]}],"web":[{"name":"device_info_plus","path":"C:\\\\Users\\\\smeb\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.flutter-io.cn\\\\device_info_plus-8.2.2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]}],"date_created":"2023-07-04 15:53:37.990976","version":"3.7.7"}

View File

@ -1,3 +1,3 @@
## 0.0.1
## 1.0.1
* TODO: Describe initial release.
* 支持所有平台

View File

@ -1 +1,25 @@
TODO: Add your license here.
Copyright 2022 The SDK Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,18 +1,48 @@
# cim_flutter_sdk
A new Flutter plugin project.
开源通讯库 [CIM](https://gitee.com/farsunset/cim) 的 flutter版本SDK
## Getting Started
## 如何在自己的项目中引用SDK
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.
在 pubspec.yaml 引入
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.
```
dependencies:
cim_flutter_sdk:^1.0.1
```
## 如何使用
```
import 'package:cim_flutter_sdk/cim_socket.dart';
...
final CIMSocket cimSocket = CIMSocket();
String Message = 'Unknown';
cimSocket.init('127.0.0.1', 34567, 16501516154949);
cimSocket.connect();
cimSocket.addListener(() {
if (cimSocket.model == null) return;
setState(() {
Message = cimSocket.model!.toProto3Json().toString();
});
});
...
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Message is: $Message\n'),
),
),
);
```

View File

@ -0,0 +1,30 @@
# 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: app
# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da
base_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da
- platform: windows
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'

View File

@ -1,9 +1,8 @@
import 'package:cim_flutter_sdk/CimSocket.dart';
import 'package:cim_flutter_sdk/cim_socket.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());
@ -18,26 +17,22 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
String Message = 'Unknown';
final _cimFlutterSdkPlugin = CimFlutterSdk();
@override
void initState() {
super.initState();
initCimState();
}
final CIMSocket cimSocket = CIMSocket();
// 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.init('api.hoxin.farsunset.com', 34567, 16501516154949);
cimSocket.connect();
cimSocket.addListener(() {
print(cimSocket.model!.toProto3Json());
if (!mounted) return;
if (cimSocket.model == null) return;
setState(() {
Message = cimSocket.model!.toProto3Json().toString();
});

View File

@ -31,7 +31,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "1.0.1"
clock:
dependency: transitive
description:

View File

@ -5,8 +5,7 @@
// 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';
import 'cim_socket.dart';
class CimFlutterSdk {
final CIMSocket cimSocket = CIMSocket();

View File

@ -1,4 +1,3 @@
// ignore: file_names
import 'dart:async';
import 'dart:convert';
import 'dart:io';
@ -9,9 +8,9 @@ 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 './Message.pb.dart' as messages;
import './ReplyBody.pb.dart' as replybody;
import './SentBody.pb.dart' as sentbody;
import 'package:fixnum/fixnum.dart';
import 'package:convert/convert.dart';
@ -37,7 +36,7 @@ const PING_TYPE = 1;
// ignore: constant_identifier_names
const DATA_HEADER_LENGTH = 1;
const SOCKET_APP_VERSION = '100';
const sOCKETAPPVERSION = '100';
class CIMSocket extends ChangeNotifier {
late Socket? socket;
@ -49,11 +48,15 @@ class CIMSocket extends ChangeNotifier {
late TimerUtil timer = TimerUtil()
..mTotalTime = 10000
..setOnTimerTickCallback((millisUntilFinished) {
connect();
if (millisUntilFinished == 0 && uid != null) {
connect();
}
});
late bool isConnected = false;
late Message.Model? model = null;
late messages.Model? _model = null;
messages.Model? get model => _model;
Future init(String uri, int port, int uid) async {
this.uri = uri;
@ -75,47 +78,39 @@ class CIMSocket extends ChangeNotifier {
sendPong();
} else if (data[0] == REPLY_BODY) {
var message = data.sublist(3, length + 3);
ReplyBody.Model info = ReplyBody.Model();
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();
messages.Model model = messages.Model();
model.mergeFromBuffer(message);
switchMessage(model);
}
}, onError: (error, StackTrace trace) {
print('CIMSocket error');
socket = null;
isConnected = false;
if (!timer.isActive()) {
timer.startTimer();
timer.setTotalTime(12000);
timer.startCountDown();
}
notifyListeners();
}, onDone: () {
print('CIMSocket done');
socket = null;
isConnected = false;
notifyListeners();
if (endCode != "999") {
if (!timer.isActive()) {
timer.startTimer();
}
timer.setTotalTime(12000);
timer.startCountDown();
}
}, 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();
}
timer.setTotalTime(12000);
timer.startCountDown();
});
}
@ -141,7 +136,7 @@ class CIMSocket extends ChangeNotifier {
Map<String, String> map = {
"uid": uid.toString(), //id
"channel": channel,
"appVersion": SOCKET_APP_VERSION,
"appVersion": sOCKETAPPVERSION,
"osVersion": systemVersion,
"packageName": "cn.asihe.cim",
"deviceId": deviceId,
@ -151,7 +146,7 @@ class CIMSocket extends ChangeNotifier {
};
int time = DateTime.now().millisecondsSinceEpoch;
Int64 timeStamp = Int64.parseInt(time.toString());
var body = SentBody.Model(data: map);
var body = sentbody.Model(data: map);
body.key = "client_bind";
body.timestamp = timeStamp;
var data = body.writeToBuffer();
@ -162,7 +157,6 @@ class CIMSocket extends ChangeNotifier {
protobuf.setRange(3, data.length + 3, data);
socket!.add(protobuf);
await socket!.flush();
print('CIMSocket login finished');
isConnected = true;
if (timer.isActive()) {
timer.cancel();
@ -175,7 +169,7 @@ class CIMSocket extends ChangeNotifier {
Map<String, String> map1 = {"tag": tag};
int time = DateTime.now().millisecondsSinceEpoch;
Int64 timeStamp = Int64.parseInt(time.toString());
var body = SentBody.Model(data: map1);
var body = sentbody.Model(data: map1);
body.key = "client_set_tag";
body.timestamp = timeStamp;
var data = body.writeToBuffer();
@ -186,23 +180,22 @@ class CIMSocket extends ChangeNotifier {
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);
var pONG = Uint8List(7);
var pONGBODY = Uint8List(4);
pONGBODY[0] = 80;
pONGBODY[1] = 79;
pONGBODY[2] = 78;
pONGBODY[3] = 71;
pONG[0] = PONG_TYPE;
pONG[1] = (pONGBODY.length & 0xff);
pONG[2] = ((pONGBODY.length >> 8) & 0xff);
pONG.setRange(3, 6, pONGBODY);
socket!.add(pONG);
await socket!.flush();
isConnected = true;
if (timer.isActive()) {
@ -212,9 +205,8 @@ class CIMSocket extends ChangeNotifier {
}
///
Future switchMessage(Message.Model model, {bool isHistory = false}) async {
print(model.toProto3Json());
model = model;
Future switchMessage(messages.Model model) async {
_model = model;
notifyListeners();
}
}

View File

@ -1,7 +1,8 @@
name: cim_flutter_sdk
description: A new Flutter plugin project.
version: 0.0.1
homepage:
description: a flutter sdk for cim.
repository: https://gitee.com/farsunset/cim
version: 1.0.1
homepage: http://farsunset.com/
environment:
sdk: '>=2.19.4 <3.0.0'
@ -14,65 +15,67 @@ dependencies:
protobuf: ^2.0.1 # Google protobuf 序列化
device_info_plus: ^8.2.2
common_utils: ^2.1.0
crypto: ^3.0.3
convert: ^3.1.1
fixnum: ^1.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
# -------------------
#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 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
# 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