master
jack ning 3 years ago
parent 95c9c66142
commit 96f627500b

@ -3,12 +3,14 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {
/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3D8CAEDC2823D9A400EBA5BE /* Info-Release.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3D8CAEDA2823D9A400EBA5BE /* Info-Release.plist */; };
3D8CAEDD2823D9A400EBA5BE /* Info-Profile.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3D8CAEDB2823D9A400EBA5BE /* Info-Profile.plist */; };
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
@ -36,6 +38,8 @@
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
1BE257D15466126E85068C73 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3D8CAEDA2823D9A400EBA5BE /* Info-Release.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Release.plist"; sourceTree = "<group>"; };
3D8CAEDB2823D9A400EBA5BE /* Info-Profile.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Profile.plist"; sourceTree = "<group>"; };
76314B5AB6122B6FE14148CA /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@ -47,7 +51,7 @@
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info-Debug.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-Debug.plist"; sourceTree = "<group>"; };
BA046583E3DEF9F4762795D2 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -70,7 +74,6 @@
BA046583E3DEF9F4762795D2 /* Pods-Runner.release.xcconfig */,
01F8337D7CF1E25D0170423C /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
@ -112,7 +115,9 @@
97C146FA1CF9000F007C117D /* Main.storyboard */,
97C146FD1CF9000F007C117D /* Assets.xcassets */,
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
97C147021CF9000F007C117D /* Info.plist */,
97C147021CF9000F007C117D /* Info-Debug.plist */,
3D8CAEDB2823D9A400EBA5BE /* Info-Profile.plist */,
3D8CAEDA2823D9A400EBA5BE /* Info-Release.plist */,
97C146F11CF9000F007C117D /* Supporting Files */,
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
@ -199,8 +204,10 @@
buildActionMask = 2147483647;
files = (
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
3D8CAEDC2823D9A400EBA5BE /* Info-Release.plist in Resources */,
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
3D8CAEDD2823D9A400EBA5BE /* Info-Profile.plist in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -368,7 +375,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = L5F47963M2;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@ -492,7 +499,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = L5F47963M2;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@ -511,7 +518,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = L5F47963M2;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>zh_CN</string>
<key>CFBundleDisplayName</key>
<string>萝卜丝Demo</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>bytedesk_demo</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSAppleMusicUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取音乐</string>
<key>NSCalendarsUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取日历</string>
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) 拍照并发送图片</string>
<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取联系人推荐好友</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用,如果您需要使用后台定位功能请选择“始终允许”。</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) 发送语音</string>
<key>NSMotionUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取运动健身</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) 发送图片</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) 发送图片</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取语音识别</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocalNetworkUsageDescription</key>
<string>Allow flutter to access localhost</string>
<key>NSBonjourServices</key>
<array>
<string>_dartobservatory._tcp</string>
</array>
</dict>
</plist>

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>zh_CN</string>
<key>CFBundleDisplayName</key>
<string>萝卜丝Demo</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>bytedesk_demo</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true />
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true />
</dict>
<key>NSAppleMusicUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取音乐</string>
<key>NSCalendarsUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取日历</string>
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) 拍照并发送图片</string>
<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取联系人推荐好友</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用,如果您需要使用后台定位功能请选择“始终允许”。</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) 发送语音</string>
<key>NSMotionUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取运动健身</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) 发送图片</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) 发送图片</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取语音识别</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false />
</dict>
</plist>

@ -30,9 +30,9 @@ void main() {
String _subDomain = "vip";
//
BytedeskKefu.init(_appKey, _subDomain);
// 使:
// BytedeskKefu.initWithUsernameAndNicknameAndAvatar('myuniappusername', '我是美女', 'https://bytedesk.oss-cn-shenzhen.aliyuncs.com/avatars/girl.png', subDomain, appKey);
// BytedeskKefu.initWithUsername('myuniappusername',subDomain, appKey); // username
// 使usernamenickname使
// BytedeskKefu.initWithUsernameAndNicknameAndAvatar('myflutterusername', '我是美女', 'https://bytedesk.oss-cn-shenzhen.aliyuncs.com/avatars/girl.png', _appKey, _subDomain);
// BytedeskKefu.initWithUsername('myflutterusername', _appKey, _subDomain); // username
// /使 initWithUsernameAndNicknameinitWithUsernameAndNicknameAndAvatar
// bytedesk_kefu/bytedesk_kefu.dart
}
@ -228,7 +228,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
} else if (event.message.type == BytedeskConstants.MESSAGE_TYPE_FILE) {
print('文件消息:' + event.message.fileUrl!);
} else {
print('其他类型消息');
print('其他类型消息:' + event.message.type!);
}
});
// token

@ -204,10 +204,10 @@ class _ChatTypePageState extends State<ChatTypePage> {
title: const Text('H5网页会话'),
trailing: const Icon(Icons.keyboard_arrow_right),
onTap: () {
print('h5 chat');
// print('h5 chat');
// : ->->()-> URL
String url =
"https://h1.kefux.cn/chat/h5/index.html?sub=vip&uid=201808221551193&wid=201807171659201&type=workGroup&aid=&hidenav=1&ph=ph";
"https://h2.kefux.cn/chat/h5/index.html?sub=vip&uid=201808221551193&wid=201807171659201&type=workGroup&aid=&hidenav=1&ph=ph";
String title = 'H5在线客服演示';
BytedeskKefu.startH5Chat(context, url, title);
},

@ -46,7 +46,7 @@ dependencies:
# 请在ios/Podfile中添加use_frameworks!
vibration: ^1.7.3
# 在线客服 https://pub.dev/packages/bytedesk_kefu
bytedesk_kefu: ^1.2.4
bytedesk_kefu: ^1.2.5
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.

@ -1,5 +1,9 @@
# Upgrade Log
## 1.2.5
* optimize user experience
## 1.2.4
* optimize user experience

@ -34,6 +34,8 @@
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3D8CAED62823D79D00EBA5BE /* Info-Release.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Release.plist"; sourceTree = "<group>"; };
3D8CAED82823D86F00EBA5BE /* Info-Profile.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Profile.plist"; sourceTree = "<group>"; };
483DAFF376EA336E70A1AF95 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
72FBC4611027C1F583CD56F7 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
@ -46,7 +48,7 @@
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info-Debug.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-Debug.plist"; sourceTree = "<group>"; };
ACD77D260F2F57A568414FB9 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DB686996A5E8B0AF86E5C84F /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -119,7 +121,9 @@
97C146FA1CF9000F007C117D /* Main.storyboard */,
97C146FD1CF9000F007C117D /* Assets.xcassets */,
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
97C147021CF9000F007C117D /* Info.plist */,
97C147021CF9000F007C117D /* Info-Debug.plist */,
3D8CAED82823D86F00EBA5BE /* Info-Profile.plist */,
3D8CAED62823D79D00EBA5BE /* Info-Release.plist */,
97C146F11CF9000F007C117D /* Supporting Files */,
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
@ -367,7 +371,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = L5F47963M2;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@ -491,7 +495,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = L5F47963M2;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@ -510,7 +514,7 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = L5F47963M2;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>萝卜丝Demo</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSAppleMusicUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取音乐</string>
<key>NSCalendarsUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取日历</string>
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) 拍照并发送图片</string>
<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取联系人推荐好友</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用,如果您需要使用后台定位功能请选择“始终允许”。</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) 发送语音</string>
<key>NSMotionUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取运动健身</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) 发送图片</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) 发送图片</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取语音识别</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocalNetworkUsageDescription</key>
<string>allow flutter to access localhost network</string>
<key>NSBonjourServices</key>
<array>
<string>_dartobservatory._tcp</string>
</array>
</dict>
</plist>

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>萝卜丝Demo</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSAppleMusicUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取音乐</string>
<key>NSCalendarsUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取日历</string>
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) 拍照并发送图片</string>
<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取联系人推荐好友</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用,如果您需要使用后台定位功能请选择“始终允许”。</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>地图功能需要您的定位服务,否则无法使用。</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) 发送语音</string>
<key>NSMotionUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取运动健身</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) 发送图片</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) 发送图片</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>$(PRODUCT_NAME) 需要读取语音识别</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>

@ -30,9 +30,9 @@ void main() {
String _subDomain = "vip";
//
BytedeskKefu.init(_appKey, _subDomain);
// 使:
// BytedeskKefu.initWithUsernameAndNicknameAndAvatar('myuniappusername', '我是美女', 'https://bytedesk.oss-cn-shenzhen.aliyuncs.com/avatars/girl.png', subDomain, appKey);
// BytedeskKefu.initWithUsername('myuniappusername',subDomain, appKey); // username
// 使usernamenickname使
// BytedeskKefu.initWithUsernameAndNicknameAndAvatar('myflutterusername', '我是美女', 'https://bytedesk.oss-cn-shenzhen.aliyuncs.com/avatars/girl.png', _appKey, _subDomain);
// BytedeskKefu.initWithUsername('myflutterusername', _appKey, _subDomain); // username
// /使 initWithUsernameAndNicknameinitWithUsernameAndNicknameAndAvatar
// bytedesk_kefu/bytedesk_kefu.dart
}
@ -134,6 +134,12 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
}));
},
),
// ListTile(
// title: Text('退出登录'),
// onTap: () {
// BytedeskKefu.logout();
// },
// ),
ListTile(
title: Text('技术支持: QQ-3群: 825257535'),
)
@ -227,7 +233,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
} else if (event.message.type == BytedeskConstants.MESSAGE_TYPE_FILE) {
print('文件消息:' + event.message.fileUrl!);
} else {
print('其他类型消息');
print('其他类型消息:' + event.message.type!);
}
});
// token

@ -207,7 +207,7 @@ class _ChatTypePageState extends State<ChatTypePage> {
print('h5 chat');
// : ->->()-> URL
String url =
"https://h1.kefux.cn/chat/h5/index.html?sub=vip&uid=201808221551193&wid=201807171659201&type=workGroup&aid=&hidenav=1&ph=ph";
"https://h2.kefux.cn/chat/h5/index.html?sub=vip&uid=201808221551193&wid=201807171659201&type=workGroup&aid=&hidenav=1&ph=ph";
String title = 'H5在线客服演示';
BytedeskKefu.startH5Chat(context, url, title);
},

@ -1,4 +1,4 @@
import 'dart:async';
// import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:bytedesk_kefu/blocs/contact_bloc/bloc.dart';
import 'package:bytedesk_kefu/repositories/contact_repository.dart';
@ -6,31 +6,29 @@ import 'package:bytedesk_kefu/repositories/contact_repository.dart';
class ContactBloc extends Bloc<ContactEvent, ContactState> {
final ContactRepository contactRepository = new ContactRepository();
// ContactBloc({@required this.contactRepository});
ContactBloc() : super(ContactUninitialized());
ContactBloc() : super(ContactUninitialized()) {
on<RefreshContactEvent>(_mapRefreshContactToState);
}
// @override
// ContactState get initialState => ContactUninitialized();
@override
Stream<ContactState> mapEventToState(ContactEvent event) async* {
//
if (event is RefreshContactEvent) {
yield* _mapRefreshContactToState(event);
} else {
//
}
}
// Stream<ContactState> mapEventToState(ContactEvent event) async* {
// //
// if (event is RefreshContactEvent) {
// yield* _mapRefreshContactToState(event);
// } else {
// //
// }
// }
Stream<ContactState> _mapRefreshContactToState(
RefreshContactEvent event) async* {
yield ContactLoading();
void _mapRefreshContactToState(
RefreshContactEvent event, Emitter<ContactState> emit) async {
emit(ContactLoading());
try {
// final List<Contact> contactList = await contactRepository.getContacts();
// yield ContactLoadSuccess(contactList);
} catch (error) {
print(error);
yield ContactLoadError();
emit(ContactLoadError());
}
}
}

@ -1,4 +1,4 @@
import 'dart:async';
// import 'dart:async';
import 'package:bytedesk_kefu/blocs/feedback_bloc/bloc.dart';
import 'package:bytedesk_kefu/model/helpCategory.dart';
// import 'package:bytedesk_kefu/model/jsonResult.dart';
@ -9,55 +9,58 @@ class FeedbackBloc extends Bloc<FeedbackEvent, FeedbackState> {
//
final FeedbackRepository feedbackRepository = new FeedbackRepository();
FeedbackBloc() : super(new UnFeedbackState());
@override
Stream<FeedbackState> mapEventToState(
FeedbackEvent event,
) async* {
if (event is GetFeedbackCategoryEvent) {
yield* _mapGetFeedbackCategoryToState(event);
} else if (event is SubmitFeedbackEvent) {
yield* _mapSubmitFeedbackToState(event);
} else if (event is UploadImageEvent) {
yield* _mapUploadImageToState(event);
}
FeedbackBloc() : super(new UnFeedbackState()) {
on<GetFeedbackCategoryEvent>(_mapGetFeedbackCategoryToState);
on<SubmitFeedbackEvent>(_mapSubmitFeedbackToState);
on<UploadImageEvent>(_mapUploadImageToState);
}
Stream<FeedbackState> _mapGetFeedbackCategoryToState(
GetFeedbackCategoryEvent event) async* {
yield FeedbackLoading();
// @override
// void mapEventToState(
// FeedbackEvent event,
// ) async {
// if (event is GetFeedbackCategoryEvent) {
// yield* _mapGetFeedbackCategoryToState(event);
// } else if (event is SubmitFeedbackEvent) {
// yield* _mapSubmitFeedbackToState(event);
// } else if (event is UploadImageEvent) {
// yield* _mapUploadImageToState(event);
// }
// }
void _mapGetFeedbackCategoryToState(
GetFeedbackCategoryEvent event, Emitter<FeedbackState> emit) async {
emit(FeedbackLoading());
try {
final List<HelpCategory> categoryList =
await feedbackRepository.getHelpFeedbackCategories(event.uid);
yield FeedbackCategoryState(categoryList);
emit(FeedbackCategoryState(categoryList));
} catch (error) {
print(error);
yield FeedbackLoadError();
emit(FeedbackLoadError());
}
}
Stream<FeedbackState> _mapSubmitFeedbackToState(
SubmitFeedbackEvent event) async* {
yield FeedbackSubmiting();
void _mapSubmitFeedbackToState(
SubmitFeedbackEvent event, Emitter<FeedbackState> emit) async {
emit(FeedbackSubmiting());
try {
// final JsonResult jsonResult =
await feedbackRepository.submitFeedback(event.content, event.imageUrls);
yield FeedbackSubmitSuccess();
emit(FeedbackSubmitSuccess());
} catch (error) {
print(error);
yield FeedbackSubmitError();
emit(FeedbackSubmitError());
}
}
Stream<FeedbackState> _mapUploadImageToState(UploadImageEvent event) async* {
yield ImageUploading();
void _mapUploadImageToState(UploadImageEvent event, Emitter<FeedbackState> emit) async {
emit(ImageUploading());
try {
final String url = await feedbackRepository.upload(event.filePath);
yield UploadImageSuccess(url);
emit(UploadImageSuccess(url));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
}

@ -1,5 +1,4 @@
import 'dart:async';
// import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:bytedesk_kefu/blocs/friend_bloc/bloc.dart';
import 'package:bytedesk_kefu/model/friend.dart';
@ -8,84 +7,90 @@ import 'package:bytedesk_kefu/repositories/friend_repository.dart';
class FriendBloc extends Bloc<FriendEvent, FriendState> {
final FriendRepository friendRepository = new FriendRepository();
FriendBloc() : super(UnFriendState());
@override
Stream<FriendState> mapEventToState(FriendEvent event) async* {
//
if (event is QueryFriendEvent) {
yield* _mapQueryFriendToState(event);
} else if (event is UploadFriendAddressEvent) {
yield* _mapUploadFriendAddressToState(event);
} else if (event is QueryFriendAddressEvent) {
yield* _mapQueryFriendAddressToState(event);
} else if (event is QueryFriendNearbyEvent) {
yield* _mapQueryFriendNearbyToState(event);
} else if (event is UpdateFriendNearbyEvent) {
yield* _mapUpdateFriendNearbyToState(event);
}
FriendBloc() : super(UnFriendState()) {
on<QueryFriendEvent>(_mapQueryFriendToState);
on<QueryFriendAddressEvent>(_mapQueryFriendAddressToState);
on<UploadFriendAddressEvent>(_mapUploadFriendAddressToState);
on<QueryFriendNearbyEvent>(_mapQueryFriendNearbyToState);
on<UpdateFriendNearbyEvent>(_mapUpdateFriendNearbyToState);
}
Stream<FriendState> _mapQueryFriendToState(QueryFriendEvent event) async* {
yield FriendLoading();
// @override
// void mapEventToState(FriendEvent event) async {
// //
// if (event is QueryFriendEvent) {
// yield* _mapQueryFriendToState(event);
// } else if (event is UploadFriendAddressEvent) {
// yield* _mapUploadFriendAddressToState(event);
// } else if (event is QueryFriendAddressEvent) {
// yield* _mapQueryFriendAddressToState(event);
// } else if (event is QueryFriendNearbyEvent) {
// yield* _mapQueryFriendNearbyToState(event);
// } else if (event is UpdateFriendNearbyEvent) {
// yield* _mapUpdateFriendNearbyToState(event);
// }
// }
void _mapQueryFriendToState(QueryFriendEvent event, Emitter<FriendState> emit) async {
emit(FriendLoading());
try {
final List<Friend> friendList =
await friendRepository.getFriends(event.page, event.size);
yield FriendLoadSuccess(friendList);
emit(FriendLoadSuccess(friendList));
} catch (error) {
print(error);
yield ErrorFriendState('friend error');
emit(ErrorFriendState('friend error'));
}
}
Stream<FriendState> _mapQueryFriendAddressToState(
QueryFriendAddressEvent event) async* {
yield FriendLoading();
void _mapQueryFriendAddressToState(
QueryFriendAddressEvent event, Emitter<FriendState> emit) async {
emit(FriendLoading());
try {
final List<Friend> friendList =
await friendRepository.getFriendsAddress(event.page, event.size);
yield FriendLoadSuccess(friendList);
emit(FriendLoadSuccess(friendList));
} catch (error) {
print(error);
yield ErrorFriendState('friend error');
emit(ErrorFriendState('friend error'));
}
}
Stream<FriendState> _mapUploadFriendAddressToState(
UploadFriendAddressEvent event) async* {
yield FriendLoading();
void _mapUploadFriendAddressToState(
UploadFriendAddressEvent event, Emitter<FriendState> emit) async {
emit(FriendLoading());
try {
final Friend friend =
await friendRepository.uploadAddress(event.nickname, event.mobile);
yield FriendCreateSuccess(friend: friend);
emit(FriendCreateSuccess(friend: friend));
} catch (error) {
print(error);
yield ErrorFriendState('friend error');
emit(ErrorFriendState('friend error'));
}
}
Stream<FriendState> _mapQueryFriendNearbyToState(
QueryFriendNearbyEvent event) async* {
yield FriendLoading();
void _mapQueryFriendNearbyToState(
QueryFriendNearbyEvent event, Emitter<FriendState> emit) async {
emit(FriendLoading());
try {
final List<Friend> friendList =
await friendRepository.getFriendsNearby(event.page, event.size);
yield FriendLoadSuccess(friendList);
emit(FriendLoadSuccess(friendList));
} catch (error) {
print(error);
yield ErrorFriendState('friend error');
emit(ErrorFriendState('friend error'));
}
}
Stream<FriendState> _mapUpdateFriendNearbyToState(
UpdateFriendNearbyEvent event) async* {
yield FriendLoading();
void _mapUpdateFriendNearbyToState(
UpdateFriendNearbyEvent event, Emitter<FriendState> emit) async {
emit(FriendLoading());
try {
await friendRepository.updateLocation(event.latitude, event.longtitude);
yield FriendUpdateSuccess();
emit(FriendUpdateSuccess());
} catch (error) {
print(error);
yield ErrorFriendState('friend error');
emit(ErrorFriendState('friend error'));
}
}
}

@ -1,14 +1,17 @@
import 'dart:async';
// import 'dart:async';
import 'package:bloc/bloc.dart';
import './bloc.dart';
class GroupBloc extends Bloc<GroupEvent, GroupState> {
GroupBloc() : super(InitialGroupState());
@override
Stream<GroupState> mapEventToState(
GroupEvent event,
) async* {
// TODO: Add Logic
GroupBloc() : super(InitialGroupState()) {
}
// @override
// Stream<GroupState> mapEventToState(
// GroupEvent event,
// ) async* {
// // TODO: Add Logic
// }
}

@ -9,39 +9,43 @@ class HelpBloc extends Bloc<HelpEvent, HelpState> {
//
final HelpRepository helpRepository = new HelpRepository();
HelpBloc() : super(new UnHelpState());
@override
Stream<HelpState> mapEventToState(HelpEvent event) async* {
if (event is GetHelpCategoryEvent) {
yield* _mapGetHelpCategoryToState(event);
} else if (event is GetHelpArticleEvent) {
yield* _mapGetHelpArticleState(event);
}
HelpBloc() : super(new UnHelpState()) {
on<GetHelpCategoryEvent>(_mapGetHelpCategoryToState);
on<GetHelpArticleEvent>(_mapGetHelpArticleState);
}
Stream<HelpState> _mapGetHelpCategoryToState(
GetHelpCategoryEvent event) async* {
yield HelpLoading();
// @override
// Stream<HelpState> mapEventToState(HelpEvent event) async* {
// if (event is GetHelpCategoryEvent) {
// yield* _mapGetHelpCategoryToState(event);
// } else if (event is GetHelpArticleEvent) {
// yield* _mapGetHelpArticleState(event);
// }
// }
void _mapGetHelpCategoryToState(
GetHelpCategoryEvent event, Emitter<HelpState> emit) async {
emit(HelpLoading());
try {
final List<HelpCategory> categoryList =
await helpRepository.getHelpCategories(event.uid);
yield HelpCategoryState(categoryList);
emit(HelpCategoryState(categoryList));
} catch (error) {
print(error);
yield HelpLoadError();
emit(HelpLoadError());
}
}
Stream<HelpState> _mapGetHelpArticleState(GetHelpArticleEvent event) async* {
yield HelpLoading();
void _mapGetHelpArticleState(
GetHelpArticleEvent event, Emitter<HelpState> emit) async {
emit(HelpLoading());
try {
final List<HelpArticle> categoryList =
await helpRepository.getCategoryArticles(event.categoryId);
yield HelpArticleState(categoryList);
emit(HelpArticleState(categoryList));
} catch (error) {
print(error);
yield HelpLoadError();
emit(HelpLoadError());
}
}
}

@ -7,56 +7,43 @@ class LeaveMsgBloc extends Bloc<LeaveMsgEvent, LeaveMsgState> {
//
final LeaveMsgRepository leaveMsgRepository = new LeaveMsgRepository();
LeaveMsgBloc() : super(new UnLeaveMsgState());
@override
Stream<LeaveMsgState> mapEventToState(
LeaveMsgEvent event,
) async* {
// if (event is GetLeaveMsgCategoryEvent) {
// yield* _mapGetLeaveMsgCategoryToState(event);
// } else
if (event is SubmitLeaveMsgEvent) {
yield* _mapSubmitLeaveMsgToState(event);
} else if (event is UploadImageEvent) {
yield* _mapUploadImageToState(event);
}
LeaveMsgBloc() : super(new UnLeaveMsgState()) {
on<SubmitLeaveMsgEvent>(_mapSubmitLeaveMsgToState);
on<UploadImageEvent>(_mapUploadImageToState);
}
// Stream<LeaveMsgState> _mapGetLeaveMsgCategoryToState(
// GetLeaveMsgCategoryEvent event) async* {
// yield LeaveMsgLoading();
// try {
// final List<HelpCategory> categoryList =
// await leaveMsgRepository.getHelpLeaveMsgCategories(event.uid);
// yield LeaveMsgCategoryState(categoryList);
// } catch (error) {
// print(error);
// yield LeaveMsgLoadError();
// @override
// Stream<LeaveMsgState> mapEventToState(
// LeaveMsgEvent event,
// ) async* {
// if (event is SubmitLeaveMsgEvent) {
// yield* _mapSubmitLeaveMsgToState(event);
// } else if (event is UploadImageEvent) {
// yield* _mapUploadImageToState(event);
// }
// }
Stream<LeaveMsgState> _mapSubmitLeaveMsgToState(
SubmitLeaveMsgEvent event) async* {
yield LeaveMsgSubmiting();
void _mapSubmitLeaveMsgToState(
SubmitLeaveMsgEvent event, Emitter<LeaveMsgState> emit) async {
emit(LeaveMsgSubmiting());
try {
// final JsonResult jsonResult =
await leaveMsgRepository.submitLeaveMsg(event.content, event.imageUrls);
yield LeaveMsgSubmitSuccessState();
emit(LeaveMsgSubmitSuccessState());
} catch (error) {
print(error);
yield LeaveMsgSubmitError();
emit(LeaveMsgSubmitError());
}
}
Stream<LeaveMsgState> _mapUploadImageToState(UploadImageEvent event) async* {
yield ImageUploading();
void _mapUploadImageToState(UploadImageEvent event, Emitter<LeaveMsgState> emit) async {
emit(ImageUploading());
try {
final String url = await leaveMsgRepository.upload(event.filePath);
yield UploadImageSuccess(url);
emit(UploadImageSuccess(url));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
}

@ -1,4 +1,4 @@
import 'dart:async';
// import 'dart:async';
import 'package:bytedesk_kefu/model/codeResult.dart';
import 'package:bytedesk_kefu/model/jsonResult.dart';
import 'package:bytedesk_kefu/model/oauth.dart';
@ -10,172 +10,179 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
//
final UserRepository _userRepository = new UserRepository();
LoginBloc() : super(LoginInitial());
@override
Stream<LoginState> mapEventToState(LoginEvent event) async* {
//
if (event is LoginButtonPressed) {
yield* _mapLoginState(event);
} else if (event is SMSLoginButtonPressed) {
yield* _mapSMSLoginState(event);
} else if (event is RegisterButtonPressed) {
yield* _mapRegisterState(event);
} else if (event is RequestCodeButtonPressed) {
yield* _mapRequestCodeState(event);
} else if (event is BindMobileEvent) {
yield* _mapBindMobileState(event);
} else if (event is UnionidOAuthEvent) {
yield* _mapUnionidOAuthState(event);
} else if (event is ResetPasswordButtonPressed) {
yield* _mapResetPasswordState(event);
} else if (event is UpdatePasswordButtonPressed) {
yield* _mapUpdatePasswordState(event);
}
LoginBloc() : super(LoginInitial()) {
on<LoginButtonPressed>(_mapLoginState);
on<SMSLoginButtonPressed>(_mapSMSLoginState);
on<RegisterButtonPressed>(_mapRegisterState);
on<RequestCodeButtonPressed>(_mapRequestCodeState);
on<BindMobileEvent>(_mapBindMobileState);
on<UnionidOAuthEvent>(_mapUnionidOAuthState);
on<ResetPasswordButtonPressed>(_mapResetPasswordState);
on<UpdatePasswordButtonPressed>(_mapUpdatePasswordState);
}
Stream<LoginState> _mapLoginState(LoginButtonPressed event) async* {
yield LoginInProgress();
// @override
// void mapEventToState(LoginEvent event, Emitter<LoginState> emit) async {
// //
// if (event is LoginButtonPressed) {
// yield* _mapLoginState(event);
// } else if (event is SMSLoginButtonPressed) {
// yield* _mapSMSLoginState(event);
// } else if (event is RegisterButtonPressed) {
// yield* _mapRegisterState(event);
// } else if (event is RequestCodeButtonPressed) {
// yield* _mapRequestCodeState(event);
// } else if (event is BindMobileEvent) {
// yield* _mapBindMobileState(event);
// } else if (event is UnionidOAuthEvent) {
// yield* _mapUnionidOAuthState(event);
// } else if (event is ResetPasswordButtonPressed) {
// yield* _mapResetPasswordState(event);
// } else if (event is UpdatePasswordButtonPressed) {
// yield* _mapUpdatePasswordState(event);
// }
// }
void _mapLoginState(LoginButtonPressed event, Emitter<LoginState> emit) async {
emit(LoginInProgress());
try {
OAuth oauth = await _userRepository.login(event.username, event.password);
if (oauth.statusCode == 200) {
//
yield LoginSuccess();
emit(LoginSuccess());
} else {
//
yield LoginError();
emit(LoginError());
}
} catch (error) {
//
yield LoginFailure(error: error.toString());
emit(LoginFailure(error: error.toString()));
}
}
Stream<LoginState> _mapSMSLoginState(SMSLoginButtonPressed event) async* {
yield LoginInProgress();
void _mapSMSLoginState(SMSLoginButtonPressed event, Emitter<LoginState> emit) async {
emit(LoginInProgress());
try {
//
OAuth oauth = await _userRepository.smsOAuth(event.mobile, event.code);
if (oauth.statusCode == 200) {
//
yield SMSLoginSuccess();
emit(SMSLoginSuccess());
} else {
//
yield LoginError();
emit(LoginError());
}
} catch (error) {
//
yield LoginFailure(error: error.toString());
emit(LoginFailure(error: error.toString()));
}
}
Stream<LoginState> _mapRegisterState(RegisterButtonPressed event) async* {
yield RegisterInProgress();
void _mapRegisterState(RegisterButtonPressed event, Emitter<LoginState> emit) async {
emit(RegisterInProgress());
try {
//
JsonResult jsonResult =
await _userRepository.register(event.mobile, event.password);
if (jsonResult.statusCode == 200) {
yield RegisterSuccess();
emit(RegisterSuccess());
} else {
yield RegisterError(
message: jsonResult.message, statusCode: jsonResult.statusCode);
emit(RegisterError(
message: jsonResult.message, statusCode: jsonResult.statusCode));
}
} catch (error) {
//
yield LoginFailure(error: error.toString());
emit(LoginFailure(error: error.toString()));
}
}
Stream<LoginState> _mapRequestCodeState(
RequestCodeButtonPressed event) async* {
yield RequestCodeInProgress();
void _mapRequestCodeState(RequestCodeButtonPressed event, Emitter<LoginState> emit) async {
emit(RequestCodeInProgress());
try {
//
CodeResult codeResult = await _userRepository.requestCode(event.mobile);
if (codeResult.statusCode == 200) {
yield RequestCodeSuccess(codeResult: codeResult);
emit(RequestCodeSuccess(codeResult: codeResult));
} else {
yield RequestCodeError(
message: codeResult.message, statusCode: codeResult.statusCode);
emit(RequestCodeError(
message: codeResult.message, statusCode: codeResult.statusCode));
}
} catch (error) {
//
yield LoginFailure(error: error.toString());
emit(LoginFailure(error: error.toString()));
}
}
Stream<LoginState> _mapBindMobileState(BindMobileEvent event) async* {
yield BindMobileInProgress();
void _mapBindMobileState(BindMobileEvent event, Emitter<LoginState> emit) async {
emit(BindMobileInProgress());
try {
//
JsonResult jsonResult = await _userRepository.bindMobile(event.mobile);
if (jsonResult.statusCode == 200) {
yield BindMobileSuccess(jsonResult: jsonResult);
emit(BindMobileSuccess(jsonResult: jsonResult));
} else {
yield BindMobileError(
message: jsonResult.message, statusCode: jsonResult.statusCode);
emit(BindMobileError(
message: jsonResult.message, statusCode: jsonResult.statusCode));
}
} catch (error) {
//
yield LoginFailure(error: error.toString());
emit(LoginFailure(error: error.toString()));
}
}
Stream<LoginState> _mapUnionidOAuthState(UnionidOAuthEvent event) async* {
yield UnionidOAuthInProgress();
void _mapUnionidOAuthState(UnionidOAuthEvent event, Emitter<LoginState> emit) async {
emit(UnionidOAuthInProgress());
try {
//
OAuth oauth = await _userRepository.unionIdOAuth(event.unionid);
if (oauth.statusCode == 200) {
//
yield UnionidLoginSuccess();
emit(UnionidLoginSuccess());
} else {
//
yield LoginError();
emit(LoginError());
}
} catch (error) {
//
yield LoginFailure(error: error.toString());
emit(LoginFailure(error: error.toString()));
}
}
Stream<LoginState> _mapResetPasswordState(
ResetPasswordButtonPressed event) async* {
yield ResetPasswordInProgress();
void _mapResetPasswordState(ResetPasswordButtonPressed event, Emitter<LoginState> emit) async {
emit(ResetPasswordInProgress());
try {
//
JsonResult jsonResult =
await _userRepository.changePassword(event.mobile, event.password);
if (jsonResult.statusCode == 200) {
yield ResetPasswordSuccess();
emit(ResetPasswordSuccess());
} else {
yield ResetPasswordError(
message: jsonResult.message, statusCode: jsonResult.statusCode);
emit(ResetPasswordError(
message: jsonResult.message, statusCode: jsonResult.statusCode));
}
} catch (error) {
//
yield LoginFailure(error: error.toString());
emit(LoginFailure(error: error.toString()));
}
}
Stream<LoginState> _mapUpdatePasswordState(
UpdatePasswordButtonPressed event) async* {
void _mapUpdatePasswordState(UpdatePasswordButtonPressed event, Emitter<LoginState> emit) async {
//
yield UpdatePasswordInProgress();
emit(UpdatePasswordInProgress());
try {
//
JsonResult jsonResult =
await _userRepository.changePassword(event.mobile, event.password);
if (jsonResult.statusCode == 200) {
yield UpdatePasswordSuccess();
emit(UpdatePasswordSuccess());
} else {
yield UpdatePasswordError(
message: jsonResult.message, statusCode: jsonResult.statusCode);
emit(UpdatePasswordError(
message: jsonResult.message, statusCode: jsonResult.statusCode));
}
} catch (error) {
//
yield LoginFailure(error: error.toString());
emit(LoginFailure(error: error.toString()));
}
}
}

@ -1,4 +1,4 @@
import 'dart:async';
// import 'dart:async';
import 'package:bytedesk_kefu/model/jsonResult.dart';
import 'package:bytedesk_kefu/model/message.dart';
import 'package:bytedesk_kefu/model/requestAnswer.dart';
@ -11,154 +11,160 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
//
final MessageRepository messageRepository = new MessageRepository();
MessageBloc() : super(InitialMessageState());
MessageBloc() : super(InitialMessageState()) {
on<ReceiveMessageEvent>(_mapRefreshCourseToState);
on<UploadImageEvent>(_mapUploadImageToState);
on<UploadVideoEvent>(_mapUploadVideoToState);
on<SendMessageRestEvent>(_mapSendMessageRestToState);
on<LoadHistoryMessageEvent>(_mapLoadHistoryMessageToState);
on<LoadTopicMessageEvent>(_mapLoadTopicMessageToState);
@override
Stream<MessageState> mapEventToState(MessageEvent event) async* {
if (event is ReceiveMessageEvent) {
yield* _mapRefreshCourseToState(event);
} else if (event is UploadImageEvent) {
yield* _mapUploadImageToState(event);
} else if (event is UploadVideoEvent) {
yield* _mapUploadVideoToState(event);
} else if (event is QueryAnswerEvent) {
yield* _mapQueryAnswerToState(event);
} else if (event is MessageAnswerEvent) {
yield* _mapMessageAnswerToState(event);
} else if (event is RateAnswerEvent) {
yield* _mapRateAnswerToState(event);
} else if (event is LoadHistoryMessageEvent) {
yield* _mapLoadHistoryMessageToState(event);
} else if (event is LoadTopicMessageEvent) {
yield* _mapLoadTopicMessageToState(event);
} else if (event is LoadChannelMessageEvent) {
yield* _mapLoadChannelMessageToState(event);
} else if (event is SendMessageRestEvent) {
yield* _mapSendMessageRestToState(event);
}
on<LoadChannelMessageEvent>(_mapLoadChannelMessageToState);
on<QueryAnswerEvent>(_mapQueryAnswerToState);
on<MessageAnswerEvent>(_mapMessageAnswerToState);
on<RateAnswerEvent>(_mapRateAnswerToState);
}
Stream<MessageState> _mapRefreshCourseToState(
ReceiveMessageEvent event) async* {
// @override
// void mapEventToState(MessageEvent event, Emitter<MessageState> emit) async {
// if (event is ReceiveMessageEvent) {
// yield* _mapRefreshCourseToState(event);
// } else if (event is UploadImageEvent) {
// yield* _mapUploadImageToState(event);
// } else if (event is UploadVideoEvent) {
// yield* _mapUploadVideoToState(event);
// } else if (event is QueryAnswerEvent) {
// yield* _mapQueryAnswerToState(event);
// } else if (event is MessageAnswerEvent) {
// yield* _mapMessageAnswerToState(event);
// } else if (event is RateAnswerEvent) {
// yield* _mapRateAnswerToState(event);
// } else if (event is LoadHistoryMessageEvent) {
// yield* _mapLoadHistoryMessageToState(event);
// } else if (event is LoadTopicMessageEvent) {
// yield* _mapLoadTopicMessageToState(event);
// } else if (event is LoadChannelMessageEvent) {
// yield* _mapLoadChannelMessageToState(event);
// } else if (event is SendMessageRestEvent) {
// yield* _mapSendMessageRestToState(event);
// }
// }
void _mapRefreshCourseToState(ReceiveMessageEvent event, Emitter<MessageState> emit) async {
try {
yield ReceiveMessageState(message: event.message);
emit(ReceiveMessageState(message: event.message));
} catch (error) {
print(error);
}
}
Stream<MessageState> _mapUploadImageToState(UploadImageEvent event) async* {
yield MessageUpLoading();
void _mapUploadImageToState(UploadImageEvent event, Emitter<MessageState> emit) async {
emit(MessageUpLoading());
try {
final UploadJsonResult uploadJsonResult =
await messageRepository.uploadImage(event.filePath);
yield UploadImageSuccess(uploadJsonResult);
emit(UploadImageSuccess(uploadJsonResult));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<MessageState> _mapUploadVideoToState(UploadVideoEvent event) async* {
yield MessageUpLoading();
void _mapUploadVideoToState(UploadVideoEvent event, Emitter<MessageState> emit) async {
emit(MessageUpLoading());
try {
final UploadJsonResult uploadJsonResult =
await messageRepository.uploadVideo(event.filePath);
yield UploadVideoSuccess(uploadJsonResult);
emit(UploadVideoSuccess(uploadJsonResult));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<MessageState> _mapSendMessageRestToState(
SendMessageRestEvent event) async* {
yield RestMessageSending();
void _mapSendMessageRestToState(SendMessageRestEvent event, Emitter<MessageState> emit) async {
emit(RestMessageSending());
try {
final JsonResult jsonResult =
await messageRepository.sendMessageRest(event.json);
yield SendMessageRestSuccess(jsonResult);
emit(SendMessageRestSuccess(jsonResult));
} catch (error) {
print(error);
yield SendMessageRestError();
emit(SendMessageRestError());
}
}
Stream<MessageState> _mapLoadHistoryMessageToState(
LoadHistoryMessageEvent event) async* {
yield MessageLoading();
void _mapLoadHistoryMessageToState(LoadHistoryMessageEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading());
try {
final List<Message> messageList = await messageRepository
.loadHistoryMessages(event.uid, event.page, event.size);
yield LoadHistoryMessageSuccess(messageList: messageList);
emit(LoadHistoryMessageSuccess(messageList: messageList));
} catch (error) {
print(error);
yield LoadHistoryMessageError();
emit(LoadHistoryMessageError());
}
}
Stream<MessageState> _mapLoadTopicMessageToState(
LoadTopicMessageEvent event) async* {
yield MessageLoading();
void _mapLoadTopicMessageToState(LoadTopicMessageEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading());
try {
final List<Message> messageList = await messageRepository
.loadTopicMessages(event.topic, event.page, event.size);
yield LoadTopicMessageSuccess(messageList: messageList);
emit(LoadTopicMessageSuccess(messageList: messageList));
} catch (error) {
print(error);
yield LoadTopicMessageError();
emit(LoadTopicMessageError());
}
}
Stream<MessageState> _mapLoadChannelMessageToState(
LoadChannelMessageEvent event) async* {
yield MessageLoading();
void _mapLoadChannelMessageToState(LoadChannelMessageEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading());
try {
final List<Message> messageList = await messageRepository
.loadChannelMessages(event.cid, event.page, event.size);
yield LoadChannelMessageSuccess(messageList: messageList);
emit(LoadChannelMessageSuccess(messageList: messageList));
} catch (error) {
print(error);
yield LoadChannelMessageError();
emit(LoadChannelMessageError());
}
}
Stream<MessageState> _mapQueryAnswerToState(QueryAnswerEvent event) async* {
yield MessageLoading();
void _mapQueryAnswerToState(QueryAnswerEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading());
try {
final RequestAnswerResult requestAnswerResult =
await messageRepository.queryAnswer(event.tid, event.aid);
yield QueryAnswerSuccess(
query: requestAnswerResult.query, answer: requestAnswerResult.anwser);
emit(QueryAnswerSuccess(
query: requestAnswerResult.query, answer: requestAnswerResult.anwser));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<MessageState> _mapMessageAnswerToState(
MessageAnswerEvent event) async* {
yield MessageLoading();
void _mapMessageAnswerToState(MessageAnswerEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading());
try {
final RequestAnswerResult requestAnswerResult = await messageRepository
.messageAnswer(event.type, event.wid, event.aid, event.content);
yield MessageAnswerSuccess(
query: requestAnswerResult.query, answer: requestAnswerResult.anwser);
emit(MessageAnswerSuccess(
query: requestAnswerResult.query, answer: requestAnswerResult.anwser));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<MessageState> _mapRateAnswerToState(RateAnswerEvent event) async* {
yield MessageLoading();
void _mapRateAnswerToState(RateAnswerEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading());
try {
final RequestAnswerResult requestAnswerResult =
await messageRepository.rateAnswer(event.aid, event.mid, event.rate);
yield RateAnswerSuccess(result: requestAnswerResult.anwser);
emit(RateAnswerSuccess(result: requestAnswerResult.anwser));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
}

@ -9,172 +9,184 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
//
final UserRepository userRepository = new UserRepository();
ProfileBloc() : super(InitialProfileState());
ProfileBloc() : super(InitialProfileState()) {
on<GetProfileEvent>(_mapProfileState);
on<UploadImageEvent>(_mapUploadImageToState);
on<UpdateAvatarEvent>(_mapUpdateAvatarToState);
on<UpdateNicknameEvent>(_mapUpdateNicknameToState);
on<UpdateDescriptionEvent>(_mapUpdateDescriptionToState);
on<UpdateMobileEvent>(_mapUpdateMobileToState);
@override
Stream<ProfileState> mapEventToState(ProfileEvent event) async* {
//
if (event is GetProfileEvent) {
yield* _mapProfileState();
} else if (event is UploadImageEvent) {
yield* _mapUploadImageToState(event);
} else if (event is UpdateAvatarEvent) {
yield* _mapUpdateAvatarToState(event);
} else if (event is UpdateNicknameEvent) {
yield* _mapUpdateNicknameToState(event);
} else if (event is UpdateDescriptionEvent) {
yield* _mapUpdateDescriptionToState(event);
} else if (event is UpdateMobileEvent) {
yield* _mapUpdateMobileToState(event);
} else if (event is UpdateSexEvent) {
yield* _mapUpdateSexToState(event);
} else if (event is UpdateLocationEvent) {
yield* _mapUpdateLocationToState(event);
} else if (event is UpdateBirthdayEvent) {
yield* _mapUpdateBirthdayToState(event);
} else if (event is QueryFollowEvent) {
yield* _mapQueryFollowToState(event);
} else if (event is UserFollowEvent) {
yield* _mapUserFollowToState(event);
} else if (event is UserUnfollowEvent) {
yield* _mapUserUnfollowToState(event);
}
}
Stream<ProfileState> _mapProfileState() async* {
yield ProfileInProgress();
on<UpdateSexEvent>(_mapUpdateSexToState);
on<UpdateLocationEvent>(_mapUpdateLocationToState);
on<UpdateBirthdayEvent>(_mapUpdateBirthdayToState);
on<QueryFollowEvent>(_mapQueryFollowToState);
on<UserFollowEvent>(_mapUserFollowToState);
on<UserUnfollowEvent>(_mapUserUnfollowToState);
}
// @override
// void mapEventToState(ProfileEvent event, Emitter<ProfileState> emit) async {
// //
// if (event is GetProfileEvent) {
// yield* _mapProfileState();
// } else if (event is UploadImageEvent) {
// yield* _mapUploadImageToState(event);
// } else if (event is UpdateAvatarEvent) {
// yield* _mapUpdateAvatarToState(event);
// } else if (event is UpdateNicknameEvent) {
// yield* _mapUpdateNicknameToState(event);
// } else if (event is UpdateDescriptionEvent) {
// yield* _mapUpdateDescriptionToState(event);
// } else if (event is UpdateMobileEvent) {
// yield* _mapUpdateMobileToState(event);
// } else if (event is UpdateSexEvent) {
// yield* _mapUpdateSexToState(event);
// } else if (event is UpdateLocationEvent) {
// yield* _mapUpdateLocationToState(event);
// } else if (event is UpdateBirthdayEvent) {
// yield* _mapUpdateBirthdayToState(event);
// } else if (event is QueryFollowEvent) {
// yield* _mapQueryFollowToState(event);
// } else if (event is UserFollowEvent) {
// yield* _mapUserFollowToState(event);
// } else if (event is UserUnfollowEvent) {
// yield* _mapUserUnfollowToState(event);
// }
// }
void _mapProfileState(GetProfileEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress());
try {
User user = await userRepository.getProfile();
yield ProfileSuccess(user: user);
emit(ProfileSuccess(user: user));
} catch (error) {
//
yield ProfileFailure(error: error.toString());
emit(ProfileFailure(error: error.toString()));
}
}
Stream<ProfileState> _mapUploadImageToState(UploadImageEvent event) async* {
yield ProfileInProgress();
void _mapUploadImageToState(UploadImageEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress());
try {
final String url = await userRepository.upload(event.filePath);
yield UploadImageSuccess(url);
emit(UploadImageSuccess(url));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<ProfileState> _mapUpdateAvatarToState(UpdateAvatarEvent event) async* {
yield ProfileInProgress();
void _mapUpdateAvatarToState(UpdateAvatarEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress());
try {
final User user = await userRepository.updateAvatar(event.avatar);
yield UpdateAvatarSuccess(user);
emit(UpdateAvatarSuccess(user));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<ProfileState> _mapUpdateNicknameToState(
UpdateNicknameEvent event) async* {
yield ProfileInProgress();
void _mapUpdateNicknameToState(UpdateNicknameEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress());
try {
final User user = await userRepository.updateNickname(event.nickname);
yield UpdateNicknameSuccess(user);
emit(UpdateNicknameSuccess(user));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<ProfileState> _mapUpdateDescriptionToState(
UpdateDescriptionEvent event) async* {
yield ProfileInProgress();
void _mapUpdateDescriptionToState(UpdateDescriptionEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress());
try {
final User user =
await userRepository.updateDescription(event.description);
yield UpdateDescriptionSuccess(user);
emit(UpdateDescriptionSuccess(user));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<ProfileState> _mapUpdateMobileToState(UpdateMobileEvent event) async* {
yield ProfileInProgress();
void _mapUpdateMobileToState(UpdateMobileEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress());
try {
final User user = await userRepository.updateMobile(event.mobile);
yield UpdateMobileSuccess(user);
emit(UpdateMobileSuccess(user));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<ProfileState> _mapUpdateSexToState(UpdateSexEvent event) async* {
yield ProfileInProgress();
void _mapUpdateSexToState(UpdateSexEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress());
try {
final User user = await userRepository.updateSex(event.sex);
yield UpdateSexSuccess(user);
emit(UpdateSexSuccess(user));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<ProfileState> _mapUpdateLocationToState(
UpdateLocationEvent event) async* {
yield ProfileInProgress();
void _mapUpdateLocationToState(UpdateLocationEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress());
try {
final User user = await userRepository.updateLocation(event.location);
yield UpdateLocationSuccess(user);
emit(UpdateLocationSuccess(user));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<ProfileState> _mapUpdateBirthdayToState(
UpdateBirthdayEvent event) async* {
yield ProfileInProgress();
void _mapUpdateBirthdayToState(UpdateBirthdayEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress());
try {
final User user = await userRepository.updateBirthday(event.birthday);
yield UpdateBirthdaySuccess(user);
emit(UpdateBirthdaySuccess(user));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
Stream<ProfileState> _mapQueryFollowToState(QueryFollowEvent event) async* {
yield QueryFollowing();
void _mapQueryFollowToState(QueryFollowEvent event, Emitter<ProfileState> emit) async {
emit(QueryFollowing());
try {
final bool isFollowed = await userRepository.isFollowed(event.uid);
yield QueryFollowSuccess(isFollowed);
emit(QueryFollowSuccess(isFollowed));
} catch (error) {
print(error);
yield QueryFollowError();
emit(QueryFollowError());
}
}
Stream<ProfileState> _mapUserFollowToState(UserFollowEvent event) async* {
yield Following();
void _mapUserFollowToState(UserFollowEvent event, Emitter<ProfileState> emit) async {
emit(Following());
try {
final JsonResult jsonResult = await userRepository.follow(event.uid);
yield FollowResultSuccess(jsonResult);
emit(FollowResultSuccess(jsonResult));
} catch (error) {
print(error);
yield FollowError();
emit(FollowError());
}
}
Stream<ProfileState> _mapUserUnfollowToState(UserUnfollowEvent event) async* {
yield Following();
void _mapUserUnfollowToState(UserUnfollowEvent event, Emitter<ProfileState> emit) async {
emit(Following());
try {
final JsonResult jsonResult = await userRepository.unfollow(event.uid);
yield UnfollowResultSuccess(jsonResult);
emit(UnfollowResultSuccess(jsonResult));
} catch (error) {
print(error);
yield UnFollowError();
emit(UnFollowError());
}
}
}

@ -1,4 +1,4 @@
import 'dart:async';
// import 'dart:async';
import 'package:bytedesk_kefu/model/markThread.dart';
import 'package:bloc/bloc.dart';
import './bloc.dart';
@ -9,234 +9,219 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
//
final ThreadRepository threadRepository = new ThreadRepository();
ThreadBloc() : super(ThreadEmpty());
// ThreadBloc() : super(ThreadEmpty());
@override
Stream<ThreadState> mapEventToState(ThreadEvent event) async* {
//
if (event is InitThreadEvent) {
yield InitialThreadState();
} else if (event is RefreshThreadEvent) {
yield* _mapRefreshThreadToState(event);
} else if (event is RefreshHistoryThreadEvent) {
yield* _mapRefreshHistoryThreadToState(event);
} else if (event is RefreshVisitorThreadEvent) {
yield* _mapRefreshVisitorThreadToState(event);
} else if (event is RefreshVisitorThreadAllEvent) {
yield* _mapRefreshVisitorThreadAllToState(event);
} else if (event is RequestThreadEvent) {
yield* _mapRequestThreadToState(event);
} else if (event is RequestAgentEvent) {
yield* _mapRequestAgentToState(event);
} else if (event is RequestContactThreadEvent) {
yield* _mapRequestContactThreadToState(event);
} else if (event is RequestGroupThreadEvent) {
yield* _mapRequestGroupThreadToState(event);
} else if (event is MarkTopThreadEvent) {
yield* _mapMarkTopThreadEventToState(event);
} else if (event is UnMarkTopThreadEvent) {
yield* _mapUnMarkTopThreadEventToState(event);
} else if (event is MarkNodisturbThreadEvent) {
yield* _mapMarkNodisturbThreadEventToState(event);
} else if (event is UnMarkNodisturbThreadEvent) {
yield* _mapUnMarkNodisturbThreadEventToState(event);
} else if (event is MarkUnreadThreadEvent) {
yield* _mapMarkUnreadThreadEventToState(event);
} else if (event is UnMarkUnreadThreadEvent) {
yield* _mapUnMarkUnreadThreadEventToState(event);
} else if (event is DeleteThreadEvent) {
yield* _mapDeleteThreadEventToState(event);
}
}
Stream<ThreadState> _mapRefreshThreadToState(
RefreshThreadEvent event) async* {
yield ThreadLoading();
ThreadBloc() : super(ThreadEmpty()) {
// on<InitThreadEvent>(InitialThreadState);
on<RefreshThreadEvent>(_mapRefreshThreadToState);
on<RefreshHistoryThreadEvent>(_mapRefreshHistoryThreadToState);
on<RefreshVisitorThreadEvent>(_mapRefreshVisitorThreadToState);
on<RefreshVisitorThreadAllEvent>(_mapRefreshVisitorThreadAllToState);
on<RequestThreadEvent>(_mapRequestThreadToState);
on<RequestAgentEvent>(_mapRequestAgentToState);
on<RequestContactThreadEvent>(_mapRequestContactThreadToState);
on<RequestGroupThreadEvent>(_mapRequestGroupThreadToState);
on<MarkTopThreadEvent>(_mapMarkTopThreadEventToState);
on<UnMarkTopThreadEvent>(_mapUnMarkTopThreadEventToState);
on<MarkNodisturbThreadEvent>(_mapMarkNodisturbThreadEventToState);
on<UnMarkNodisturbThreadEvent>(_mapUnMarkNodisturbThreadEventToState);
on<MarkUnreadThreadEvent>(_mapMarkUnreadThreadEventToState);
on<UnMarkUnreadThreadEvent>(_mapUnMarkUnreadThreadEventToState);
on<DeleteThreadEvent>(_mapDeleteThreadEventToState);
}
void _mapRefreshThreadToState(
RefreshThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final List<Thread> threadList = await threadRepository.getThreads();
yield ThreadLoadSuccess(threadList);
emit(ThreadLoadSuccess(threadList));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapRefreshHistoryThreadToState(
RefreshHistoryThreadEvent event) async* {
yield ThreadHistoryLoading();
void _mapRefreshHistoryThreadToState(
RefreshHistoryThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadHistoryLoading());
try {
final List<Thread> threadList =
await threadRepository.getHistoryThreads(event.page, event.size);
yield ThreadLoadSuccess(threadList);
emit(ThreadLoadSuccess(threadList));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapRefreshVisitorThreadToState(
RefreshVisitorThreadEvent event) async* {
yield ThreadVisitorLoading();
void _mapRefreshVisitorThreadToState(
RefreshVisitorThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadVisitorLoading());
try {
final List<Thread> threadList =
await threadRepository.getVisitorThreads(event.page, event.size);
yield ThreadLoadSuccess(threadList);
emit(ThreadLoadSuccess(threadList));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapRefreshVisitorThreadAllToState(
RefreshVisitorThreadAllEvent event) async* {
yield ThreadLoading();
void _mapRefreshVisitorThreadAllToState(
RefreshVisitorThreadAllEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final List<Thread> threadList =
await threadRepository.getVisitorThreadsAll();
yield ThreadLoadSuccess(threadList);
emit(ThreadLoadSuccess(threadList));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapRequestThreadToState(
RequestThreadEvent event) async* {
yield RequestThreading();
void _mapRequestThreadToState(
RequestThreadEvent event, Emitter<ThreadState> emit) async {
print('RequestThreadEvent');
emit(RequestThreading());
try {
final RequestThreadResult thread = await threadRepository.requestThread(
event.wid, event.type, event.aid);
yield RequestThreadSuccess(thread);
emit(RequestThreadSuccess(thread));
} catch (error) {
print(error);
yield RequestThreadError();
emit(RequestThreadError());
}
}
Stream<ThreadState> _mapRequestAgentToState(RequestAgentEvent event) async* {
yield RequestAgentThreading();
void _mapRequestAgentToState(
RequestAgentEvent event, Emitter<ThreadState> emit) async {
emit(RequestAgentThreading());
try {
final RequestThreadResult thread =
await threadRepository.requestAgent(event.wid, event.type, event.aid);
yield RequestAgentSuccess(thread);
emit(RequestAgentSuccess(thread));
} catch (error) {
print(error);
yield RequestAgentThreadError();
emit(RequestAgentThreadError());
}
}
Stream<ThreadState> _mapRequestContactThreadToState(
RequestContactThreadEvent event) async* {
yield ThreadLoading();
void _mapRequestContactThreadToState(
RequestContactThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final RequestThreadResult thread =
await threadRepository.requestContactThread(event.cid);
yield RequestContactThreadSuccess(thread);
emit(RequestContactThreadSuccess(thread));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapRequestGroupThreadToState(
RequestGroupThreadEvent event) async* {
yield ThreadLoading();
void _mapRequestGroupThreadToState(
RequestGroupThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final RequestThreadResult thread =
await threadRepository.requestGroupThread(event.gid);
yield RequestGroupThreadSuccess(thread);
emit(RequestGroupThreadSuccess(thread));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapMarkTopThreadEventToState(
MarkTopThreadEvent event) async* {
yield ThreadLoading();
void _mapMarkTopThreadEventToState(
MarkTopThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final MarkThreadResult thread = await threadRepository.markTop(event.tid);
yield MarkTopThreadSuccess(thread);
emit(MarkTopThreadSuccess(thread));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapUnMarkTopThreadEventToState(
UnMarkTopThreadEvent event) async* {
yield ThreadLoading();
void _mapUnMarkTopThreadEventToState(
UnMarkTopThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final MarkThreadResult thread =
await threadRepository.unmarkTop(event.tid);
yield UnMarkTopThreadSuccess(thread);
emit(UnMarkTopThreadSuccess(thread));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapMarkNodisturbThreadEventToState(
MarkNodisturbThreadEvent event) async* {
yield ThreadLoading();
void _mapMarkNodisturbThreadEventToState(
MarkNodisturbThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final MarkThreadResult thread =
await threadRepository.markNodisturb(event.tid);
yield MarkNodisturbThreadSuccess(thread);
emit(MarkNodisturbThreadSuccess(thread));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapUnMarkNodisturbThreadEventToState(
UnMarkNodisturbThreadEvent event) async* {
yield ThreadLoading();
void _mapUnMarkNodisturbThreadEventToState(
UnMarkNodisturbThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final MarkThreadResult thread =
await threadRepository.unmarkNodisturb(event.tid);
yield UnMarkNodisturbThreadSuccess(thread);
emit(UnMarkNodisturbThreadSuccess(thread));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapMarkUnreadThreadEventToState(
MarkUnreadThreadEvent event) async* {
yield ThreadLoading();
void _mapMarkUnreadThreadEventToState(
MarkUnreadThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final MarkThreadResult thread =
await threadRepository.markUnread(event.tid);
yield MarkUnreadThreadSuccess(thread);
emit(MarkUnreadThreadSuccess(thread));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapUnMarkUnreadThreadEventToState(
UnMarkUnreadThreadEvent event) async* {
yield ThreadLoading();
void _mapUnMarkUnreadThreadEventToState(
UnMarkUnreadThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final MarkThreadResult thread =
await threadRepository.unmarkUnread(event.tid);
yield UnMarkUnreadThreadSuccess(thread);
emit(UnMarkUnreadThreadSuccess(thread));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
Stream<ThreadState> _mapDeleteThreadEventToState(
DeleteThreadEvent event) async* {
yield ThreadLoading();
void _mapDeleteThreadEventToState(
DeleteThreadEvent event, Emitter<ThreadState> emit) async {
emit(ThreadLoading());
try {
final MarkThreadResult thread = await threadRepository.delete(event.tid);
yield DeleteThreadSuccess(thread);
emit(DeleteThreadSuccess(thread));
} catch (error) {
print(error);
yield ThreadLoadError();
emit(ThreadLoadError());
}
}
}

@ -9,7 +9,7 @@ abstract class ThreadEvent extends Equatable {
List<Object> get props => [];
}
class InitThreadEvent extends ThreadEvent {}
// class InitThreadEvent extends ThreadEvent {}
class RefreshThreadEvent extends ThreadEvent {}

@ -1,4 +1,4 @@
import 'dart:async';
// import 'dart:async';
import 'package:bytedesk_kefu/blocs/ticket_bloc/bloc.dart';
import 'package:bloc/bloc.dart';
import 'package:bytedesk_kefu/repositories/ticket_repository.dart';
@ -7,54 +7,57 @@ class TicketBloc extends Bloc<TicketEvent, TicketState> {
//
final TicketRepository feedbackRepository = new TicketRepository();
TicketBloc() : super(new UnTicketState());
@override
Stream<TicketState> mapEventToState(
TicketEvent event,
) async* {
if (event is GetTicketCategoryEvent) {
yield* _mapGetTicketCategoryToState(event);
} else if (event is SubmitTicketEvent) {
yield* _mapSubmitTicketToState(event);
} else if (event is UploadImageEvent) {
yield* _mapUploadImageToState(event);
}
TicketBloc() : super(new UnTicketState()) {
on<GetTicketCategoryEvent>(_mapGetTicketCategoryToState);
on<SubmitTicketEvent>(_mapSubmitTicketToState);
on<UploadImageEvent>(_mapUploadImageToState);
}
Stream<TicketState> _mapGetTicketCategoryToState(
GetTicketCategoryEvent event) async* {
yield TicketLoading();
// @override
// void mapEventToState(
// TicketEvent event,
// ) async* {
// if (event is GetTicketCategoryEvent) {
// yield* _mapGetTicketCategoryToState(event);
// } else if (event is SubmitTicketEvent) {
// yield* _mapSubmitTicketToState(event);
// } else if (event is UploadImageEvent) {
// yield* _mapUploadImageToState(event);
// }
// }
void _mapGetTicketCategoryToState(GetTicketCategoryEvent event, Emitter<TicketState> emit) async {
emit(TicketLoading());
try {
// final List<HelpCategory> categoryList =
// await feedbackRepository.getHelpTicketCategories();
// yield TicketCategoryState(categoryList);
// emit(TicketCategoryState(categoryList);
} catch (error) {
print(error);
yield TicketLoadError();
emit(TicketLoadError());
}
}
Stream<TicketState> _mapSubmitTicketToState(SubmitTicketEvent event) async* {
yield TicketLoading();
void _mapSubmitTicketToState(SubmitTicketEvent event, Emitter<TicketState> emit) async {
emit(TicketLoading());
try {
// final List<HelpCategory> categoryList =
// await feedbackRepository.getHelpTicketCategories();
// yield TicketCategoryState(categoryList);
// emit(TicketCategoryState(categoryList);
} catch (error) {
print(error);
yield TicketLoadError();
emit(TicketLoadError());
}
}
Stream<TicketState> _mapUploadImageToState(UploadImageEvent event) async* {
yield TicketLoading();
void _mapUploadImageToState(UploadImageEvent event, Emitter<TicketState> emit) async {
emit(TicketLoading());
try {
final String url = await feedbackRepository.upload(event.filePath);
yield UploadImageSuccess(url);
emit(UploadImageSuccess(url));
} catch (error) {
print(error);
yield UpLoadImageError();
emit(UpLoadImageError());
}
}
}

@ -54,28 +54,23 @@ class BytedeskKefu {
static void initWithUsernameAndNicknameAndAvatar(String username,
String nickname, String avatar, String appKey, String subDomain) async {
// anonymousLogin(appKey, subDomain);
/// sp
await SpUtil.getInstance();
//
String? spusername = SpUtil.getString(BytedeskConstants.username);
if (spusername!.isEmpty) {
// ,
String? sppassword = SpUtil.getString(BytedeskConstants.password);
if (spusername!.isNotEmpty) {
//
userLogin(spusername, sppassword!, appKey, subDomain);
} else {
//
//
String password = username;
await BytedeskUserHttpApi()
.registerUser(username, nickname, password, avatar, subDomain);
username = username + "@" + subDomain;
userLogin(username, password, appKey, subDomain);
} else if (spusername == username) {
//
String password = username;
username = username + "@" + subDomain;
userLogin(username, password, appKey, subDomain);
} else {
// TODO: ,
// String password = username;
// username = username + "@" + subDomain;
// userLogin(username, password, appKey, subDomain);
//
String usernameCompose = username + "@" + subDomain;
userLogin(usernameCompose, password, appKey, subDomain);
}
}
@ -128,7 +123,7 @@ class BytedeskKefu {
}
await BytedeskUserHttpApi().oauth(username, password);
//
BytedeskUtils.mqttConnect();
connect();
// if (role == BytedeskConstants.ROLE_ADMIN) {
// // TODO:
// }
@ -141,7 +136,7 @@ class BytedeskKefu {
//
await BytedeskUserHttpApi().unionIdOAuth(unionid);
//
BytedeskUtils.mqttConnect();
connect();
//
await BytedeskDeviceHttpApi().setDeviceInfo();
}
@ -149,7 +144,7 @@ class BytedeskKefu {
//
static void otherOAuth() async {
//
BytedeskUtils.mqttConnect();
connect();
//
await BytedeskDeviceHttpApi().setDeviceInfo();
}
@ -164,6 +159,11 @@ class BytedeskKefu {
return BytedeskUtils.mqttReConnect();
}
//
static void disconnect() {
BytedeskUtils.mqttDisconnect();
}
//
static bool isConnected() {
return BytedeskUtils.isMqttConnected();
@ -489,6 +489,9 @@ class BytedeskKefu {
// 退
static Future<void> logout() {
//
disconnect();
//
return BytedeskUserHttpApi().logout();
}

@ -17,7 +17,6 @@ import 'package:http/http.dart' as http;
class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//
Future<OAuth> oauth(String? username, String? password) async {
// final oauthUrl = '$baseUrl/oauth/token';
var oauthUrl = Uri.http(BytedeskConstants.host, '/oauth/token');
// print("http api client: oauthUrl $oauthUrl");
Map<String, String> headers = {
@ -31,12 +30,13 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
};
final oauthResponse =
await this.httpClient.post(oauthUrl, headers: headers, body: bodyMap);
// print('oauth result: $oauthResponse');
print('oauth result: $oauthResponse');
// check the status code for the result
int statusCode = oauthResponse.statusCode;
// print("statusCode $statusCode");
// 200:
final oauthJson = jsonDecode(oauthResponse.body);
// print('oauthJson:' + oauthJson);
SpUtil.putBool(BytedeskConstants.isLogin, true);
SpUtil.putString(BytedeskConstants.accessToken, oauthJson['access_token']);
//
@ -187,28 +187,35 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
Uri.http(BytedeskConstants.host, '/visitor/api/register/user');
final initResponse =
await this.httpClient.post(initUrl, headers: headers, body: body);
//json
Utf8Decoder utf8decoder = Utf8Decoder(); // fix
//string json
final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes));
// final responseJson = json.decode(initResponse.body);
print("responseJson $responseJson");
// return JsonResult.fromJson(responseJson);
//
int statusCode = responseJson['status_code'];
if (statusCode == 200) {
//
User user = User.fromJson(responseJson['data']);
//
SpUtil.putString(BytedeskConstants.uid, user.uid!);
SpUtil.putString(BytedeskConstants.username, user.username!);
SpUtil.putString(BytedeskConstants.password, password!);
SpUtil.putString(BytedeskConstants.nickname, user.nickname!);
SpUtil.putString(BytedeskConstants.avatar, user.avatar!);
SpUtil.putString(BytedeskConstants.description, user.description!);
SpUtil.putString(BytedeskConstants.subDomain, user.subDomain!);
//
return user;
} else {
//
SpUtil.putString(BytedeskConstants.uid, responseJson['data']);
SpUtil.putString(BytedeskConstants.username, username! + '@' + subDomain!);
SpUtil.putString(BytedeskConstants.password, password!);
SpUtil.putString(BytedeskConstants.nickname, nickname!);
SpUtil.putString(BytedeskConstants.avatar, avatar!);
SpUtil.putString(BytedeskConstants.description, "");
SpUtil.putString(BytedeskConstants.subDomain, subDomain);
}
return new User();
}
@ -240,9 +247,6 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
Future<CodeResult> requestCode(String? mobile) async {
//
Map<String, String> headers = {"Content-Type": "application/json"};
//
// final initUrl =
// '$baseUrl/sms/api/send/liangshibao?mobile=$mobile&client=$client';
final initUrl = Uri.http(BytedeskConstants.host,
'/sms/api/send/liangshibao', {'mobile': mobile, 'client': client});
final initResponse = await this.httpClient.get(initUrl, headers: headers);
@ -263,10 +267,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
Future<JsonResult> bindMobile(String? mobile) async {
//
String? uid = SpUtil.getString(BytedeskConstants.uid);
//
var body = json.encode({"uid": uid, "mobile": mobile, "client": client});
//
// final initUrl = '$baseUrl/api/user/bind/mobile';
final initUrl = Uri.http(BytedeskConstants.host, '/api/user/bind/mobile');
final initResponse =
await this.httpClient.post(initUrl, headers: getHeaders(), body: body);
@ -288,7 +290,6 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
///
Future<User> getProfile() async {
//
// final initUrl = '$baseUrl/api/user/profile?client=$client';
final initUrl = Uri.http(
BytedeskConstants.host, '/api/user/profile/simple', {'client': client});
final initResponse =
@ -317,8 +318,6 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
Future<User> updateNickname(String? nickname) async {
//
var body = json.encode({"nickname": nickname, "client": client});
//
// final initUrl = '$baseUrl/api/user/nickname';
final initUrl = Uri.http(BytedeskConstants.host, '/api/user/nickname');
final initResponse =
await this.httpClient.post(initUrl, headers: getHeaders(), body: body);
@ -774,8 +773,6 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
Map<String, String> headers = {"Content-Type": "application/json"};
var body = json.encode({"client": client});
// final initUrl = '$baseUrl/api/user/logout?access_token=$accessToken';
final initUrl = Uri.http(BytedeskConstants.host, '/api/user/logout',
{'access_token': accessToken});
final initResponse =
@ -784,23 +781,6 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
final responseJson = json.decode(initResponse.body);
print("responseJson $responseJson");
//
// Preference.clearAccessToken();
BytedeskUtils.clearUserCache();
//
// SpUtil.putString(BytedeskConstants.uid, '');
// SpUtil.putString(BytedeskConstants.username, '');
// SpUtil.putString(BytedeskConstants.nickname, '');
// SpUtil.putString(BytedeskConstants.avatar, '');
// SpUtil.putString(BytedeskConstants.description, '');
// SpUtil.putString(BytedeskConstants.subDomain, '');
// SpUtil.putString(BytedeskConstants.role, '');
// //
// SpUtil.putString(BytedeskConstants.unionid, '');
// SpUtil.putString(BytedeskConstants.openid, '');
// //
// SpUtil.putBool(BytedeskConstants.isLogin, false);
// SpUtil.putBool(BytedeskConstants.isAuthenticated, false);
// SpUtil.putString(BytedeskConstants.mobile, '');
// SpUtil.putString(BytedeskConstants.accessToken, '');
}
}

@ -67,7 +67,7 @@ class MessageProvider {
version: 9,
);
// database path:/Users/ningjinpeng/Library/Developer/CoreSimulator/Devices/715CBA02-A602-4DE1-8C57-75A64B53BF03/data/Containers/Data/Application/8F46273D-9492-4C42-A618-4DF3815562BA/Documents/bytedesk-message-v9.db
// print('database path:' + database!.path);
print('database path:' + database!.path);
}
Future<int> insert(Message message) async {

@ -24,7 +24,7 @@ import 'package:bytedesk_kefu/protobuf/thread.pb.dart' as protothread;
// ignore: import_of_legacy_library_into_null_safe
import 'package:bytedesk_kefu/protobuf/user.pb.dart' as protouser;
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
// import 'package:fluttertoast/fluttertoast.dart';
// import 'package:vibration/vibration.dart';
class BytedeskMqtt {
@ -46,13 +46,13 @@ class BytedeskMqtt {
return _singleton;
}
BytedeskMqtt._internal() {
_connect();
}
//
void _connect() async {
//
// _connect();
reconnect();
}
//
// void _connect() async {
// reconnect();
// }
void reconnect() async {
// eventbus广...
@ -60,8 +60,6 @@ class BytedeskMqtt {
.fire(ConnectionEventBus(BytedeskConstants.USER_STATUS_CONNECTING));
//
currentUid = SpUtil.getString(BytedeskConstants.uid);
// String role = SpUtil.getString(BytedeskConstants.role,
// defValue: BytedeskConstants.ROLE_VISITOR);
client = BytedeskUtils.getClient();
clientId = "$currentUid/$client";
@ -81,6 +79,11 @@ class BytedeskMqtt {
MqttServerClient(BytedeskConstants.webSocketWssUrl, clientId!);
mqttClient.useWebSocket = true;
mqttClient.port = 443;
/// You can also supply your own websocket protocol list or disable this feature using the websocketProtocols
/// setter, read the API docs for further details here, the vast majority of brokers will support the client default
/// list so in most cases you can ignore this. Mosquito needs the single default setting.
// mqttClient.websocketProtocols = MqttClientConstants.protocolsSingleDefault;
} else {
mqttClient = MqttServerClient(BytedeskConstants.mqttHost, clientId!);
mqttClient.port = BytedeskConstants.mqttPort;
@ -92,6 +95,7 @@ class BytedeskMqtt {
mqttClient.setProtocolV311();
/// Set logging on if needed, defaults to off
// mqttClient.logging(on: BytedeskConstants.isDebug);
mqttClient.logging(on: false); // BytedeskConstants.isDebug
/// If you intend to use a keep alive value in your connect message that is not the default(60s)
/// you must set it here
@ -111,7 +115,7 @@ class BytedeskMqtt {
/// client identifier, any supplied username/password, the default keepalive interval(60s)
/// and clean session, an example of a specific one below.
final MqttConnectMessage connMess = MqttConnectMessage()
final MqttConnectMessage connMessage = MqttConnectMessage()
.withClientIdentifier(clientId!)
.authenticateAs('username', 'password'); // TODO: auth便
// .keepAliveFor(keepAlivePeriod); // Must agree with the keep alive set above or not set
@ -123,7 +127,7 @@ class BytedeskMqtt {
if (BytedeskConstants.isDebug) {
print('mqttClient connecting....');
}
mqttClient.connectionMessage = connMess;
mqttClient.connectionMessage = connMessage;
/// Connect the client, any errors here are communicated by raising of the appropriate exception. Note
/// in some circumstances the broker will just disconnect us, see the spec about this, we however eill
@ -162,7 +166,7 @@ class BytedeskMqtt {
// print('Published notification:: topic is ${messageBinary.variableHeader.topicName}, with Qos ${messageBinary.header.qos}');
//
protomsg.Message messageProto =
protomsg.Message.fromBuffer(messageBinary.payload.message!);
protomsg.Message.fromBuffer(messageBinary.payload.message);
// FIXME: mid
var mid = messageProto.mid;
if (midList.contains(mid)) {
@ -220,7 +224,8 @@ class BytedeskMqtt {
isSend: uid == currentUid ? 1 : 0,
currentUid: currentUid,
thread: thread,
user: user);
user: user,
client: client);
//
// var autoReply = false;
var sendReceipt = false;
@ -282,10 +287,15 @@ class BytedeskMqtt {
message.content = messageProto.text.content;
break;
}
case BytedeskConstants.MESSAGE_TYPE_NOTIFICATION_QUEUE:
{
message.content = messageProto.text.content;
break;
}
case BytedeskConstants.MESSAGE_TYPE_NOTIFICATION_QUEUE_ACCEPT:
{
// 'joinQueueThread'
message.content = '接入队列会话';
message.content = '接入队列会话'; // TODO:
break;
}
case BytedeskConstants.MESSAGE_TYPE_NOTIFICATION_AGENT_CLOSE:
@ -667,8 +677,7 @@ class BytedeskMqtt {
currentThread, extraParam);
}
void publish(String content, String type, Thread currentThread,
ExtraParam? extraParam) {
void publish(String content, String type, Thread currentThread, ExtraParam? extraParam) {
// if (currentThread == null) {
// print('连接客服失败,请退出页面重新进入。注意: 请在App启动的时候调用init接口');
// Fluttertoast.showToast(msg: '连接客服失败,请退出页面重新进入');
@ -699,7 +708,7 @@ class BytedeskMqtt {
user.avatar = SpUtil.getString(BytedeskConstants.avatar)!;
// msg
protomsg.Message messageProto = new protomsg.Message();
messageProto.mid = BytedeskUuid.generateV4();
messageProto.mid = BytedeskUuid.uuid();
messageProto.type = type;
messageProto.timestamp = BytedeskUtils.formatedDateNow();
messageProto.client = BytedeskUtils.getClient(); //BytedeskConstants.client;
@ -710,7 +719,7 @@ class BytedeskMqtt {
message.mid = messageProto.mid;
message.type = messageProto.type;
message.timestamp = messageProto.timestamp;
// message.client
message.client = messageProto.client;
message.nickname = user.nickname;
message.avatar = user.avatar;
message.topic = thread.topic;

@ -52,8 +52,8 @@ class MqttBrowserWsConnection extends MqttBrowserConnection {
client = WebSocket(uriString, protocols);
client.binaryType = 'arraybuffer';
messageStream = MqttByteBuffer(typed.Uint8Buffer());
var closeEvents;
var errorEvents;
dynamic closeEvents;
dynamic errorEvents;
client.onOpen.listen((e) {
MqttLogger.log('MqttBrowserWsConnection::connect - websocket is open');
closeEvents.cancel();
@ -117,8 +117,8 @@ class MqttBrowserWsConnection extends MqttBrowserConnection {
client = WebSocket(uriString, protocols);
client.binaryType = 'arraybuffer';
messageStream = MqttByteBuffer(typed.Uint8Buffer());
var closeEvents;
var errorEvents;
dynamic closeEvents;
dynamic errorEvents;
client.onOpen.listen((e) {
MqttLogger.log(
'MqttBrowserWsConnection::connectAuto - websocket is open');
@ -181,4 +181,13 @@ class MqttBrowserWsConnection extends MqttBrowserConnection {
client = null;
}
}
/// Stops listening and closes the socket immediately.
@override
void stopListening() {
if (client != null) {
listener?.cancel();
client.close();
}
}
}

@ -49,6 +49,9 @@ abstract class IMqttConnectionHandler {
/// Closes a connection.
void close();
/// Kills all listeners from old connections.
void stopListening();
/// Connects to a message broker
/// The broker server to connect to
/// The port to connect to

@ -21,6 +21,10 @@ class MqttConnectionBase {
@protected
dynamic client;
/// The stream controller as returned when clients listen.
@protected
StreamSubscription? listener;
/// The read wrapper
@protected
ReadWrapper? readWrapper;
@ -75,12 +79,17 @@ class MqttConnectionBase {
void _disconnect() {
if (client != null) {
client.close();
listener?.cancel();
client.destroy();
client.close();
client = null;
}
}
/// Stops listening and closes the socket immediately, must be overridden in
/// connection classes
void stopListening() {}
/// User requested or auto disconnect disconnection
@protected
void disconnect({bool auto = false}) {

@ -184,6 +184,11 @@ abstract class MqttConnectionHandlerBase implements IMqttConnectionHandler {
}
}
@override
void stopListening() {
connection.stopListening();
}
/// Registers for the receipt of messages when they arrive.
@override
void registerForMessage(

@ -16,11 +16,16 @@ typedef PongCallback = void Function();
/// This class implements the keep alive by sending an MqttPingRequest
/// to the broker if a message has not been sent or received
/// within the keep alive period.
/// Optionally a disconnect on no response property can be set to force disconnect the client
/// if the broker does not respond to a ping request for a specified period of time.
class MqttConnectionKeepAlive {
/// Initializes a new instance of the MqttConnectionKeepAlive class.
MqttConnectionKeepAlive(
IMqttConnectionHandler connectionHandler, int keepAliveSeconds) {
MqttConnectionKeepAlive(IMqttConnectionHandler connectionHandler,
events.EventBus? eventBus, int keepAliveSeconds,
[int disconnectOnNoResponsePeriod = 0]) {
_connectionHandler = connectionHandler;
_clientEventBus = eventBus;
this.disconnectOnNoResponsePeriod = disconnectOnNoResponsePeriod * 1000;
keepAlivePeriod = keepAliveSeconds * 1000;
// Register for message handling of ping request and response messages.
connectionHandler.registerForMessage(
@ -31,15 +36,28 @@ class MqttConnectionKeepAlive {
// Start the timer so we do a ping whenever required.
pingTimer = Timer(Duration(milliseconds: keepAlivePeriod), pingRequired);
MqttLogger.log(
'MqttConnectionKeepAlive:: initialised with a keep alive value of $keepAliveSeconds seconds');
'MqttConnectionKeepAlive:: Initialised with a keep alive value of $keepAliveSeconds seconds');
disconnectOnNoResponsePeriod == 0
? MqttLogger.log(
'MqttConnectionKeepAlive:: Disconnect on no ping response is disabled')
: MqttLogger.log(
'MqttConnectionKeepAlive:: Disconnect on no ping response is enabled with a value of $disconnectOnNoResponsePeriod seconds');
}
/// The keep alive period in milliseconds
late int keepAlivePeriod;
/// The period of time to wait if the broker does not respond to a ping request, in milliseconds.
/// If this time period is exceeded the client is forcibly disconnected.
/// The default is 0, which disables this functionality.
int disconnectOnNoResponsePeriod = 0;
/// The timer that manages the ping callbacks.
Timer? pingTimer;
/// Timer that manages the disconnect on no ping response period.
Timer? disconnectTimer;
/// The connection handler
late IMqttConnectionHandler _connectionHandler;
@ -49,6 +67,9 @@ class MqttConnectionKeepAlive {
/// Ping response received callback
PongCallback? pongCallback;
/// The event bus
events.EventBus? _clientEventBus;
/// Pings the message broker if there has been no activity for
/// the specified amount of idle time.
bool pingRequired() {
@ -73,6 +94,30 @@ class MqttConnectionKeepAlive {
MqttLogger.log(
'MqttConnectionKeepAlive::pingRequired - restarting ping timer');
pingTimer = Timer(Duration(milliseconds: keepAlivePeriod), pingRequired);
if (disconnectOnNoResponsePeriod != 0) {
if (disconnectTimer == null) {
MqttLogger.log(
'MqttConnectionKeepAlive::pingRequired - starting disconnect timer');
if (pinged) {
disconnectTimer = Timer(
Duration(milliseconds: disconnectOnNoResponsePeriod),
noPingResponseReceived);
}
} else {
if (disconnectTimer != null && !disconnectTimer!.isActive) {
if (pinged) {
MqttLogger.log(
'MqttConnectionKeepAlive::pingRequired - restarting disconnect timer');
disconnectTimer = Timer(
Duration(milliseconds: disconnectOnNoResponsePeriod),
noPingResponseReceived);
}
} else {
MqttLogger.log(
'MqttConnectionKeepAlive::pingRequired - disconnect timer is active, not restarting');
}
}
}
_shutdownPadlock = false;
return pinged;
}
@ -101,6 +146,8 @@ class MqttConnectionKeepAlive {
if (pongCallback != null) {
pongCallback!();
}
// Cancel the disconnect timer if needed.
disconnectTimer?.cancel();
return true;
}
@ -111,5 +158,27 @@ class MqttConnectionKeepAlive {
void stop() {
MqttLogger.log('MqttConnectionKeepAlive::stop - stopping keep alive');
pingTimer!.cancel();
disconnectTimer?.cancel();
}
/// Handle the disconnect timer timeout
void noPingResponseReceived() {
// Only disconnect if we are connected.
if (_connectionHandler.connectionStatus.state ==
MqttConnectionState.connected) {
MqttLogger.log(
'MqttConnectionKeepAlive::noPingResponseReceived - connected, attempting to disconnect');
if (_clientEventBus != null) {
_clientEventBus!.fire(DisconnectOnNoPingResponse());
MqttLogger.log(
'MqttConnectionKeepAlive::noPingResponseReceived - OK - disconnect event fired');
} else {
MqttLogger.log(
'MqttConnectionKeepAlive::noPingResponseReceived - ERROR - disconnect event not fired, no event handler');
}
} else {
MqttLogger.log(
'MqttConnectionKeepAlive::noPingResponseReceived - not disconnecting, not connected');
}
}
}

@ -36,7 +36,7 @@ class MqttServerConnection extends MqttConnectionBase {
void _startListening() {
MqttLogger.log('MqttServerConnection::_startListening');
try {
client.listen(_onData, onError: onError, onDone: onDone);
listener = client.listen(_onData, onError: onError, onDone: onDone);
} on Exception catch (e) {
print('MqttServerConnection::_startListening - exception raised $e');
}
@ -94,4 +94,14 @@ class MqttServerConnection extends MqttConnectionBase {
final messageBytes = message.read(message.length);
client?.add(messageBytes.toList());
}
/// Stops listening and closes the socket immediately.
@override
void stopListening() {
if (client != null) {
listener?.cancel();
client.destroy();
client.close();
}
}
}

@ -151,7 +151,8 @@ class MqttServerWs2Connection extends MqttServerConnection {
messageStream = MqttByteBuffer(typed.Uint8Buffer());
MqttLogger.log('MqttWs2Connection::connect - start listening');
_startListening();
completer.complete();
completer.complete(MqttClientConnectionStatus()
..state = MqttConnectionState.connected);
}).catchError((dynamic e) {
onError(e);
completer.completeError(e);
@ -242,6 +243,15 @@ class MqttServerWs2Connection extends MqttServerConnection {
return completer.future;
}
/// Stops listening and closes the socket immediately.
@override
void stopListening() {
if (client != null) {
listener?.cancel();
client.close();
}
}
Future<bool> _performWSHandshake(Socket socket, Uri uri) async {
_response = '';
final c = Completer<bool>();

@ -146,4 +146,13 @@ class MqttServerWsConnection extends MqttServerConnection {
client = null;
}
}
/// Stops listening and closes the socket immediately.
@override
void stopListening() {
if (client != null) {
listener?.cancel();
client.close();
}
}
}

@ -20,7 +20,7 @@ class MqttClientTopicFilter {
_subscriptionTopic = SubscriptionTopic(_topic);
_clientUpdates!.listen(_topicIn);
_updates =
StreamController<List<MqttReceivedMessage<MqttMessage>>>.broadcast(
StreamController<List<MqttReceivedMessage<MqttMessage?>>>.broadcast(
sync: true);
}

@ -58,7 +58,7 @@ class MqttPublishMessage extends MqttMessage {
/// Appends data to publish to the end of the current message payload.
MqttPublishMessage publishData(typed.Uint8Buffer data) {
payload.message!.addAll(data);
payload.message.addAll(data);
return this;
}
@ -76,7 +76,7 @@ class MqttPublishMessage extends MqttMessage {
/// Removes the current published data.
MqttPublishMessage clearPublishData() {
payload.message!.clear();
payload.message.clear();
return this;
}

@ -27,7 +27,7 @@ class MqttPublishPayload extends MqttPayload {
MqttPublishVariableHeader? variableHeader;
/// The message that forms the payload of the publish message.
typed.Uint8Buffer? message;
late typed.Uint8Buffer message;
/// Creates a payload from the specified header stream.
@override
@ -48,11 +48,11 @@ class MqttPublishPayload extends MqttPayload {
/// Gets the length of the payload in bytes when written to a stream.
@override
int getWriteLength() => message!.length;
int getWriteLength() => message.length;
@override
String toString() =>
'Payload: {${message!.length} bytes={${bytesToString(message!)}';
'Payload: {${message.length} bytes={${bytesToString(message)}';
/// Converts an array of bytes to a byte string.
static String bytesToString(typed.Uint8Buffer message) {

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save