97 lines
2.9 KiB
CoffeeScript
97 lines
2.9 KiB
CoffeeScript
context = window
|
|
teacherActions = window.JK.Actions.Teacher
|
|
|
|
@BonjourMixin = {
|
|
|
|
resyncBonjour: () ->
|
|
rest.getUserJamBlasters({client_id: @app.clientId}).done((response) => @getUserJamBlastersDone(response)).fail((response) => @getUserJamBlastersFail(response))
|
|
|
|
getUserJamBlastersDone: (response) ->
|
|
@setState({userJamBlasters: response})
|
|
|
|
@getLocalClients(response)
|
|
|
|
|
|
findJamBlaster: (id) ->
|
|
found = null
|
|
if @clients?
|
|
for client in @clients
|
|
if client.id == id
|
|
found = client
|
|
break
|
|
if client.ipv6_addr == id
|
|
found = client
|
|
break
|
|
|
|
found
|
|
|
|
getUserJamBlastersFail: (jqXHR) ->
|
|
@app.layout.ajaxError(jqXHR)
|
|
|
|
mergeBonjourClients: (localClients, userJamBlasters) ->
|
|
console.log("@state.localClients", localClients)
|
|
console.log("@state.userJamBlasters", userJamBlasters)
|
|
|
|
# for localClient in @state.localClients
|
|
|
|
for localClient in localClients
|
|
if localClient.connect_url.indexOf(':30330') && localClient.is_jb
|
|
client = {}
|
|
client.ipv6_addr = localClient.ipv6_addr
|
|
client.isPaired = localClient.isPaired
|
|
client.name = localClient.name
|
|
client.has_local = true
|
|
client.has_server = false
|
|
client.id = client.ipv6_addr
|
|
client.connect_url = localClient.connect_url
|
|
|
|
|
|
for serverClient in userJamBlasters
|
|
# see if we can join on ipv6
|
|
if ipv6_addr == serverClient.ipv6_link_local
|
|
# ok, matched! augment with server data
|
|
client.serial_no = serverClient.serial_no
|
|
client.user_id = serverClient.user_id
|
|
client.id = serverClient.id
|
|
client.client_id = serverClient.client_id
|
|
client.ipv4_link_local = serverClient.ipv4_link_local
|
|
client.display_name = serverClient.display_name
|
|
client.has_server = true
|
|
break
|
|
clients.push(client)
|
|
|
|
for serverClient in userJamBlasters
|
|
|
|
foundLocal = false
|
|
for localClient in localClients
|
|
if ipv6_addr == serverClient.ipv6_link_local
|
|
foundLocal = true
|
|
break
|
|
if !foundLocal
|
|
# this server version of the client has not been spoken for in the earlier loop above
|
|
# so we need to add it in to the client list
|
|
|
|
client = {}
|
|
client.serial_no = serverClient.serial_no
|
|
client.user_id = serverClient.user_id
|
|
client.id = serverClient.id
|
|
client.client_id = serverClient.client_id
|
|
client.ipv4_link_local = serverClient.ipv4_link_local
|
|
client.display_name = serverClient.display_name
|
|
client.has_local = false
|
|
client.has_server = true
|
|
clients.push(client)
|
|
|
|
console.log("all client", clients)
|
|
|
|
@clients = clients
|
|
@setState({clients: clients})
|
|
|
|
getLocalClients: (userJamBlasters) ->
|
|
localClients = context.jamClient.getLocalClients()
|
|
|
|
@mergeBonjourClients(localClients, userJamBlasters)
|
|
|
|
@setState({localClients: localClients})
|
|
|
|
} |