You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2017/08/10 09:08:11 UTC
[2/8] incubator-weex git commit: + [ios] add array buffer support
+ [ios] add array buffer support
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/fd8f1770
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/fd8f1770
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/fd8f1770
Branch: refs/heads/0.16-dev
Commit: fd8f177020b712724c52a02052b20e06d2d22661
Parents: 1aa0bf4
Author: 齐山 <su...@163.com>
Authored: Wed Aug 2 16:27:11 2017 +0800
Committer: 齐山 <su...@163.com>
Committed: Wed Aug 2 16:27:11 2017 +0800
----------------------------------------------------------------------
examples/vue/modules/websocket.vue | 15 +-
.../WeexSDK/Sources/Loader/WXWebSocketLoader.h | 2 +-
.../WeexSDK/Sources/Loader/WXWebSocketLoader.m | 2 +-
.../WeexSDK/Sources/Module/WXWebSocketModule.m | 20 +-
.../Sources/WebSocket/WXWebSocketDefaultImpl.m | 2 +-
pre-build/native-bundle-main.js | 26024 ++++++++++++++++-
6 files changed, 26050 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fd8f1770/examples/vue/modules/websocket.vue
----------------------------------------------------------------------
diff --git a/examples/vue/modules/websocket.vue b/examples/vue/modules/websocket.vue
index 72d7ea1..e6ba2e1 100644
--- a/examples/vue/modules/websocket.vue
+++ b/examples/vue/modules/websocket.vue
@@ -88,7 +88,13 @@
self.onopeninfo = 'websocket open';
}
websocket.onmessage = function(e) {
- self.onmessage = e.data;
+ if(Object.prototype.toString.apply(e.data) === 'ArrayBuffer'){
+ self.onmessage = 'you receive array buffer'
+ }
+ if(Object.prototype.toString.apply(e.data) === 'String'){
+ self.onmessage = e.data;
+ }
+
}
websocket.onerror = function(e) {
self.onerrorinfo = e.data;
@@ -101,7 +107,12 @@
send: function(e) {
var input = this.$refs.input;
input.blur();
- websocket.send(this.txtInput);
+ var buffer = new ArrayBuffer(16)
+ var view = new Float32Array(buffer)
+ view.set([4,89,36.9,0.765])
+ console.log(buffer);
+ this.sendinfo = buffer;
+ websocket.send(buffer);
this.sendinfo = this.txtInput;
},
oninput: function(event) {
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fd8f1770/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.h b/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.h
index 378a85e..95e5398 100644
--- a/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.h
+++ b/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.h
@@ -28,7 +28,7 @@
- (instancetype)initWithUrl:(NSString *)url protocol:(NSString *)protocol;
- (void)open;
-- (void)send:(NSString *)data;
+- (void)send:(id)data;
- (void)close;
- (void)close:(NSInteger)code reason:(NSString *)reason;
- (void)clear;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fd8f1770/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.m b/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.m
index c751c0a..7821ed6 100644
--- a/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.m
+++ b/ios/sdk/WeexSDK/Sources/Loader/WXWebSocketLoader.m
@@ -74,7 +74,7 @@
}
}
-- (void)send:(NSString *)data
+- (void)send:(id)data
{
id<WXWebSocketHandler> requestHandler = [WXHandlerFactory handlerForProtocol:@protocol(WXWebSocketHandler)];
if (requestHandler) {
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fd8f1770/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m b/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m
index 018103a..046702d 100644
--- a/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m
+++ b/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m
@@ -61,6 +61,12 @@ WX_EXPORT_METHOD(@selector(onclose:))
NSMutableDictionary *dic = [NSMutableDictionary new];
if([message isKindOfClass:[NSString class]]) {
[dic setObject:message forKey:@"data"];
+ }else if([message isKindOfClass:[NSData class]]){
+ NSMutableDictionary *dataDict = [NSMutableDictionary new];
+ NSString *base64Encoded = [message base64EncodedStringWithOptions:0];
+ [dataDict setObject:@"binary" forKey:@"@type"];
+ [dataDict setObject:base64Encoded forKey:@"base64"];
+ [dic setObject:dataDict forKey:@"data"];
}
if (weakSelf.messageCallBack) {
weakSelf.messageCallBack(dic,true);;
@@ -103,9 +109,19 @@ WX_EXPORT_METHOD(@selector(onclose:))
[loader open];
}
-- (void)send:(NSString *)data
+- (void)send:(id)data
{
- [loader send:data];
+ if([data isKindOfClass:[NSString class]]){
+ [loader send:data];
+ }else if([data isKindOfClass:[NSDictionary class]]){
+ if([@"binary" isEqualToString:data[@"@type"]]){
+ NSString *base64 = data[@"base64"];
+ NSData *sendData = [[NSData alloc] initWithBase64EncodedString:base64 options:0];
+ [loader send:sendData];
+ }
+ }
+
+
}
- (void)close
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fd8f1770/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m
index 951f385..c0b554e 100644
--- a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m
+++ b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m
@@ -56,7 +56,7 @@
[_webSockets setObject:webSocket forKey:identifier];
}
-- (void)send:(NSString *)identifier data:(NSString *)data
+- (void)send:(id)identifier data:(NSString *)data
{
SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
if(webSocket) {