You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by so...@apache.org on 2017/06/28 08:45:54 UTC
[03/37] incubator-weex git commit: + [html5] add webSocket api for
web platform @notdanger
+ [html5] add webSocket api for web platform @notdanger
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/9df3655d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/9df3655d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/9df3655d
Branch: refs/heads/0.15-dev
Commit: 9df3655d5e42bb335c09aa21d29fe03979175894
Parents: 9994583
Author: erha19 <75...@qq.com>
Authored: Thu Jun 22 11:57:45 2017 +0800
Committer: erha19 <75...@qq.com>
Committed: Thu Jun 22 14:41:50 2017 +0800
----------------------------------------------------------------------
html5/render/vue/env/weex.js | 3 +
html5/render/vue/modules/index.js | 2 +
html5/render/vue/modules/websocket/index.js | 26 ++++++++
html5/render/vue/modules/websocket/websocket.js | 66 ++++++++++++++++++++
4 files changed, 97 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9df3655d/html5/render/vue/env/weex.js
----------------------------------------------------------------------
diff --git a/html5/render/vue/env/weex.js b/html5/render/vue/env/weex.js
index e5ae94b..9b804cb 100644
--- a/html5/render/vue/env/weex.js
+++ b/html5/render/vue/env/weex.js
@@ -78,6 +78,9 @@ const weex = {
if (!weexModules[name]) {
weexModules[name] = {}
}
+ if (!!meta && meta.mountType === 'full') {
+ weexModules[name] = module
+ }
for (const key in module) {
if (module.hasOwnProperty(key)) {
weexModules[name][key] = utils.bind(module[key], this)
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9df3655d/html5/render/vue/modules/index.js
----------------------------------------------------------------------
diff --git a/html5/render/vue/modules/index.js b/html5/render/vue/modules/index.js
index 4237f9d..27f0592 100644
--- a/html5/render/vue/modules/index.js
+++ b/html5/render/vue/modules/index.js
@@ -33,6 +33,7 @@ import globalEvent from './globalEvent'
import modal from './modal'
import navigator from './navigator'
import webview from './webview'
+import websocket from './websocket'
const legacyModules = {
event,
@@ -57,6 +58,7 @@ export default {
weex.install(legacyModules[k])
}
weex.install(modal)
+ weex.install(websocket)
for (const k in modules) {
weex.registerModule(k, modules[k])
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9df3655d/html5/render/vue/modules/websocket/index.js
----------------------------------------------------------------------
diff --git a/html5/render/vue/modules/websocket/index.js b/html5/render/vue/modules/websocket/index.js
new file mode 100644
index 0000000..273ed58
--- /dev/null
+++ b/html5/render/vue/modules/websocket/index.js
@@ -0,0 +1,26 @@
+/*
+ * 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 websocket from './websocket'
+
+// TODO: rewrite the module meta
+export default {
+ init: function (Weex) {
+ Weex.registerModule('webSocket', websocket, { mountType: 'full' })
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9df3655d/html5/render/vue/modules/websocket/websocket.js
----------------------------------------------------------------------
diff --git a/html5/render/vue/modules/websocket/websocket.js b/html5/render/vue/modules/websocket/websocket.js
new file mode 100644
index 0000000..c5cfa26
--- /dev/null
+++ b/html5/render/vue/modules/websocket/websocket.js
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+/**
+ * websocket module
+ */
+// let instance = null
+
+export default (function () {
+ let instance = null
+ const registerListeners = ['onopen', 'onmessage', 'onerror', 'onclose']
+ const ws = {
+ hasOwnProperty: function (e) {
+ return true
+ },
+ WebSocket: function (url, protocol) {
+ if (!url) {
+ return
+ }
+ if (!protocol) {
+ instance = new WebSocket(url)
+ }
+ else {
+ instance = new WebSocket(url, protocol)
+ }
+ return instance
+ },
+ send: function (messages) {
+ instance && instance.send(messages)
+ },
+ close: function () {
+ instance && instance.close()
+ }
+ }
+ for (const i in registerListeners) {
+ if (registerListeners.hasOwnProperty(i)) {
+ Object.defineProperty(ws, registerListeners[i], {
+ get: function () {
+ return instance && instance[registerListeners[i]]
+ },
+ set: function (fn) {
+ if (instance) {
+ instance[registerListeners[i]] = fn
+ }
+ }
+ })
+ }
+ }
+ return ws
+})()