Commit 2c57de18 authored by shigemi miura's avatar shigemi miura

Chat

parent 883a1faf
...@@ -121,6 +121,9 @@ ...@@ -121,6 +121,9 @@
D5E008762B2ADD5900C4070A /* MenuManualRADARView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E008752B2ADD5900C4070A /* MenuManualRADARView.swift */; }; D5E008762B2ADD5900C4070A /* MenuManualRADARView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E008752B2ADD5900C4070A /* MenuManualRADARView.swift */; };
D5E008782B2B022200C4070A /* MenuAboutAppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E008772B2B022200C4070A /* MenuAboutAppView.swift */; }; D5E008782B2B022200C4070A /* MenuAboutAppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E008772B2B022200C4070A /* MenuAboutAppView.swift */; };
D5E03A672B04484D00D65FCE /* SessionTaskList.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E03A662B04484D00D65FCE /* SessionTaskList.swift */; }; D5E03A672B04484D00D65FCE /* SessionTaskList.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E03A662B04484D00D65FCE /* SessionTaskList.swift */; };
D5FCEF552B478985009A81D0 /* ResChatMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5FCEF542B478985009A81D0 /* ResChatMessage.swift */; };
D5FCEF572B4789A8009A81D0 /* ResAckMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5FCEF562B4789A8009A81D0 /* ResAckMessage.swift */; };
D5FCEF592B4789D2009A81D0 /* ResChatMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5FCEF582B4789D2009A81D0 /* ResChatMode.swift */; };
D6BEB5D3598C619546873CFC /* Pods_Sailassist.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C8118E85BA516EF0E884AA5 /* Pods_Sailassist.framework */; }; D6BEB5D3598C619546873CFC /* Pods_Sailassist.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C8118E85BA516EF0E884AA5 /* Pods_Sailassist.framework */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -281,6 +284,9 @@ ...@@ -281,6 +284,9 @@
D5E008752B2ADD5900C4070A /* MenuManualRADARView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MenuManualRADARView.swift; path = Sailassist/Menu/View/MenuManualRADARView.swift; sourceTree = SOURCE_ROOT; }; D5E008752B2ADD5900C4070A /* MenuManualRADARView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MenuManualRADARView.swift; path = Sailassist/Menu/View/MenuManualRADARView.swift; sourceTree = SOURCE_ROOT; };
D5E008772B2B022200C4070A /* MenuAboutAppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MenuAboutAppView.swift; path = Sailassist/Menu/View/MenuAboutAppView.swift; sourceTree = SOURCE_ROOT; }; D5E008772B2B022200C4070A /* MenuAboutAppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MenuAboutAppView.swift; path = Sailassist/Menu/View/MenuAboutAppView.swift; sourceTree = SOURCE_ROOT; };
D5E03A662B04484D00D65FCE /* SessionTaskList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SessionTaskList.swift; path = Sailassist/ServerSession/SessionTaskList.swift; sourceTree = SOURCE_ROOT; }; D5E03A662B04484D00D65FCE /* SessionTaskList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SessionTaskList.swift; path = Sailassist/ServerSession/SessionTaskList.swift; sourceTree = SOURCE_ROOT; };
D5FCEF542B478985009A81D0 /* ResChatMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ResChatMessage.swift; path = Sailassist/Json/ResChatMessage.swift; sourceTree = SOURCE_ROOT; };
D5FCEF562B4789A8009A81D0 /* ResAckMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ResAckMessage.swift; path = Sailassist/Json/ResAckMessage.swift; sourceTree = SOURCE_ROOT; };
D5FCEF582B4789D2009A81D0 /* ResChatMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ResChatMode.swift; path = Sailassist/Json/ResChatMode.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -742,6 +748,9 @@ ...@@ -742,6 +748,9 @@
D592D5282B0F198100B91A1C /* ReqChatModeMessage.swift */, D592D5282B0F198100B91A1C /* ReqChatModeMessage.swift */,
D59908C52B19EA70000E13DD /* ResPushHistory.swift */, D59908C52B19EA70000E13DD /* ResPushHistory.swift */,
025F99732B2C125900C9A18A /* ResGetManualUrl.swift */, 025F99732B2C125900C9A18A /* ResGetManualUrl.swift */,
D5FCEF542B478985009A81D0 /* ResChatMessage.swift */,
D5FCEF562B4789A8009A81D0 /* ResAckMessage.swift */,
D5FCEF582B4789D2009A81D0 /* ResChatMode.swift */,
); );
path = Json; path = Json;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -964,6 +973,7 @@ ...@@ -964,6 +973,7 @@
02CD06952AE895F5005F8D8F /* APIError.swift in Sources */, 02CD06952AE895F5005F8D8F /* APIError.swift in Sources */,
D5B803282B3B988E003B32AD /* AppVersionModel.swift in Sources */, D5B803282B3B988E003B32AD /* AppVersionModel.swift in Sources */,
D592D5232B0F14FE00B91A1C /* SessionUploadImage.swift in Sources */, D592D5232B0F14FE00B91A1C /* SessionUploadImage.swift in Sources */,
D5FCEF552B478985009A81D0 /* ResChatMessage.swift in Sources */,
022A98202AF8B8960079C55A /* LocationCalculation.swift in Sources */, 022A98202AF8B8960079C55A /* LocationCalculation.swift in Sources */,
D5258CA72B03988600365276 /* ReqTaskList.swift in Sources */, D5258CA72B03988600365276 /* ReqTaskList.swift in Sources */,
D5CB6F9B2B021C4F00EC2010 /* LocationViewModel.swift in Sources */, D5CB6F9B2B021C4F00EC2010 /* LocationViewModel.swift in Sources */,
...@@ -976,6 +986,7 @@ ...@@ -976,6 +986,7 @@
D5AE351D2AEBA6FC00059889 /* SessionLogin.swift in Sources */, D5AE351D2AEBA6FC00059889 /* SessionLogin.swift in Sources */,
D5258C9F2B03527400365276 /* ResGetMessages.swift in Sources */, D5258C9F2B03527400365276 /* ResGetMessages.swift in Sources */,
D55135242B15C3BF007B66B1 /* DeleteEcaArea.swift in Sources */, D55135242B15C3BF007B66B1 /* DeleteEcaArea.swift in Sources */,
D5FCEF592B4789D2009A81D0 /* ResChatMode.swift in Sources */,
024EDE1B2B0C41E40013BAC8 /* MenuSettingView.swift in Sources */, 024EDE1B2B0C41E40013BAC8 /* MenuSettingView.swift in Sources */,
020B98552AD924930029DE4C /* QrCodeScannerView.swift in Sources */, 020B98552AD924930029DE4C /* QrCodeScannerView.swift in Sources */,
02CE4D7F2ADE42A9002E79BC /* MenuContentView.swift in Sources */, 02CE4D7F2ADE42A9002E79BC /* MenuContentView.swift in Sources */,
...@@ -1012,6 +1023,7 @@ ...@@ -1012,6 +1023,7 @@
025C27FE2B0206D700BADC49 /* PDFDownloadManager.swift in Sources */, 025C27FE2B0206D700BADC49 /* PDFDownloadManager.swift in Sources */,
D59908CA2B1AC381000E13DD /* GetPushHistory.swift in Sources */, D59908CA2B1AC381000E13DD /* GetPushHistory.swift in Sources */,
D54D174B2B35137A00A0EAA5 /* LocalWebView.swift in Sources */, D54D174B2B35137A00A0EAA5 /* LocalWebView.swift in Sources */,
D5FCEF572B4789A8009A81D0 /* ResAckMessage.swift in Sources */,
025C27FC2AFE191A00BADC49 /* MenuManualView.swift in Sources */, 025C27FC2AFE191A00BADC49 /* MenuManualView.swift in Sources */,
D58E1F502B142A260092D8FE /* EcaArea.swift in Sources */, D58E1F502B142A260092D8FE /* EcaArea.swift in Sources */,
020B98592AD92A4C0029DE4C /* MainTabView.swift in Sources */, 020B98592AD92A4C0029DE4C /* MainTabView.swift in Sources */,
......
...@@ -26,7 +26,7 @@ struct ChatView: View { ...@@ -26,7 +26,7 @@ struct ChatView: View {
.frame(height: 20) .frame(height: 20)
ForEach(message.messages, id: \.messageId) { msg in ForEach(message.messages, id: \.messageId) { msg in
if msg.fromId != String(SharingData.my.id){ if msg.fromId == String(SharingData.my.id){
//自分のメッセージ //自分のメッセージ
MyChatContentView(message: msg) MyChatContentView(message: msg)
.padding(.bottom, 24) .padding(.bottom, 24)
......
...@@ -12,25 +12,22 @@ class GetMessage { ...@@ -12,25 +12,22 @@ class GetMessage {
func start() { func start() {
print(debug: "called") print(debug: "called")
sessionGetMessage.RequestGetMessage(responseGetMessage) sessionGetMessage.RequestGetMessage { response in
} switch response {
case .success(let resultData):
private func responseGetMessage(result: Result<Data, APIError>) { let serverSession = ServerSession()
print(debug: "called") let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResGetMessages.self)
switch result { if let res = resjson {
case .success(let resultData): SharingData.message.mode = res.mode
let serverSession = ServerSession() SharingData.message.messages = []
let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResGetMessages.self) if let msg = res.messages {
if let res = resjson { SharingData.message.messages = msg
SharingData.message.mode = res.mode }
SharingData.message.messages = []
if let msg = res.messages {
SharingData.message.messages = msg
} }
case .failure(let errorCode):
print(debug: errorCode)
break
} }
case .failure(let errorCode):
print(debug: errorCode)
break
} }
} }
} }
......
...@@ -9,8 +9,10 @@ import SwiftUI ...@@ -9,8 +9,10 @@ import SwiftUI
struct ChatInputView: View { struct ChatInputView: View {
@EnvironmentObject private var sceneDelegate: SceneDelegate @EnvironmentObject private var sceneDelegate: SceneDelegate
@EnvironmentObject var signalRService: SignalRService
@State var inputText = "" @State var inputText = ""
@FocusState var isKeyboard : Bool @FocusState var isKeyboard : Bool
var body: some View { var body: some View {
VStack(spacing: 0){ VStack(spacing: 0){
Spacer() Spacer()
...@@ -31,7 +33,8 @@ struct ChatInputView: View { ...@@ -31,7 +33,8 @@ struct ChatInputView: View {
Button{ Button{
isKeyboard = false isKeyboard = false
signalRService.chatMessage(message: inputText)
inputText = ""
} label: { } label: {
Image("send") Image("send")
.resizable() .resizable()
......
...@@ -12,7 +12,7 @@ struct ReqAckMessage : Codable { ...@@ -12,7 +12,7 @@ struct ReqAckMessage : Codable {
var messageId: String = "" //確認したMessageId var messageId: String = "" //確認したMessageId
var time: String = "" //投稿日時 2023-11-02T05:25:49.4362123Z var time: String = "" //投稿日時 2023-11-02T05:25:49.4362123Z
var location: Int = 0 //1:Shore / 2:Ship var location: Int = 0 //1:Shore / 2:Ship
var fromeId: String = "" //ユーザーID var fromeId: Int = 0 //ユーザーID
init(shipId: Int, messageId: String) { init(shipId: Int, messageId: String) {
self.shipId = shipId self.shipId = shipId
......
...@@ -15,7 +15,7 @@ struct ReqChatModeMessage : Codable { ...@@ -15,7 +15,7 @@ struct ReqChatModeMessage : Codable {
var shipId: Int = 0 var shipId: Int = 0
var time: String = "" //投稿日時 2023-11-02T05:25:49.4362123Z var time: String = "" //投稿日時 2023-11-02T05:25:49.4362123Z
var location: Int = 0 //1:Shore / 2:Ship var location: Int = 0 //1:Shore / 2:Ship
var fromeId: String = "" //ユーザーID var fromeId: Int = 0 //ユーザーID
var mode: Int = 0 //0:通常 / 1:Warning中 var mode: Int = 0 //0:通常 / 1:Warning中
init(shipId: Int) { init(shipId: Int) {
......
...@@ -14,9 +14,9 @@ struct ReqMessage : Codable { ...@@ -14,9 +14,9 @@ struct ReqMessage : Codable {
var time: String = "" //2023-11-02T05:25:49.4362123Z var time: String = "" //2023-11-02T05:25:49.4362123Z
var location: Int = 0 //1:Shore / 2:Ship var location: Int = 0 //1:Shore / 2:Ship
var from: String = "" //投稿者名 var from: String = "" //投稿者名
var fromeId: String = "" //ユーザーID var fromeId: Int = 0 //ユーザーID
var message: String = "" //テキスト var message: String = "" //テキスト
var stampId: Int = 0 //スタンプ番号 0:Fire〜 var stampId: Int? //スタンプ番号 0:Fire〜
init(shipId: Int, messageId: String) { init(shipId: Int, messageId: String) {
self.shipId = shipId self.shipId = shipId
......
//
// ResAckMessage.swift
// Sailassist
//
// Created by 三浦薫巳 on 2024/01/05.
//
import Foundation
struct ResAckMessage: Codable {
var shipId: Int
var messageId: Int //UUID
var time: String //投稿日時
var location: Int //1:Shore、2:Ship
var fromId: Int //ユーザーID
}
//
// ResChatMessage.swift
// Sailassist
//
// Created by 三浦薫巳 on 2024/01/05.
//
import Foundation
struct ResChatMessage: Codable {
var shipId: Int
var messageId: Int //UUID
var type: Int //0:テキスト、1:スタンプ
var time: String //投稿日時
var location: Int //1:Shore、2:Ship
var from: String //投稿者名
var fromId: Int //ユーザーID
var message: String //テキスト
var stampId: Int //スタンプ番号
}
//
// ResChatMode.swift
// Sailassist
//
// Created by 三浦薫巳 on 2024/01/05.
//
import Foundation
struct ResChatMode: Codable {
var shipId: Int
var time: String //投稿日時
var location: Int //1:Shore、2:Ship
var fromId: Int //ユーザーID
var mode: Int //0:通常、1:Warning中
}
...@@ -10,16 +10,17 @@ import Foundation ...@@ -10,16 +10,17 @@ import Foundation
struct ResGetMessages: Codable { struct ResGetMessages: Codable {
var mode: Int // 0:通常 , 1:Warning中 var mode: Int // 0:通常 , 1:Warning中
var messages: [ChatMessage]? var messages: [ChatMessage]?
var users: [ChatUser]?
} }
struct ChatMessage: Codable { struct ChatMessage: Codable {
var shipId: UInt var shipId: Int
var messageId: String //各メッセージ固有ID var messageId: String //各メッセージ固有ID
var type: Int //0:テキスト , 1:スタンプ , 2:画像 var type: Int //0:テキスト , 1:スタンプ , 2:画像
var time: String //投稿日時 var time: String //投稿日時
var location: Int //1:Shore , 2:Ship var location: Int //1:Shore , 2:Ship
var from: String //投稿者名 var from: String //投稿者名
var fromId: String //ユーザーID var fromId: String? //ユーザーID
var message: String //テキスト時:テキスト , 画像時:サムネイルのUri var message: String //テキスト時:テキスト , 画像時:サムネイルのUri
var stampId: Int //スタンプ番号 0:Fire~ var stampId: Int //スタンプ番号 0:Fire~
var viewer: [Viewer] //閲覧者情報 var viewer: [Viewer] //閲覧者情報
...@@ -30,3 +31,10 @@ struct Viewer: Codable { ...@@ -30,3 +31,10 @@ struct Viewer: Codable {
var location: Int //1:Shore , 2:Ship var location: Int //1:Shore , 2:Ship
var id: String //ユーザーID var id: String //ユーザーID
} }
struct ChatUser: Codable {
var time: String //最終アクセス日時
var location: Int //1:Shore , 2:Ship
var id: String //ログイン時のデバイスID
var name: String //ユーザー名
}
...@@ -13,7 +13,6 @@ class GetManualUrl { ...@@ -13,7 +13,6 @@ class GetManualUrl {
func start() { func start() {
print(debug: "called") print(debug: "called")
sessionGetManualUrl.getManualUrl { response in sessionGetManualUrl.getManualUrl { response in
print(debug: "called")
switch response { switch response {
case .success(let resultData): case .success(let resultData):
print(debug: String(data: resultData, encoding: .utf8) as Any) print(debug: String(data: resultData, encoding: .utf8) as Any)
......
...@@ -53,6 +53,7 @@ struct SailassistApp: App { ...@@ -53,6 +53,7 @@ struct SailassistApp: App {
} else { } else {
ContentView() ContentView()
.environmentObject(locationViewModel) .environmentObject(locationViewModel)
.environmentObject(signalRService)
} }
} }
} }
...@@ -67,8 +68,8 @@ class NotificationTags: NSObject { ...@@ -67,8 +68,8 @@ class NotificationTags: NSObject {
let bamTag = "bam-" + shipId let bamTag = "bam-" + shipId
let taskAlertTag = "taskalert-" + shipId let taskAlertTag = "taskalert-" + shipId
let sailassistTag = "sailassist-" + shipId let sailassistTag = "sailassist-" + shipId
// let chatTag = "chat-" + shipId let chatTag = "chat-" + shipId
MSNotificationHub.addTags([routeTag, bamTag, taskAlertTag, sailassistTag]) MSNotificationHub.addTags([routeTag, bamTag, taskAlertTag, sailassistTag, chatTag])
} }
} }
} }
...@@ -120,8 +121,8 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M ...@@ -120,8 +121,8 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M
// Push通知を受信した時(サイレントプッシュ) // Push通知を受信した時(サイレントプッシュ)
func notificationHub(_ notificationHub: MSNotificationHub, didReceivePushNotification notification: MSNotificationHubMessage) { func notificationHub(_ notificationHub: MSNotificationHub, didReceivePushNotification notification: MSNotificationHubMessage) {
// let title = notification.title ?? "" // let title = notification.title ?? ""
// let body = notification.body ?? "" // let body = notification.body ?? ""
let userInfo = notification.userInfo let userInfo = notification.userInfo
print(debug: "called \(String(describing: userInfo))") print(debug: "called \(String(describing: userInfo))")
......
...@@ -74,50 +74,7 @@ class SharingData{ ...@@ -74,50 +74,7 @@ class SharingData{
static var message = Message() static var message = Message()
class Message: ObservableObject { class Message: ObservableObject {
@Published var mode: Int = 0 // 0:通常 , 1:Warning中 @Published var mode: Int = 0 // 0:通常 , 1:Warning中
@Published var messages: [ChatMessage] = [ @Published var messages: [ChatMessage] = []
ChatMessage(
shipId: 10000003,
messageId: "92c2dfb5-f5ed-4943-98a3-9848d7f9a962",
type: 0,
time: "2023-10-06T01:51:01.872Z",
location: 1,
from: "はだだ",
fromId: "487420489",
message: "999",
stampId: 0,
viewer: [
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 1,
id: ""),
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 2,
id: "")
]
),
ChatMessage(
shipId: 10000001,
messageId: "92c2dfb5-f5ed-4943-98a3-a848d7f9a962",
type: 0,
time: "2023-10-06T01:51:01.872Z",
location: 1,
from: "はだだ",
fromId: "487420489",
message: "999",
stampId: 0,
viewer: [
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 1,
id: ""),
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 2,
id: "")
]
),
]
} }
/** /**
......
...@@ -8,42 +8,44 @@ ...@@ -8,42 +8,44 @@
import Foundation import Foundation
import SwiftSignalRClient import SwiftSignalRClient
public class SignalRService { class SignalRService: ObservableObject{
private var connection: HubConnection private var connection: HubConnection
private var hubConnectionDelegate: HubConnectionDelegate? private var hubConnectionDelegate: HubConnectionDelegate?
public init() { public init() {
// hubConnectionDelegate = ChatHubConnectionDelegate(app: self) // hubConnectionDelegate = ChatHubConnectionDelegate(controller: self)
hubConnectionDelegate = ChatHubConnectionDelegate() hubConnectionDelegate = ChatHubConnectionDelegate()
connection = HubConnectionBuilder(url: URL(string : HttpRequestType.SignalR.rawValue)!) connection = HubConnectionBuilder(url: URL(string : HttpRequestType.SignalR.rawValue)!)
.withHubConnectionDelegate(delegate: hubConnectionDelegate!) .withHubConnectionDelegate(delegate: hubConnectionDelegate!)
.withAutoReconnect() .withAutoReconnect()
.withLogging(minLogLevel: .error).build() .withLogging(minLogLevel: .error)
.withHubConnectionOptions(configureHubConnectionOptions: {options in options.keepAliveInterval = 20 })
.build()
connection.on(method: "chatMessage", callback: { (shipId: Int, messageId: Int, type: Int, time: String, location: Int, from: String, fromeId: Int, message: String) in connection.on(method: "chatMessage", callback: { (message: ResChatMessage) in
self.handleChatMessage(message, from: from) self.handleChatMessage(message: message)
}) })
connection.on(method: "ackMessage", callback: { (shipId: Int, time: String, location: Int, fromId: Int, mode: Int) in connection.on(method: "ackMessage", callback: { (message: ResAckMessage) in
self.handleAckMessage(time) self.handleAckMessage(message: message)
}) })
connection.on(method: "chatMode", callback: { (shipId: Int, time: String, location: Int, fromId: String, mode: Int) in connection.on(method: "chatMode", callback: { (message: ResChatMode) in
self.handleChatMessage(fromId) self.handleChatMessage(message: message)
}) })
connection.start() connection.start()
} }
private func handleChatMessage(_ message: String, from user: String) { private func handleChatMessage(message: ResChatMessage) {
print(debug: "called") print(debug: "called")
} }
private func handleAckMessage(_ time: String) { private func handleAckMessage(message: ResAckMessage) {
print(debug: "called") print(debug: "called")
} }
private func handleChatMessage(_ fromId: String) { private func handleChatMessage(message: ResChatMode) {
print(debug: "called") print(debug: "called")
} }
...@@ -52,18 +54,18 @@ public class SignalRService { ...@@ -52,18 +54,18 @@ public class SignalRService {
} }
//呼び出す //呼び出す
func chatMessage(_ message: String) { func chatMessage(message: String) {
var request = ReqMessage(shipId: Preferences.shipId, messageId: "aaaa") var request = ReqMessage(shipId: Preferences.shipId, messageId: UUID().uuidString)
request.type = 0 //0:テキスト, 1:スタンプ request.type = 0 //0:テキスト, 1:スタンプ
// request.time = DateTextLib.Date2ISO8601Text(date: Date()) request.time = DateTextLib.Date2ISO8601Text(Date())
request.location = 2 //1:Shore , 2:Ship request.location = 2 //1:Shore , 2:Ship
request.from = Preferences.UserName //投稿者名 request.from = Preferences.UserName //投稿者名
// request.fromeId = SharingData.my.shipName //ユーザーID request.fromeId = SharingData.my.id //ユーザーID
request.message = message //テキスト request.message = message //テキスト
// request.stampId = //スタンプ番号 0:Fire~ // request.stampId = //スタンプ番号 0:Fire~
if message != "" { if message != "" {
connection.invoke(method: "ChatMessage", message) { error in connection.invoke(method: "chatMessage", request) { error in
if let e = error { if let e = error {
print(debug: "Error:\(e)") print(debug: "Error:\(e)")
} }
...@@ -71,13 +73,13 @@ public class SignalRService { ...@@ -71,13 +73,13 @@ public class SignalRService {
} }
} }
func ackMessage(_ message: String) { func ackMessage(messageId: String) {
var request = ReqAckMessage(shipId: Preferences.shipId, messageId: "aaaa") var request = ReqAckMessage(shipId: Preferences.shipId, messageId: messageId)
//request.time = DateTextLib.Date2ISO8601Text(date: Date()) request.time = DateTextLib.Date2ISO8601Text(Date())
request.location = 2 //1:Shore , 2:Ship request.location = 2 //1:Shore , 2:Ship
// request.fromeId = SharingData.my.shipName //ユーザーID request.fromeId = SharingData.my.id //ユーザーID
if message != "" { if messageId != "" {
connection.invoke(method: "AckMessage", request) { error in connection.invoke(method: "ackMessage", request) { error in
if let e = error { if let e = error {
print(debug: "Error:\(e)") print(debug: "Error:\(e)")
} }
...@@ -85,17 +87,15 @@ public class SignalRService { ...@@ -85,17 +87,15 @@ public class SignalRService {
} }
} }
func chatMode(_ message: String) { func chatMode() {
var request = ReqChatModeMessage(shipId: Preferences.shipId) var request = ReqChatModeMessage(shipId: Preferences.shipId)
// request.time = DateTextLib.Date2ISO8601Text(date: Date()) request.time = DateTextLib.Date2ISO8601Text(Date())
request.location = 2 //1:Shore , 2:Ship request.location = 2 //1:Shore , 2:Ship
// request.fromeId = SharingData.my.shipName //ユーザーID request.fromeId = SharingData.my.id //ユーザーID
request.mode = 0 //0:通常 / 1:Warning中 request.mode = 0 //0:通常 / 1:Warning中
if message != "" { connection.invoke(method: "chatMode", request) { error in
connection.invoke(method: "ChatMode", message) { error in if let e = error {
if let e = error { print(debug: "Error:\(e)")
print(debug: "Error:\(e)")
}
} }
} }
} }
...@@ -110,20 +110,22 @@ public class SignalRService { ...@@ -110,20 +110,22 @@ public class SignalRService {
} }
class ChatHubConnectionDelegate: HubConnectionDelegate { class ChatHubConnectionDelegate: HubConnectionDelegate {
// weak var app: AppDelegate? // weak var app: SignalRService?
// //
// init(app: AppDelegate) { // init(app: SignalRService) {
// self.app = app // self.app = app
// } // }
//接続が正常に開始されたときに発生
func connectionDidOpen(hubConnection: HubConnection) { func connectionDidOpen(hubConnection: HubConnection) {
print("connectionDidOpen") print("connectionDidOpen")
// After connection established call registerUserInServer method // After connection established call registerUserInServer method
DispatchQueue.main.async { DispatchQueue.main.async {
// self.registerUserInServer() // self.registerUserInServer()
} }
} }
//接続を正常に開始できなかったときに発生
func connectionDidFailToOpen(error: Error) { func connectionDidFailToOpen(error: Error) {
print("connectionDidFailToOpen") print("connectionDidFailToOpen")
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment