+ [example] add websocket arraybuffer demo
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/09669574 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/09669574 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/09669574 Branch: refs/heads/0.16-dev Commit: 096695744c4cb7767a6942c1fb7219129aa6d687 Parents: ec94e28 Author: é½å±± <sunjjb...@163.com> Authored: Tue Aug 8 15:40:02 2017 +0800 Committer: é½å±± <sunjjb...@163.com> Committed: Tue Aug 8 15:40:02 2017 +0800 ---------------------------------------------------------------------- examples/vue/modules/websocket.vue | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/09669574/examples/vue/modules/websocket.vue ---------------------------------------------------------------------- diff --git a/examples/vue/modules/websocket.vue b/examples/vue/modules/websocket.vue index e2ab2ce..2620677 100644 --- a/examples/vue/modules/websocket.vue +++ b/examples/vue/modules/websocket.vue @@ -8,6 +8,7 @@ <div style="flex-direction: row; justify-content: center;"> <text class="button" @click="connect">connect</text> <text class="button" @click="send">send</text> + <text class="button" @click="sendArrayBuffer">sendArrayBuffer</text> <text class="button" @click="close">close</text> </div> <div style="background-color: lightgray"> @@ -80,6 +81,7 @@ } }, methods: { + connect: function() { websocket.WebSocket('ws://echo.websocket.org', ''); var self = this; @@ -88,13 +90,14 @@ self.onopeninfo = 'websocket open'; } websocket.onmessage = function(e) { - if(typeof(e.data) === 'String'){ + console.log(typeof(e.data)); + if(typeof(e.data) === 'string'){ self.onmessage = e.data; }else { - self.onmessage = 'you receive array buffer' + var str = 'receive array buffer show with string:' + String.fromCharCode.apply(null, new Float32Array(e.data)); + self.onmessage = str; } - } websocket.onerror = function(e) { self.onerrorinfo = e.data; @@ -107,13 +110,19 @@ send: function(e) { var input = this.$refs.input; input.blur(); + websocket.send(this.txtInput); + this.sendinfo = this.txtInput; + }, + sendArrayBuffer: function(e) { + var input = this.$refs.input; + input.blur(); var buffer = new ArrayBuffer(16) var view = new Float32Array(buffer) view.set([4,89,36.9,0.765]) console.log(buffer); - this.sendinfo = buffer; + var str = 'send array buffer show with string:' + String.fromCharCode.apply(null, new Float32Array(buffer)); + this.sendinfo = str; websocket.send(buffer); - this.sendinfo = this.txtInput; }, oninput: function(event) { this.txtInput = event.value;