forked from Ericsson/c3-web-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharedCursor.html
More file actions
131 lines (121 loc) · 4.25 KB
/
sharedCursor.html
File metadata and controls
131 lines (121 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!--
* Copyright (C) 2016 Ericsson AB. All rights reserved.
*
* Licensed 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.
-->
<!DOCTYPE html>
<html>
<head>
<title>Shared Cursor</title>
<link rel="stylesheet" type="text/css" href="../resources/main.css">
<link rel="icon" href="../resources/favicon.ico">
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/3.2.1/es6-promise.min.js"></script>
<script type="text/javascript" src="https://get.cct.ericsson.net/latest/cct.js"></script>
<script type="text/javascript" src="../exampleUtils.js"></script>
<style>
#shareBox {
position: relative;
background-color: #ccc;
margin: 10px;
width: 400px;
height: 200px;
}
.mouseIndicator {
position: absolute;
transform: translate(-10px, -10px);
left: 20px;
width: 20px;
height: 20px;
border-radius: 10px;
}
.mouseIndicator > p {
position: relative;
top: -19px;
left: 25px;
}
#self {
background-color: #f00;
top: 20px;
}
#remote {
background-color: #06f;
top: 50px;
}
</style>
</head>
<body>
<header></header>
<main>
<section>
<div class="about">
<h2>Shared Cursor example</h2>
This example shows how to connect two <a href="https://get.cct.ericsson.net/latest/docs/reference/Client.html"></a> together through a <a href="https://get.cct.ericsson.net/latest/docs/reference/Room.html">room</a>. Once they both have joined the room, a peer-2-peer WebRTC <a href="https://get.cct.ericsson.net/latest/docs/reference/Room.html#startCall__anchor">call</a> is set up. Once the call is set up a <a href="https://get.cct.ericsson.net/latest/docs/reference/DataShare.html">DataShare</a> is created between the two clients sending their respective cursor data to eachother.
</div>
<div class="peer-link">
<h3 class="peer-link-title"></h3>
<input class="peer-link-input" type="url" value="" size="55">
<div class="peer-link-connection-state"></div>
</div>
</section>
<div class="margins">
<h1 id="exampleStatus">Waiting for peer to join</h1>
<p id="instructions"></p>
<div id="shareBox">
<div class="mouseIndicator" id="self"><p>self</p></div>
<div class="mouseIndicator" id="remote"><p>remote</p></div>
</div>
</div>
<footer></footer>
</main>
<script>
'use strict'
cct.log.setLogLevel('example', cct.log.ALL)
cct.log.color = true
var el = {
exampleStatus: document.getElementById('exampleStatus'),
instructions: document.getElementById('instructions'),
shareBox: document.getElementById('shareBox'),
self: document.getElementById('self'),
remote: document.getElementById('remote'),
}
var client = new cct.Client()
PeerConnecter.clientInCall(client).then(function (connecter) {
var call = connecter.call
call.on('connectionState', function (connectionState) {
if (connectionState === 'connected') {
el.exampleStatus.textContent = 'Sharing enabled'
el.instructions.textContent = 'Move your mouse inside the grey box to send cursor data.'
} else {
el.exampleStatus.textContent = ''
el.instructions.textContent = ''
}
})
var data = new cct.DataShare({ownerId: call.ownId})
call.attach('data', data)
data.on('update', function (update) {
var updateEl = update.key === call.ownId ? el.self : el.remote
updateEl.style.left = update.value.x + 'px'
updateEl.style.top = update.value.y + 'px'
})
el.shareBox.addEventListener('mousemove', function (event) {
if (event.target === el.shareBox) {
data.set(call.ownId, {x: event.offsetX, y: event.offsetY})
}
})
}).catch(function (error) {
cct.log.error('example', '' + error)
logError('Error: ' + error)
})
</script>
</body>
</html>