You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by xi...@apache.org on 2018/12/17 09:10:17 UTC

[incubator-weex] branch master updated: [iOS] Add WebSocket' implementation in playground's project. (#1920)

This is an automated email from the ASF dual-hosted git repository.

xifang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new 9a8ee88  [iOS] Add WebSocket' implementation in playground's project. (#1920)
9a8ee88 is described below

commit 9a8ee88c3a5c6fcd2d08a9661eaac7bfbfe4ec1e
Author: Douma Fang <do...@gmail.com>
AuthorDate: Mon Dec 17 17:10:11 2018 +0800

    [iOS] Add WebSocket' implementation in playground's project. (#1920)
    
    Note, you need change your code to http://dotwe.org/vue/a235218427ab3a2a918c3fe16ec19b51.
    
    You need change
    
    websocket.onmessage = (e)=>{
              this.onmessage = e.data;
            };
    
    to code like this
    
    websocket.onmessage((e) => {
              this.onmessage = e.data;
            });
---
 ios/playground/WeexDemo.xcodeproj/project.pbxproj  |  56 +++++++++-
 ios/playground/WeexDemo/AppDelegate.m              |   2 +
 .../WeexDemo/Websocket/SRWebSocket+Weex.h          |  29 +++++
 .../WeexDemo/Websocket/SRWebSocket+Weex.m          |  47 ++++++++
 .../WeexDemo/Websocket/WXWebSocketDefaultImpl.h    |  25 +++++
 .../WeexDemo/Websocket/WXWebSocketDefaultImpl.m    | 120 +++++++++++++++++++++
 6 files changed, 277 insertions(+), 2 deletions(-)

diff --git a/ios/playground/WeexDemo.xcodeproj/project.pbxproj b/ios/playground/WeexDemo.xcodeproj/project.pbxproj
index 0b33d60..1dd2b43 100644
--- a/ios/playground/WeexDemo.xcodeproj/project.pbxproj
+++ b/ios/playground/WeexDemo.xcodeproj/project.pbxproj
@@ -11,6 +11,8 @@
 		17036A5A20FDF9DF0029AE3D /* WXApmImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 17036A5920FDF9DF0029AE3D /* WXApmImpl.m */; };
 		17C1DB57206B675D000E0CEB /* DebugAnzlyzer.m in Sources */ = {isa = PBXBuildFile; fileRef = 17C1DB56206B675D000E0CEB /* DebugAnzlyzer.m */; };
 		2AE88A2C1C8544E6003329DE /* WXScannerVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 2AE88A2B1C8544E6003329DE /* WXScannerVC.m */; };
+		3375BEE821C74C5C003CAAB8 /* WXWebSocketDefaultImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 3375BEE521C74C5C003CAAB8 /* WXWebSocketDefaultImpl.m */; };
+		3375BEE921C74C5C003CAAB8 /* SRWebSocket+Weex.m in Sources */ = {isa = PBXBuildFile; fileRef = 3375BEE721C74C5C003CAAB8 /* SRWebSocket+Weex.m */; };
 		564B94671DD9C65000441C8D /* WeexUITestDemo-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 564B94661DD9C65000441C8D /* WeexUITestDemo-Info.plist */; };
 		59EA0DA71D2E7D19004F904A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 59EA0DA61D2E7D19004F904A /* Images.xcassets */; };
 		7478481E1E0CD4910044500D /* WXSyncTestModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 7478481D1E0CD4910044500D /* WXSyncTestModule.m */; };
@@ -80,6 +82,10 @@
 		22E4D2883CC56188A2CA9C13 /* Pods-WeexDemo.uitest.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WeexDemo.uitest.xcconfig"; path = "Pods/Target Support Files/Pods-WeexDemo/Pods-WeexDemo.uitest.xcconfig"; sourceTree = "<group>"; };
 		2AE88A2A1C8544E6003329DE /* WXScannerVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WXScannerVC.h; path = Scanner/WXScannerVC.h; sourceTree = "<group>"; };
 		2AE88A2B1C8544E6003329DE /* WXScannerVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WXScannerVC.m; path = Scanner/WXScannerVC.m; sourceTree = "<group>"; };
+		3375BEE421C74C5C003CAAB8 /* SRWebSocket+Weex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SRWebSocket+Weex.h"; sourceTree = "<group>"; };
+		3375BEE521C74C5C003CAAB8 /* WXWebSocketDefaultImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXWebSocketDefaultImpl.m; sourceTree = "<group>"; };
+		3375BEE621C74C5C003CAAB8 /* WXWebSocketDefaultImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXWebSocketDefaultImpl.h; sourceTree = "<group>"; };
+		3375BEE721C74C5C003CAAB8 /* SRWebSocket+Weex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SRWebSocket+Weex.m"; sourceTree = "<group>"; };
 		564B94661DD9C65000441C8D /* WeexUITestDemo-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "WeexUITestDemo-Info.plist"; sourceTree = "<group>"; };
 		59EA0DA61D2E7D19004F904A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
 		5AF8846546DAC65CAC038806 /* Pods-WeexDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WeexDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WeexDemo/Pods-WeexDemo.debug.xcconfig"; sourceTree = "<group>"; };
@@ -193,6 +199,17 @@
 			name = Frameworks;
 			sourceTree = "<group>";
 		};
+		3375BEE321C74C5C003CAAB8 /* Websocket */ = {
+			isa = PBXGroup;
+			children = (
+				3375BEE421C74C5C003CAAB8 /* SRWebSocket+Weex.h */,
+				3375BEE521C74C5C003CAAB8 /* WXWebSocketDefaultImpl.m */,
+				3375BEE621C74C5C003CAAB8 /* WXWebSocketDefaultImpl.h */,
+				3375BEE721C74C5C003CAAB8 /* SRWebSocket+Weex.m */,
+			);
+			path = Websocket;
+			sourceTree = "<group>";
+		};
 		74CC79EC1C2B9FC600829368 /* Demo */ = {
 			isa = PBXGroup;
 			children = (
@@ -338,6 +355,7 @@
 		DCABAFF71D0296E8001C8592 /* handler */ = {
 			isa = PBXGroup;
 			children = (
+				3375BEE321C74C5C003CAAB8 /* Websocket */,
 				DC15A3CF200E30FC009C8977 /* WXNavigationHandlerImpl.h */,
 				DC15A3CE200E30FC009C8977 /* WXNavigationHandlerImpl.m */,
 				DC20B8E41ECADA2500845F39 /* WXConfigCenterDefaultImpl.h */,
@@ -374,6 +392,7 @@
 				775BEE781C1E8ECC008D1629 /* Frameworks */,
 				775BEE791C1E8ECC008D1629 /* Resources */,
 				C715566148067A7FFAB7797D /* [CP] Copy Pods Resources */,
+				ED72EE9F9A66E17E73D6C3BC /* [CP] Embed Pods Frameworks */,
 			);
 			buildRules = (
 			);
@@ -411,6 +430,7 @@
 				84361D3C1CA10F8E00F43825 /* Frameworks */,
 				84361D431CA10F8E00F43825 /* Resources */,
 				84361D6F1CA10F8E00F43825 /* [CP] Copy Pods Resources */,
+				EC0A67104CF45CC2B03DF0BE /* [CP] Embed Pods Frameworks */,
 			);
 			buildRules = (
 			);
@@ -522,7 +542,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n    # print error to STDERR\n    echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n    exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
+			shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n    # print error to STDERR\n    echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n    exit 1\nfi\n";
 			showEnvVarsInLog = 0;
 		};
 		84361D6F1CA10F8E00F43825 /* [CP] Copy Pods Resources */ = {
@@ -572,7 +592,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n    # print error to STDERR\n    echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n    exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
+			shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n    # print error to STDERR\n    echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n    exit 1\nfi\n";
 			showEnvVarsInLog = 0;
 		};
 		C715566148067A7FFAB7797D /* [CP] Copy Pods Resources */ = {
@@ -607,6 +627,36 @@
 			shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-WeexDemo/Pods-WeexDemo-resources.sh\"\n";
 			showEnvVarsInLog = 0;
 		};
+		EC0A67104CF45CC2B03DF0BE /* [CP] Embed Pods Frameworks */ = {
+			isa = PBXShellScriptBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			inputPaths = (
+			);
+			name = "[CP] Embed Pods Frameworks";
+			outputPaths = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+			shellPath = /bin/sh;
+			shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-WeexUITestDemo/Pods-WeexUITestDemo-frameworks.sh\"\n";
+			showEnvVarsInLog = 0;
+		};
+		ED72EE9F9A66E17E73D6C3BC /* [CP] Embed Pods Frameworks */ = {
+			isa = PBXShellScriptBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			inputPaths = (
+			);
+			name = "[CP] Embed Pods Frameworks";
+			outputPaths = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+			shellPath = /bin/sh;
+			shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-WeexDemo/Pods-WeexDemo-frameworks.sh\"\n";
+			showEnvVarsInLog = 0;
+		};
 /* End PBXShellScriptBuildPhase section */
 
 /* Begin PBXSourcesBuildPhase section */
@@ -617,6 +667,7 @@
 				17C1DB57206B675D000E0CEB /* DebugAnzlyzer.m in Sources */,
 				DCABAFF31D029685001C8592 /* WXATLoggerPlugin.m in Sources */,
 				DC15A3D0200E30FC009C8977 /* WXNavigationHandlerImpl.m in Sources */,
+				3375BEE921C74C5C003CAAB8 /* SRWebSocket+Weex.m in Sources */,
 				2AE88A2C1C8544E6003329DE /* WXScannerVC.m in Sources */,
 				17036A5720FDF9AA0029AE3D /* WXApmGeneratorImpl.m in Sources */,
 				775BEE861C1E8ECC008D1629 /* WXDemoViewController.m in Sources */,
@@ -634,6 +685,7 @@
 				DCABAFFE1D029753001C8592 /* WXImgLoaderDefaultImpl.m in Sources */,
 				747DF6681E2F176A005C53A8 /* UIView+UIThreadCheck.m in Sources */,
 				C47B78D21F299E27001D3B0C /* WXExtendCallNativeTest.m in Sources */,
+				3375BEE821C74C5C003CAAB8 /* WXWebSocketDefaultImpl.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/ios/playground/WeexDemo/AppDelegate.m b/ios/playground/WeexDemo/AppDelegate.m
index 4725fbe..fd40c93 100644
--- a/ios/playground/WeexDemo/AppDelegate.m
+++ b/ios/playground/WeexDemo/AppDelegate.m
@@ -36,6 +36,7 @@
 #import "WXNavigationHandlerImpl.h"
 //#import "WXAnalyzerCenter.h"
 #import "WXApmGeneratorImpl.h"
+#import "WXWebSocketDefaultImpl.h"
 
 
 #ifdef DEBUG
@@ -123,6 +124,7 @@
     [WXSDKEngine registerHandler:[WXConfigCenterDefaultImpl new] withProtocol:@protocol(WXConfigCenterProtocol)];
     [WXSDKEngine registerHandler:[WXNavigationHandlerImpl new] withProtocol:@protocol(WXNavigationProtocol)];
     [WXSDKEngine registerHandler:[WXApmGeneratorImpl new] withProtocol:@protocol(WXApmGeneratorProtocol)];
+    [WXSDKEngine registerHandler:[WXWebSocketDefauzltImpl new] withProtocol:@protocol(WXWebSocketHandler)];
     
     [WXSDKEngine registerComponent:@"select" withClass:NSClassFromString(@"WXSelectComponent")];
     [WXSDKEngine registerModule:@"event" withClass:[WXEventModule class]];
diff --git a/ios/playground/WeexDemo/Websocket/SRWebSocket+Weex.h b/ios/playground/WeexDemo/Websocket/SRWebSocket+Weex.h
new file mode 100644
index 0000000..8bb36b5
--- /dev/null
+++ b/ios/playground/WeexDemo/Websocket/SRWebSocket+Weex.h
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import <SocketRocket/SRWebSocket.h>
+#import <WeexSDK/WXWebSocketHandler.h>
+#import <objc/runtime.h>
+
+@interface SRWebSocket (Weex)
+
+@property (nonatomic, copy) NSString *wx_Identifier;
+@property (nonatomic, weak) id<WXWebSocketDelegate> wx_WebSocketDelegate;
+
+@end
diff --git a/ios/playground/WeexDemo/Websocket/SRWebSocket+Weex.m b/ios/playground/WeexDemo/Websocket/SRWebSocket+Weex.m
new file mode 100644
index 0000000..afdbcfa
--- /dev/null
+++ b/ios/playground/WeexDemo/Websocket/SRWebSocket+Weex.m
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import "SRWebSocket+Weex.h"
+static char wx_IdentifierKey;
+static char wx_WebSocketDelegateKey;
+
+
+@implementation SRWebSocket (Weex)
+
+-(void)setWx_Identifier:(NSString *)wx_Identifier
+{
+    objc_setAssociatedObject(self, &wx_IdentifierKey, wx_Identifier, OBJC_ASSOCIATION_COPY);
+}
+
+-(NSString *)wx_Identifier
+{
+    return objc_getAssociatedObject(self, &wx_IdentifierKey);
+}
+
+-(void)setWx_WebSocketDelegate:(id<WXWebSocketDelegate>)wx_WebSocketDelegate
+{
+    objc_setAssociatedObject(self, &wx_WebSocketDelegateKey, wx_WebSocketDelegate, OBJC_ASSOCIATION_COPY);
+}
+
+-(NSString *)wx_WebSocketDelegate
+{
+    return objc_getAssociatedObject(self, &wx_WebSocketDelegateKey);
+}
+
+@end
diff --git a/ios/playground/WeexDemo/Websocket/WXWebSocketDefaultImpl.h b/ios/playground/WeexDemo/Websocket/WXWebSocketDefaultImpl.h
new file mode 100644
index 0000000..620e71a
--- /dev/null
+++ b/ios/playground/WeexDemo/Websocket/WXWebSocketDefaultImpl.h
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import <WeexSDK/WXWebSocketHandler.h>
+
+@interface WXWebSocketDefaultImpl : NSObject<WXWebSocketHandler>
+
+@end
diff --git a/ios/playground/WeexDemo/Websocket/WXWebSocketDefaultImpl.m b/ios/playground/WeexDemo/Websocket/WXWebSocketDefaultImpl.m
new file mode 100644
index 0000000..60c9d34
--- /dev/null
+++ b/ios/playground/WeexDemo/Websocket/WXWebSocketDefaultImpl.m
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import "WXWebSocketDefaultImpl.h"
+#import <SocketRocket/SRWebSocket.h>
+#import "SRWebSocket+Weex.h"
+
+@interface WXWebSocketDefaultImpl()<SRWebSocketDelegate>
+
+@end
+
+@implementation WXWebSocketDefaultImpl
+{
+    NSMutableDictionary<NSString *, SRWebSocket *> *_webSockets;
+}
+
+#pragma mark - WXWebSocketHandler
+- (void)open:(NSString *)url protocol:(NSString *)protocol identifier:(NSString *)identifier withDelegate:(id<WXWebSocketDelegate>)delegate
+{
+    if(!_webSockets)
+    {
+        _webSockets = [NSMutableDictionary new];
+    }
+    if([_webSockets objectForKey:identifier]){
+        SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
+        webSocket.delegate = nil;
+        [webSocket close];
+        
+    }
+    NSArray *protols;
+    if([protocol length]>0){
+       protols = [NSArray arrayWithObject:protocol];
+    }
+    SRWebSocket *webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:url] protocols:protols];
+    webSocket.delegate = self;
+    [webSocket open];
+    webSocket.wx_Identifier = identifier;
+    webSocket.wx_WebSocketDelegate = delegate;
+    [_webSockets setObject:webSocket forKey:identifier];
+}
+
+- (void)send:(id)identifier data:(NSString *)data
+{
+    SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
+    if(webSocket) {
+        [webSocket send:data];
+    }
+}
+
+- (void)close:(NSString *)identifier
+{
+    SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
+    if(webSocket) {
+        [webSocket close];
+    }
+}
+
+- (void)close:(NSString *)identifier code:(NSInteger)code reason:(NSString *)reason
+{
+    SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
+    if(webSocket) {
+        [webSocket closeWithCode:code reason:reason];
+    }
+}
+
+- (void)clear:(NSString *)identifier
+{
+    SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
+    if(webSocket) {
+        webSocket.delegate = nil;
+        [webSocket close];
+        [_webSockets removeObjectForKey:identifier];
+    }
+}
+
+#pragma mark -SRWebSocketDelegate
+- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
+{
+    if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didOpen)]) {
+        [webSocket.wx_WebSocketDelegate didOpen];
+    }
+}
+
+- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
+{
+    if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didFailWithError:)]) {
+        [webSocket.wx_WebSocketDelegate didFailWithError:error];
+    }
+}
+
+- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
+{
+    if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didReceiveMessage:)]) {
+        [webSocket.wx_WebSocketDelegate didReceiveMessage:message];
+    }
+}
+
+- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
+{
+    if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didCloseWithCode:reason:wasClean:)]) {
+        [webSocket.wx_WebSocketDelegate didCloseWithCode:code reason:reason wasClean:wasClean];
+    }
+}
+@end