{"action":"created","comment":{"url":"https://api.github.com/repos/leancloud/docs/pulls/comments/201945978","pull_request_review_id":136544159,"id":201945978,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMTk0NTk3OA==","diff_hunk":"@@ -0,0 +1,693 @@\n+# Play 开发指南 &middot; Cocos Creator\n+\n+## 前言\n+\n+Play 是一个基于 JavaScript 编写的 Cocos Creator 的插件，它具备如下几项主要的功能（包括但不限于）：\n+\n+- 与服务端建立长连接\n+- 获取房间列表\n+- 创建房间\n+- 加入房间\n+- 随机加入（符合条件的）房间\n+- 获取房间玩家\n+- 获取，设置，同步房间的属性\n+- 获取，设置，同步玩家的属性\n+- 发送和接收`自定义事件`\n+- 离开房间\n+\n+> Play 为有强联网需求的网络游戏提供了一整套的客户端 SDK 解决方案，因此开发团队不再需要自建服务端，从而节省大部分开发和运维成本。\n+\n+\n+\n+## SDK 导入\n+\n+请阅读 [安装](play-js-quick-start.html#安装)，获取 js 库文件。\n+\n+\n+\n+## 初始化\n+\n+首先 Play SDK 在内部实例化了一个 `Play` 类型的对象 `play`，我们只需要引入并使用即可。（后文中的 `play` 都是指这个对象。）\n+\n+```javascript\n+import {\n+  play,\n+  PlayOptions,\n+  Region,\n+} from '../play';\n+```\n+\n+接着我们需要实例化一个 PlayOptions 类型的对象，作为初始化 Play 的参数。\n+\n+```javascript\n+const opts = new PlayOptions();\n+// 设置 APP ID\n+opts.appId = YOUR_APP_ID;\n+// 设置 APP Key\n+opts.appKey = YOUR_APP_KEY;\n+// 设置节点地区\n+// EAST_CN：华东节点\n+// NORTH_CN：华北节点\n+// US：美国节点\n+opts.region = Region.EAST_CN;\n+play.init(opts);\n+```\n+\n+\n+\n+## 连接\n+\n+我们需要设置一个 `userId` 作为客户端的唯一标识连接至服务器。\n+\n+```javascript\n+play.userId = 'leancloud';\n+```\n+\n+注意：这个 `userId` 拥有如下限制：\n+- 不支持中文和特殊字符（包括 `，！@#￥%……&*（）` 等），但可以是下划线 `_`\n+- 长度不能超过 64 字符\n+- 一个应用内全局唯一\n+\n+建立连接\n+\n+```javascript\n+play.connect({ gameVersion = '0.0.1' });\n+```\n+\n+- `gameVersion` 表示客户端的版本号，如果允许多个版本的游戏共存，则可以根据这个版本号路由到不同的游戏服务器，相当于给玩家按版本做隔离。如果没有类似需求，请忽略这个参数。\n+\n+在连接成功后，会收到 `CONNECTED`（连接成功）事件；否则，将会收到 `CONNECT_FAILED`（连接失败）事件，回调参数 `error` 将包含失败原因。\n+\n+```javascript\n+// 注册连接成功事件\n+play.on(Event.CONNECTED, () => {\n+\t// TODO 可以做跳转场景等操作\n+\n+});\n+\n+// 注册连接失败事件\n+play.on(Event.CONNECT_FAILED, (error) => {\n+\t// TODO 可以根据 error 提示用户失败原因\n+\n+});\n+```\n+\n+\n+\n+## 大厅\n+\n+在连接服务器成功之后，默认会自动加入到大厅中。\n+\n+开发者可以根据需要注册 `JOINED_LOBBY`（成功加入大厅）事件。\n+\n+```javascript\n+// 注册成功加入大厅事件\n+play.on(Event.JOINED_LOBBY, () => {\n+\t// TODO 可以做跳转场景，房间列表展示的逻辑\n+\n+});\n+```\n+\n+当玩家加入到大厅后，Play SDK 会自动同步当前大厅的房间列表，开发者可以根据房间列表显示 / 加入房间参与游戏。\n+\n+开发者可以根据下面的接口获取房间列表。\n+\n+```javascript\n+// 返回 LobbyRoom[]\n+play.lobbyRoomList;","path":"views/play-js.md","position":117,"original_position":117,"commit_id":"8f13228ffcb3b432e4cdd5f0c4c26ff24b0469d0","original_commit_id":"8f13228ffcb3b432e4cdd5f0c4c26ff24b0469d0","user":{"login":"nicecui","id":10130959,"node_id":"MDQ6VXNlcjEwMTMwOTU5","avatar_url":"https://avatars1.githubusercontent.com/u/10130959?v=4","gravatar_id":"","url":"https://api.github.com/users/nicecui","html_url":"https://github.com/nicecui","followers_url":"https://api.github.com/users/nicecui/followers","following_url":"https://api.github.com/users/nicecui/following{/other_user}","gists_url":"https://api.github.com/users/nicecui/gists{/gist_id}","starred_url":"https://api.github.com/users/nicecui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicecui/subscriptions","organizations_url":"https://api.github.com/users/nicecui/orgs","repos_url":"https://api.github.com/users/nicecui/repos","events_url":"https://api.github.com/users/nicecui/events{/privacy}","received_events_url":"https://api.github.com/users/nicecui/received_events","type":"User","site_admin":false},"body":"LobbyRoom 是什么？可以参考这里给出说明：https://leancloud.cn/docs/leaderboard-guide-js.html#hash1966985553","created_at":"2018-07-12T08:14:10Z","updated_at":"2018-07-12T08:14:10Z","html_url":"https://github.com/leancloud/docs/pull/2627#discussion_r201945978","pull_request_url":"https://api.github.com/repos/leancloud/docs/pulls/2627","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/leancloud/docs/pulls/comments/201945978"},"html":{"href":"https://github.com/leancloud/docs/pull/2627#discussion_r201945978"},"pull_request":{"href":"https://api.github.com/repos/leancloud/docs/pulls/2627"}}},"pull_request":{"url":"https://api.github.com/repos/leancloud/docs/pulls/2627","id":199349235,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk5MzQ5MjM1","html_url":"https://github.com/leancloud/docs/pull/2627","diff_url":"https://github.com/leancloud/docs/pull/2627.diff","patch_url":"https://github.com/leancloud/docs/pull/2627.patch","issue_url":"https://api.github.com/repos/leancloud/docs/issues/2627","number":2627,"state":"open","locked":false,"title":"add: 增加 Play-SDK-JS 的 Quick Start 文档","user":{"login":"onerain88","id":1450714,"node_id":"MDQ6VXNlcjE0NTA3MTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/1450714?v=4","gravatar_id":"","url":"https://api.github.com/users/onerain88","html_url":"https://github.com/onerain88","followers_url":"https://api.github.com/users/onerain88/followers","following_url":"https://api.github.com/users/onerain88/following{/other_user}","gists_url":"https://api.github.com/users/onerain88/gists{/gist_id}","starred_url":"https://api.github.com/users/onerain88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onerain88/subscriptions","organizations_url":"https://api.github.com/users/onerain88/orgs","repos_url":"https://api.github.com/users/onerain88/repos","events_url":"https://api.github.com/users/onerain88/events{/privacy}","received_events_url":"https://api.github.com/users/onerain88/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-07-05T03:04:25Z","updated_at":"2018-07-12T08:14:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"132f5ffd2ec03c6272881f69db728f6228ae898f","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/leancloud/docs/pulls/2627/commits","review_comments_url":"https://api.github.com/repos/leancloud/docs/pulls/2627/comments","review_comment_url":"https://api.github.com/repos/leancloud/docs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/leancloud/docs/issues/2627/comments","statuses_url":"https://api.github.com/repos/leancloud/docs/statuses/8f13228ffcb3b432e4cdd5f0c4c26ff24b0469d0","head":{"label":"onerain88:Play-JS","ref":"Play-JS","sha":"8f13228ffcb3b432e4cdd5f0c4c26ff24b0469d0","user":{"login":"onerain88","id":1450714,"node_id":"MDQ6VXNlcjE0NTA3MTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/1450714?v=4","gravatar_id":"","url":"https://api.github.com/users/onerain88","html_url":"https://github.com/onerain88","followers_url":"https://api.github.com/users/onerain88/followers","following_url":"https://api.github.com/users/onerain88/following{/other_user}","gists_url":"https://api.github.com/users/onerain88/gists{/gist_id}","starred_url":"https://api.github.com/users/onerain88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onerain88/subscriptions","organizations_url":"https://api.github.com/users/onerain88/orgs","repos_url":"https://api.github.com/users/onerain88/repos","events_url":"https://api.github.com/users/onerain88/events{/privacy}","received_events_url":"https://api.github.com/users/onerain88/received_events","type":"User","site_admin":false},"repo":{"id":132397473,"node_id":"MDEwOlJlcG9zaXRvcnkxMzIzOTc0NzM=","name":"docs","full_name":"onerain88/docs","owner":{"login":"onerain88","id":1450714,"node_id":"MDQ6VXNlcjE0NTA3MTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/1450714?v=4","gravatar_id":"","url":"https://api.github.com/users/onerain88","html_url":"https://github.com/onerain88","followers_url":"https://api.github.com/users/onerain88/followers","following_url":"https://api.github.com/users/onerain88/following{/other_user}","gists_url":"https://api.github.com/users/onerain88/gists{/gist_id}","starred_url":"https://api.github.com/users/onerain88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onerain88/subscriptions","organizations_url":"https://api.github.com/users/onerain88/orgs","repos_url":"https://api.github.com/users/onerain88/repos","events_url":"https://api.github.com/users/onerain88/events{/privacy}","received_events_url":"https://api.github.com/users/onerain88/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/onerain88/docs","description":"LeanCloud Documentation","fork":true,"url":"https://api.github.com/repos/onerain88/docs","forks_url":"https://api.github.com/repos/onerain88/docs/forks","keys_url":"https://api.github.com/repos/onerain88/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/onerain88/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/onerain88/docs/teams","hooks_url":"https://api.github.com/repos/onerain88/docs/hooks","issue_events_url":"https://api.github.com/repos/onerain88/docs/issues/events{/number}","events_url":"https://api.github.com/repos/onerain88/docs/events","assignees_url":"https://api.github.com/repos/onerain88/docs/assignees{/user}","branches_url":"https://api.github.com/repos/onerain88/docs/branches{/branch}","tags_url":"https://api.github.com/repos/onerain88/docs/tags","blobs_url":"https://api.github.com/repos/onerain88/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/onerain88/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/onerain88/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/onerain88/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/onerain88/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/onerain88/docs/languages","stargazers_url":"https://api.github.com/repos/onerain88/docs/stargazers","contributors_url":"https://api.github.com/repos/onerain88/docs/contributors","subscribers_url":"https://api.github.com/repos/onerain88/docs/subscribers","subscription_url":"https://api.github.com/repos/onerain88/docs/subscription","commits_url":"https://api.github.com/repos/onerain88/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/onerain88/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/onerain88/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/onerain88/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/onerain88/docs/contents/{+path}","compare_url":"https://api.github.com/repos/onerain88/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/onerain88/docs/merges","archive_url":"https://api.github.com/repos/onerain88/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/onerain88/docs/downloads","issues_url":"https://api.github.com/repos/onerain88/docs/issues{/number}","pulls_url":"https://api.github.com/repos/onerain88/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/onerain88/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/onerain88/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/onerain88/docs/labels{/name}","releases_url":"https://api.github.com/repos/onerain88/docs/releases{/id}","deployments_url":"https://api.github.com/repos/onerain88/docs/deployments","created_at":"2018-05-07T02:38:46Z","updated_at":"2018-06-29T02:55:42Z","pushed_at":"2018-07-12T06:40:12Z","git_url":"git://github.com/onerain88/docs.git","ssh_url":"git@github.com:onerain88/docs.git","clone_url":"https://github.com/onerain88/docs.git","svn_url":"https://github.com/onerain88/docs","homepage":"https://leancloud.cn/docs/","size":67625,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"leancloud:stg-play-js","ref":"stg-play-js","sha":"f73481b12f643a55f15f8c9d95c3cd353717a79c","user":{"login":"leancloud","id":6660518,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY2NjA1MTg=","avatar_url":"https://avatars2.githubusercontent.com/u/6660518?v=4","gravatar_id":"","url":"https://api.github.com/users/leancloud","html_url":"https://github.com/leancloud","followers_url":"https://api.github.com/users/leancloud/followers","following_url":"https://api.github.com/users/leancloud/following{/other_user}","gists_url":"https://api.github.com/users/leancloud/gists{/gist_id}","starred_url":"https://api.github.com/users/leancloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leancloud/subscriptions","organizations_url":"https://api.github.com/users/leancloud/orgs","repos_url":"https://api.github.com/users/leancloud/repos","events_url":"https://api.github.com/users/leancloud/events{/privacy}","received_events_url":"https://api.github.com/users/leancloud/received_events","type":"Organization","site_admin":false},"repo":{"id":25067518,"node_id":"MDEwOlJlcG9zaXRvcnkyNTA2NzUxOA==","name":"docs","full_name":"leancloud/docs","owner":{"login":"leancloud","id":6660518,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY2NjA1MTg=","avatar_url":"https://avatars2.githubusercontent.com/u/6660518?v=4","gravatar_id":"","url":"https://api.github.com/users/leancloud","html_url":"https://github.com/leancloud","followers_url":"https://api.github.com/users/leancloud/followers","following_url":"https://api.github.com/users/leancloud/following{/other_user}","gists_url":"https://api.github.com/users/leancloud/gists{/gist_id}","starred_url":"https://api.github.com/users/leancloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leancloud/subscriptions","organizations_url":"https://api.github.com/users/leancloud/orgs","repos_url":"https://api.github.com/users/leancloud/repos","events_url":"https://api.github.com/users/leancloud/events{/privacy}","received_events_url":"https://api.github.com/users/leancloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/leancloud/docs","description":"LeanCloud Documentation","fork":false,"url":"https://api.github.com/repos/leancloud/docs","forks_url":"https://api.github.com/repos/leancloud/docs/forks","keys_url":"https://api.github.com/repos/leancloud/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/leancloud/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/leancloud/docs/teams","hooks_url":"https://api.github.com/repos/leancloud/docs/hooks","issue_events_url":"https://api.github.com/repos/leancloud/docs/issues/events{/number}","events_url":"https://api.github.com/repos/leancloud/docs/events","assignees_url":"https://api.github.com/repos/leancloud/docs/assignees{/user}","branches_url":"https://api.github.com/repos/leancloud/docs/branches{/branch}","tags_url":"https://api.github.com/repos/leancloud/docs/tags","blobs_url":"https://api.github.com/repos/leancloud/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/leancloud/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/leancloud/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/leancloud/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/leancloud/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/leancloud/docs/languages","stargazers_url":"https://api.github.com/repos/leancloud/docs/stargazers","contributors_url":"https://api.github.com/repos/leancloud/docs/contributors","subscribers_url":"https://api.github.com/repos/leancloud/docs/subscribers","subscription_url":"https://api.github.com/repos/leancloud/docs/subscription","commits_url":"https://api.github.com/repos/leancloud/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/leancloud/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/leancloud/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/leancloud/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/leancloud/docs/contents/{+path}","compare_url":"https://api.github.com/repos/leancloud/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/leancloud/docs/merges","archive_url":"https://api.github.com/repos/leancloud/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/leancloud/docs/downloads","issues_url":"https://api.github.com/repos/leancloud/docs/issues{/number}","pulls_url":"https://api.github.com/repos/leancloud/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/leancloud/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/leancloud/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/leancloud/docs/labels{/name}","releases_url":"https://api.github.com/repos/leancloud/docs/releases{/id}","deployments_url":"https://api.github.com/repos/leancloud/docs/deployments","created_at":"2014-10-11T07:14:37Z","updated_at":"2018-07-11T07:01:38Z","pushed_at":"2018-07-12T06:45:40Z","git_url":"git://github.com/leancloud/docs.git","ssh_url":"git@github.com:leancloud/docs.git","clone_url":"https://github.com/leancloud/docs.git","svn_url":"https://github.com/leancloud/docs","homepage":"https://leancloud.cn/docs/","size":67634,"stargazers_count":497,"watchers_count":497,"language":"CSS","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":253,"mirror_url":null,"archived":false,"open_issues_count":82,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":253,"open_issues":82,"watchers":497,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/leancloud/docs/pulls/2627"},"html":{"href":"https://github.com/leancloud/docs/pull/2627"},"issue":{"href":"https://api.github.com/repos/leancloud/docs/issues/2627"},"comments":{"href":"https://api.github.com/repos/leancloud/docs/issues/2627/comments"},"review_comments":{"href":"https://api.github.com/repos/leancloud/docs/pulls/2627/comments"},"review_comment":{"href":"https://api.github.com/repos/leancloud/docs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/leancloud/docs/pulls/2627/commits"},"statuses":{"href":"https://api.github.com/repos/leancloud/docs/statuses/8f13228ffcb3b432e4cdd5f0c4c26ff24b0469d0"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"nicecui"}}